i have made a program t see if a number entered into text1.text is prime and it is not working it is just giving the wrng results some prime numbers it says they are nt prime sme nt prime numbers it says they are prime but only sometimes it is right i dont know what i have doen wrong, can someone help me? this is the cde:

VB Code:
  1. Option Explicit
  2. Dim calculating As Byte
  3. Dim prime As Byte
  4. Private Declare Function GetTickCount Lib "kernel32" () As Long
  5.  
  6.  
  7.  
  8.  
  9. Private Sub Command1_Click()
  10. If Text1.Text < 10 Then
  11. MsgBox "nuber must be bigger than 10 "
  12. Else
  13.  
  14.  
  15. calculating = True
  16. Dim lngStart As Long
  17. Dim lngFinish As Long
  18. Dim lngCounterOne As Long
  19. Dim lngCounterTwo As Long
  20. Command1.Caption = "calculating..."
  21. Form1.Tag = 2
  22. Text1.Tag = Str(Val(Text1.Text) - (1))
  23. lngStart = GetTickCount()
  24. Do
  25. If Text1.Text Mod Form1.Tag = 1 Then
  26. calculating = False
  27. prime = False
  28.  
  29. Else
  30. Form1.Tag = Str(Val(Form1.Tag) + (1))
  31. End If
  32. If Form1.Tag >= Text1.Tag Then
  33. calculating = False
  34. prime = True
  35. End If
  36. Loop Until calculating = False
  37. lngFinish = GetTickCount()
  38.  
  39. Label1.Tag = CStr(lngFinish - lngStart)
  40. Text2.Text = Str(Val(Form1.Tag) / (1000))
  41. If prime = True Then
  42. Label1.Caption = "number is prime"
  43. Else
  44. Label1.Caption = "number is not prime"
  45. End If
  46. Command1.Caption = "calculated"
  47. End If
  48.  
  49.  
  50.  
  51.  
  52.  
  53. End Sub