一道vb的题目 我真不知道keypress怎么捕获回车
此程序目的是判断一个数是否是回文(例如12321,1221为回文)DimsAsIntegerPrivateSubText1_KeyPres(KeyAsciiAsInteg...
此程序目的是判断一个数是否是回文(例如12321,1221为回文)
Dim s As Integer
Private Sub Text1_KeyPres(KeyAscii As Integer)
If KeyAscii = 13 Then
s = Val(Text1.Text)
If Ishw(s) Then
List1.AddItem s & " 不是回文"
Else: List1.AddItem s & " 是回文"
End If
End If
End Sub
Private Function Ishw(ByVal n As Integer) As Integer
Dim a() As Integer
Dim sum As Integer
Dim i As Integer
Ishw = 0
i = Len(t)
For i = 1 To s
a(i) = Mid(s, i, i)
Next i
For i = 1 To s / 2
If a(i) <> a(s - i + 1) Then
Ishw = 1
Exit For
End If
Next i
End Function 展开
Dim s As Integer
Private Sub Text1_KeyPres(KeyAscii As Integer)
If KeyAscii = 13 Then
s = Val(Text1.Text)
If Ishw(s) Then
List1.AddItem s & " 不是回文"
Else: List1.AddItem s & " 是回文"
End If
End If
End Sub
Private Function Ishw(ByVal n As Integer) As Integer
Dim a() As Integer
Dim sum As Integer
Dim i As Integer
Ishw = 0
i = Len(t)
For i = 1 To s
a(i) = Mid(s, i, i)
Next i
For i = 1 To s / 2
If a(i) <> a(s - i + 1) Then
Ishw = 1
Exit For
End If
Next i
End Function 展开
5个回答
展开全部
很多错误,修改如下:
Private Sub Text1_KeyPress(KeyAscii As Integer) '注意事件名称,不要写错
Dim s As Integer '不需要定义为全局变量
If KeyAscii = 13 Then
s = Val(Text1.Text)
If Ishw(s) Then
List1.AddItem s & " 不是回文"
Else
List1.AddItem s & " 是回文"
End If
End If
End Sub
Private Function Ishw(ByVal n As Integer) As Boolean '返回值定义为逻辑型
Dim i As Integer
Ishw = True
For i = 1 To Len(CStr(n)) \ 2
If Mid(CStr(n), i, 1) = Mid(CStr(n), Len(CStr(n)) - i + 1, 1) Then
Ishw = False
Exit For
End If
Next i
End Function
展开全部
第三行If KeyAscii = 13 Then这句,表示如果按下的按键的ASCII编码为13,即为Enter键,则执行。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
要把form的KeyPreview设置成true,才能捕获控件的KeyPress事件。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
keypress事件不行捕获回车键,就用 keyDown事件,用keycode = 13 判断
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
Text1_KeyPres
改为
Text1_KeyPress
改为
Text1_KeyPress
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询