so now my code look like this but it still has the same problem . the 9th digit i entered still saves inside num8. so i tried checking the value of "Len(lngNumber)" by using "Label41.Caption" and found out that the value is always 4 .
VB Code:
Private Sub Text1_Keypress(Keyascii As Integer) Dim num1 As Integer Dim num2 As Integer Dim num3 As Integer Dim num4 As Integer Dim num5 As Integer Dim num6 As Integer Dim num7 As Integer Dim num8 As Integer Dim lngNumber As Long Select Case Keyascii Case vbKey0 To vbKey9, vbKeyBack 'do nothing, accept the keys Case Else Beep 'optional Keyascii = 0 End Select ' convert string to Long variable lngNumber = CLng(Val(Text1.Text & (Chr(Keyascii)))) ' to multiple variables num1 = lngNumber \ 10000000 num2 = (lngNumber \ 1000000) Mod 10 num3 = (lngNumber \ 100000) Mod 10 num4 = (lngNumber \ 10000) Mod 10 num5 = (lngNumber \ 1000) Mod 10 num6 = (lngNumber \ 100) Mod 10 num7 = (lngNumber \ 10) Mod 10 num8 = lngNumber Mod 10 If Len(lngNumber) > 8 Then Keyascii = 0 'put nothing Exit Sub ' skip the rest End If 'this is to check the num's value Label41.Caption = Len(lngNumber) Label42.Caption = num2 Label43.Caption = num3 Label44.Caption = num4 Label13.Caption = num5 Label12.Caption = num6 Label24.Caption = num7 Label25.Caption = num8 End Sub




Reply With Quote