• Log in or sign up for an account here: https://www.sythe.org/login

ISO MASSIVE HELP VB 08 program

  • Thread starter Thread starter PvMage
  • Start date Start date
P

PvMage

Guest
im making a program that prime factors numbers, this is what i have

but for some reason it will not display the factored numbers in my textbox

If you can fix this so it works i will give u my runescape account, its a puremage, name is be0tchkillaz

i quit runescape along time ago for WoW.

PLEASE HELP!!!!!!!!!




Friend Class primeFactors
Inherits System.Windows.Forms.Form
Private Sub start_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles start.Click

Dim startingNumber As Double
Dim i As Integer
Dim temp As Double
Dim factor As Double





startingNumber = txtBox.Text 'read text box as double starting number
For i = 2 To startingNumber - 1 'for loop goes from 2 to 1 less than the starting number
If startingNumber / i = Int(startingNumber / i) Then 'if the value of i is a factor of the starting number

factor = i 'store i as factor
If IsPrime(factor) = True Then 'if factor is prime
temp = startingNumber / factor 'stores temp as the starting number divided by factor

TextBox1.Text = factor & " is a prime factor"


While temp / factor = Int(temp / factor) 'while loop to find how many of the prime factor are in the number

TextBox1.Text = factor & " is a prime factor"
temp = temp / factor
End While
End If
End If
Next i

End Sub
Private Function IsPrime(ByRef factor As Double) As Boolean
Dim check As Double 'Number to check
Dim factorRoot As Double 'Square root of factor
Dim found As Boolean 'checks for factor
If (factor Mod 1) = 0 Then 'if it is even
IsPrime = False 'sets the factor not prime
Else
factorRoot = Int(System.Math.Sqrt(factor))
check = 3 'start with 3 because only odds need to be chacked and 1 can be discounted
Do Until check > factorRoot Or found 'loop until the number being checked is higher than its square root
If factor / check = Int(factor / check) Then 'if temp is an integer
found = True 'set
Else
check = check + 2 'check the next odd number because evens will never be prime
End If
Loop
IsPrime = Not (found)
End If
If factor = 2 Then '2 is a prime number
IsPrime = True
End If
Exit Function

End Function

End Class
 
Member of the Month Winner
Sythe's 10th Anniversary
use code boxes next time. Lack of indentation and crappy font and spacing makes it hard for me to understand your code.
 
Runescape Gamblingrunescape gambling
Back
Top