2011年7月25日月曜日

→→→入力時の全半角チェック

Imports System
Imports System.Text
Imports.System.RegularExpressions

Private Sub Button1_Click(....
     Dim intRet As Integer
     Dim dr As DataSet1.入力Row = DataSet11.入力.NewRow()
     '5ケタ半角で入力
     If Regex.IsMatch( TextBox1.Text , "^[0-9]{5}$" ) Then
             Try
                    TextBox1.Text = TextBox1.Text
             Catch ex As Exception
                    MsgBox(ex.ToString)
             End Try
     Else
             MsgBox("半角5ケタで入力してください")
     End If

      dr.SEQ = TextBox1.Text
      dr.Zip   = TextBox2.Text   
      '全角で入力
      intRet = CHK(TextBox3.Text , 0 )
      If intRec > 0 Then
           MsgBox("全角で入力してください")
Exit Sub
      Else
            dr.住所 = TextBox3.Text
      End If
      DataSet11.入力.Rows.Add( dr )
      UpdateDatabase()
End Sub

Private Sub Form1_Load( ....
       oleDbDataAdapter1.Fill( DataSet11, "入力" )
End Sub

Private Sub UpdateDatabase()
        If Not DataSet11.HasChanges() Then Return
        oleDbDataAdapter1.Update( DataSet11 )
End Sub

Private Function CHK(ByVal AO As String , ByVal AKA As String) As Long
       Dim nagasa As Long
       Dim position As Long
       Dim moji  As String
       Dim sjisEnc As Encoding = Encoding.GetEncoding("Shift-JIS")
       CHK = 0
       nagasa = AO.Length
       position = 1
       Do
             If position > nagasa Then
                Exit do
             End If
             moji = Mid( AO , position , 1 )
             If sjisEnc.GetByteCount( moji ) = 1 Then
                 If AKA = 0 Then
                      CHK = position
                      Exit Function
                 End If
             Else
                 If AKA = 1 Then
                      CHK = position
                      Exit Function
                 End If
             End If
             position = position + 1
         Loop
End Function
----------------------------------------
新規フォームに
TextBox1 = SEQ
TextBox2 = Zip
TextBox3 = 住所
Button1  =    登録
を貼り付け

     



     

0 件のコメント:

コメントを投稿