But why does inputNum under Private Function not work, even though its dim under the module and not the sub?
Maybe I dont have this correct, but i've also been steadily working on 4 other questions for programming at the same time and this is the only one giving me a world of trouble and its getting to me. haha
You're help is greatly appreciated though and hopefully i'll get this soon. haha
Module Module1
Dim inputNum As String = 0
Sub Main()
Dim primeNumbers As String
Do While inputNum <> "end"
Console.WriteLine(vbNewLine & "Please enter a number: ( 'end' to stop)")
primeNumbers = ""
inputNum = Console.ReadLine()
If inputNum = "end" Then End
Dim i As Integer = 1
If isPrime(i) Then primeNumbers = i
i += 1
If isPrime(i) Then primeNumbers = i
'For i = 3 To inputNum 'not inputNum-1, because we want to test inputNum as well
' If isPrime(i) Then
' primeNumbers &= "," & i
' End If
'Next
For i = 3 To inputNum Step 2
If isPrime(i) Then
primeNumbers &= "," & i
End If
Next
Console.WriteLine(vbNewLine & "Prime numbers up to " & inputNum)
Console.WriteLine(primeNumbers)
Loop
End Sub
Private Function isPrime(ByVal testnum As Integer) As Boolean
Dim ctr As Integer
If testnum = 1 Then Return False
If testnum = 2 Then Return True
If testnum Mod 2 = 0 Then Return False
isPrime = True
For inputNum = 3 To testnum
If testnum Mod ctr = 0 Then
isPrime = False
End If
Next
End Function
End Module

New Topic/Question
Reply




MultiQuote




|