• Public Function IsPrime(ByVal lValue As Long) As Boolean Dim lCtr As Long Dim lRes As Long Dim lCount As Long 'eliminate even numbers right away lValue = Abs(lValue) If lValue Mod 2 = 0 Then Exit Function For lCtr = 1 To lValue lRes = lValue Mod lCtr If lRes <> 0 Then lCount = lCount + 1 End If Next IsPrime = (lCount = lValue - 2) End Function -------------------------------------- Works for VB 5 & 6, Declarations: '(None)
  • -require user input -define the user intput as a variable -define a 2nd variable as the variable -Define a third variable as zero -loop dividing the first variable by integer increases from 2 increasing by 1 each loop until you reach one less than the first variable -Set the loop to stop if the quotent of a division is an integer and add 1 to the third variable -When the loop ends, have an output based upon variable 3 that defines the input as prime or not There are some parts of this like integer determination that you will have to work out since I haven't programmed in visual basic for a couple of years, but this is a good start. You could also create something of a small database that checks an input against known prime numbers and reports whether the input is prime or not

Copyright 2023, Wired Ivy, LLC

Answerbag | Terms of Service | Privacy Policy