|
-
Jul 8th, 2002, 02:27 AM
#1
Thread Starter
Member
GoTo statement
need help
everytime i use the GoTo statement in EVB i get this comple error stating "Expected Statement"
This is the code which i reallly need to use the goto statement if there is anyother control i could use i am open for ideas
top:
x = nPHI Mod nE
y = x Mod nE
If y <> 0 And IsPrime(nE) Then
GCD = nE
Exit Function
Else
nE = nE + 1
End If
GoTo top error keeps pointing here...
i am working on EVB(embeded visual Basic)
For Strength And Honour..
-
Jul 8th, 2002, 02:34 AM
#2
Need-a-life Member
How about this?
VB Code:
Do
x = nPHI Mod nE
y = x Mod nE
If y <> 0 And IsPrime(nE) Then
GCD = nE
Exit Function
Else
nE = nE + 1
End If
Loop
Emiliano F. Martín
If a post has helped you then please Rate it! (and give the user points he/she deserves by clicking on the image).
Encourage the person who helped you to keep doing it, and give him the points he deserves.
MP3 Organizer: Freeware to logically organize all your MP3s.
-
Jul 8th, 2002, 02:46 AM
#3
Thread Starter
Member
hey thanks hmm just hope it doesnt go into some infinite loop thanks alot...
For Strength And Honour..
-
Jul 8th, 2002, 02:47 AM
#4
-
Jul 8th, 2002, 02:48 AM
#5
-
Jul 8th, 2002, 02:50 AM
#6
Thread Starter
Member
wel currently ur rite it is going into the infinite loop maybe i got the logic wrong let me find out
For Strength And Honour..
-
Jul 8th, 2002, 02:51 AM
#7
-
Jul 8th, 2002, 02:59 AM
#8
Retired VBF Adm1nistrator
Linkesh, if you're calculating the GCD of two numbers, then this may be of intrest :
VB Code:
'
' What is the greatest common divisor of 2 given numbers ? (Recursive)
'
Public Function RecursiveGCD(num1 As Long, num2 As Long) As Long
If (num1 = 1) Or (num2 = 1) Then
RecursiveGCD = 1
Else
If (num1 = num2) Then
RecursiveGCD = num1
Else
If (num1 > num2) Then
RecursiveGCD = RecursiveGCD(num1 - num2, num2)
Else
RecursiveGCD = RecursiveGCD(num2 - num1, num1)
End If
End If
End If
End Function
Microsoft MVP : Visual Developer - Visual Basic [2004-2005]
-
Jul 8th, 2002, 03:08 AM
#9
Thread Starter
Member
actually wat i am really doing is the rsa encryption and i need to find the GCD of the number
Private Function GCD(nPHI As Double) As Double
'generates a random number relatively prime to PHI
On Error Resume Next
Dim nE, y
Const N_UP = 99999999 'set upper limit of random number for E
Const N_LW = 10000000 'set lower limit of random number for E
Randomize
nE = Int((N_UP - N_LW + 1) * Rnd + N_LW)
Do
x = nPHI Mod nE
y = x Mod nE
If y <> 0 And IsPrime(nE) Then
GCD = nE
Exit Function
Else
nE = nE + 1
End If
Loop
end functon
This wat i got so far but still goes into the loop
For Strength And Honour..
-
Jul 8th, 2002, 03:12 AM
#10
Thread Starter
Member
sorry i think EVB does not support the MOD funtion for me to find modulas is there ay other way i can do this
x = nPHI Mod nE
y = x Mod nE
For Strength And Honour..
-
Jul 8th, 2002, 03:14 AM
#11
Hyperactive Member
None of which explains why he's getting that error in the first place! Maybe EVB doesn't support GoTo, or the syntax might be subtly different?
-
Jul 8th, 2002, 03:18 AM
#12
Thread Starter
Member
well we got the goto part figured out but now we are stuck in this infinte loop and i think it is because EVB cannot us the modulas funtion so does anyone know how i can find the modulas of NE without using any function....../
x = nPHI Mod nE
y = x Mod nE
For Strength And Honour..
-
Jul 8th, 2002, 03:18 AM
#13
Retired VBF Adm1nistrator
Linkesh, the GCD computes the greates common divisor between two numbers.
Finding the number of numbers relatively prime to a number is called the EulerPhi
Is that what you're talking about ?
Also, here's a replacement Mod function if you need it
VB Code:
Private Function nMod(ByRef n1 As Long, ByVal n2 As Long) As Long
If n1 < n2 Then
nMod = n1
Exit Function
Else
nMod = nMod(n1 - n2, n2)
End If
End Function
Private Sub Form_Load()
MsgBox nMod(61, 10)
End Sub
Microsoft MVP : Visual Developer - Visual Basic [2004-2005]
-
Jul 8th, 2002, 03:33 AM
#14
Thread Starter
Member
Thanks a million guys life saver but could someone explain wat this code is actually doing
------
On Error Resume Next
Dim nE, y
Const N_UP = 99999999 'set upper limit of random number for E
Const N_LW = 10000000 'set lower limit of random number for E
Randomize
nE = Int((N_UP - N_LW + 1) * Rnd + N_LW)
For Strength And Honour..
-
Jul 8th, 2002, 03:39 AM
#15
Retired VBF Adm1nistrator
It makes a number between 10000000 and 99999999
Microsoft MVP : Visual Developer - Visual Basic [2004-2005]
-
Jul 8th, 2002, 03:56 AM
#16
Thread Starter
Member
do u think there is anyother way to do this cos EVB doesnt support the Random function..................
For Strength And Honour..
-
Jul 8th, 2002, 04:03 AM
#17
Hyperactive Member
EVB = VB lite?
What does EVB support?
-
Jul 8th, 2002, 04:03 AM
#18
Retired VBF Adm1nistrator
Do you have an eVB language reference ?
Microsoft MVP : Visual Developer - Visual Basic [2004-2005]
-
Jul 8th, 2002, 04:10 AM
#19
Thread Starter
Member
no thats the problem the help file is not extensive enough...
For Strength And Honour..
-
Jul 8th, 2002, 04:17 AM
#20
Retired VBF Adm1nistrator
Well try somethign simple like "MsgBox Rnd" and see what happens.
Also, cam you use the GetTickCount() api ?
Microsoft MVP : Visual Developer - Visual Basic [2004-2005]
-
Jul 8th, 2002, 04:33 AM
#21
Retired VBF Adm1nistrator
Here's a function you can use.
Its not random, but its a start.
If you can use the GetTickCount() API it would help a lot
VB Code:
Private Function generateRandomNumber() As Long
Dim i As Long, n As Long: n = Second(Time): n = n + 10
For i = 0 To (n * 2)
generateRandomNumber = generateRandomNumber + ((Second(Time) * Minute(Time)) \ (Second(Time) + Minute(Time)))
generateRandomNumber = generateRandomNumber + (Second(Time) * (i + (Second(Time))))
generateRandomNumber = generateRandomNumber + (Second(Time) * Second(Time)) \ Hour(Time)
If Second(Time) Mod 2 = 0 Then
generateRandomNumber = generateRandomNumber + (Hour(Time) \ (Second(Time) + 1))
Else
generateRandomNumber = generateRandomNumber + Second(Time) + Minute(Time)
End If
generateRandomNumber = generateRandomNumber + Day(Time)
Next
End Function
Microsoft MVP : Visual Developer - Visual Basic [2004-2005]
-
Jul 8th, 2002, 05:06 AM
#22
Thread Starter
Member
where do i find the GetTickCount() and do u know a way in vb to clear memory cos i think there is alot of garbage stored in it which i wish to clear
For Strength And Honour..
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|