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:
Option Explicit Dim calculating As Byte Dim prime As Byte Private Declare Function GetTickCount Lib "kernel32" () As Long Private Sub Command1_Click() If Text1.Text < 10 Then MsgBox "nuber must be bigger than 10 " Else calculating = True Dim lngStart As Long Dim lngFinish As Long Dim lngCounterOne As Long Dim lngCounterTwo As Long Command1.Caption = "calculating..." Form1.Tag = 2 Text1.Tag = Str(Val(Text1.Text) - (1)) lngStart = GetTickCount() Do If Text1.Text Mod Form1.Tag = 1 Then calculating = False prime = False Else Form1.Tag = Str(Val(Form1.Tag) + (1)) End If If Form1.Tag >= Text1.Tag Then calculating = False prime = True End If Loop Until calculating = False lngFinish = GetTickCount() Label1.Tag = CStr(lngFinish - lngStart) Text2.Text = Str(Val(Form1.Tag) / (1000)) If prime = True Then Label1.Caption = "number is prime" Else Label1.Caption = "number is not prime" End If Command1.Caption = "calculated" End If End Sub




Reply With Quote