I am working on a prime number generator for sschool, but I jsut can't
seem to figure out how to write the contents of the variable MeSSage
into a new text file, Can someone help me?
the script is:
'================================================= =========================
'
' VBScript Source File -- Created with SAPIEN Technologies PrimalScript
4.0
'
'================================================= =========================
Dim Cntr, cnTr2, MeSSage, ModVal, OutCount, StartTime
Dim MaX
MeSSage = ""
OutCount = 4
StartTime = Now()
MaX = InputBox("Enter the highest number to reach when searching for
the prime numbers", "enter Max Number", 50)
'loop the value for count from 10 to the chosen number
For Cntr = 10 To MaX
'if cntr is odd counting in statement, else loop to next cntr value
If Cntr Mod 2 <0 Then
'set initial cntr2 value to 3
cnTr2 = 3
'while cntr is less than the value of cntr run statements
Do While cnTr2 < Cntr
'if cntr mod cntr2 =0, or a divisor is found lead loop to
go to next number
If Cntr Mod cnTr2 = 0 Then
'Exit do loop and move to next possible number
Exit Do
End If
'if cntr2 makes it to half of cntr without finding a match
call mess
If cnTr2 >= (Cntr / 2) Then
'call the module to append the numbers to the output
variable
Call MesS
Exit Do
End If
'go to the next possible number
cnTr2 = cnTr2 + 1
Loop
End If
Next
'if the prime number output has more than 669 numbers then you do not
want to display the numbers
If OutCount>669 Then
MeSSage = ""
Else
'Else display the numbers
MeSSage = MeSSage & vbCrLf & vbCrLf
End If
'Append the information to the end of the output message
MeSSage = MeSSage & "A total of " & OutCount & " prime numbers have
been found between 1 and " & MaX & "." & vbCrLf & vbCrLf & "The process
took " & DateDiff("s", StartTime, Now()) & " seconds."
'output the output MeSSage
'WScript.Echo MeSSage
Public Function MesS()
'If message has no numbers then start with the first 4 primes and
append the next prime
If MeSSage = "" Then
MeSSage = "1, 3, 5, 7, " & Cntr
Else
'Else add number To message
MeSSage = MeSSage & ", " & Cntr
End If
OutCount = OutCount + 1
End Function