VB如何判断一个text控件中的字符是数字还是字母?就是说,我要保存到数据库的数据一定要是数字.不能有字母,那我在保存事件里就要进行判断,如果有N个控件要判断的话,有没有简单的方法...请各位帮忙教一下..谢谢

解决方案 »

  1.   

    建立TEXT控件数组
        '只允许数字
        If Index = 0 Then
            If (KeyAscii < 48 Or KeyAscii > 57) And KeyAscii <> 8 Then
                KeyAscii = 0
            End If
        End If
        '数字和“-”
        If Index = 3 Or Index = 8 Or Index = 11 Then
            If (KeyAscii < 48 Or KeyAscii > 57) And KeyAscii <> 8 And KeyAscii <> 45 Then
                KeyAscii = 0
            End If
        End If
      

  2.   

    比如要在文本框中输入数据,可以将多个文本框生成一个文本框数组如text1(0)、text1(1)、text1(2),保存代码可以这样写:Private Sub Command1_Click()
        Dim i As Integer
        For i = 0 To Text1.Count - 1
            If IsNumeric(Text1(i).Text) Then
                '保存到数据库
            Else
                MsgBox "非法数据格式"
                Text1(i).SetFocus
            End If
        Next i