这个算法有问题,改为
Public Function check(phone)
 Dim phonenumber As String
 Dim i As Integer, j As Integer
 phonenumber = "0123456789"
     For i = 1 To Len(phone)
         For j = 1 To Len(phonenumber)
          If Mid(phone, i, 1) = Mid(phonenumber, j, 1) Then
               check = True
               Exit For
               Else
                 check = False
               End If
       Next
  Next
End Function
试一试。

解决方案 »

  1.   

    if mid(phone,i,1)=mid(phonenumber,j,1)这句后面少了一个then
    public function check(phone)
     phonenumber="0123456789"
         for i=1 to len(phone)
             for j=0 to len(phonenumber)
              if mid(phone,i,1)=mid(phonenumber,j,1) Then
                   check=true
                   else
                     check=false
                   end if
           next
      next
    end function
      

  2.   

    做法太奇怪了兩種做法
    1.寫代碼控制只能輸入數字
    If (KeyAscii < vbKey0 Or KeyAscii > vbKey9) And KeyAscii <> vbKeyBack And KeyAscii <> vbKeyReturn Then
            KeyAscii = C_ZERO
        End If
    2.check
    把你的方法優化一下
    用InStr方法
    有一個更好的函數,很久沒用想不起來了,試著幫你找一下
      

  3.   

    算法也有问题,在判断出含有非数字字符之后,就应该停止判断了(用Exit For或者Exit Function)。
    参考一下这个:
    ' writen by wangluonanhai(网络男孩) 
    ' 禁止在textbox中输入指定格式之外的字符
    Option Explicit
    Dim savetext As String
    Dim saveselstart As Long
    Private Sub Text6_Change()
    Static nestedcall As Boolean
    If nestedcall Then Exit Sub
    If IsNumeric(Text6.Text) Then
        savetext = Text6.Text
        saveselstart = Text6.SelStart
    Else
        nestedcall = True
        Text6.Text = savetext
        nestedcall = False
        Text6.SelStart = saveselstart
    End If
    End SubPrivate Sub Text6_GotFocus()
        savetext = Text6.Text
        saveselstart = Text6.SelStart
    End SubPrivate Sub Text6_KeyUp(KeyCode As Integer, Shift As Integer)
        saveselstart = Text6.SelStart
    End SubPrivate Sub Text6_MouseDown(Button As Integer, Shift As Integer, x As Single, Y As Single)
        saveselstart = Text6.SelStart
    End SubPrivate Sub Text6_MouseMove(Button As Integer, Shift As Integer, x As Single, Y As Single)
        saveselstart = Text6.SelStart
    End Sub
      

  4.   

    找到了strspn,不過突然發現是c的不好意思!
      

  5.   

    看了一下mid的第一個參數從1開始
    你從0開始,所以出錯