VB代码解答(关于回文数)

来源:百度知道 编辑:UC知道 时间:2024/05/26 16:48:31
Private Sub Text1_KeyPress(KeyAscii As Integer)
If Not IsNumeric(Text1) Then
MsgBox"输入非字符串,请重新输入"
Text1.Text = ""
Text1.SetFocus
Else
If IsH(Text1) Then
Picture1.Print Text1;"★"
Else
Picture1.Print Text1
End If
Text1 = ""
End If
End If
End Sub
Function IsH(ss As String) As Boolean
Dim i% , Ls%
IsH = Ture
ss = Trim(ss)
Ls = Len(ss)
For i = 1 To Ls \ 2
If Mid(ss,i,1) <> Mid(ss,Ls + 1 - i,1)Then
IsH = False
Exit Function
End If
Next i
End Function

Private Sub Text1_KeyPress(KeyAscii As Integer)
If Not IsNumeric(Text1) Then //输入非数字字符串
MsgBox"输入非字符串,请重新输入"
Text1.Text = ""
Text1.SetFocus //获得焦点
Else
If IsH(Text1) Then //布尔形变量,真输出上面,假输出下面
Picture1.Print Text1;"★"
Else
Picture1.Print Text1
End If
Text1 = "" //清空
End If
End If
End Sub
Function IsH(ss As String) As Boolean
Dim i% , Ls%
IsH = Ture
ss = Trim(ss)
Ls = Len(ss)
For i = 1 To Ls \ 2
If Mid(ss,i,1) <> Mid(ss,Ls + 1 - i,1)Then
IsH = False //前后半段字符串不一样,返回错误不是回文数
Exit Function
End If
Next i
End Function