Results 1 to 22 of 22

Thread: GoTo statement

  1. #1

    Thread Starter
    Member
    Join Date
    Jun 2002
    Posts
    44

    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..

  2. #2
    Need-a-life Member Mc Brain's Avatar
    Join Date
    Apr 2000
    Location
    Buenos Aires, Argentina
    Posts
    6,808
    How about this?
    VB Code:
    1. Do
    2.    x = nPHI Mod nE
    3.    y = x Mod nE
    4.    If y <> 0 And IsPrime(nE) Then
    5.       GCD = nE
    6.       Exit Function
    7.    Else
    8.       nE = nE + 1
    9.    End If
    10. 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.

  3. #3

    Thread Starter
    Member
    Join Date
    Jun 2002
    Posts
    44
    hey thanks hmm just hope it doesnt go into some infinite loop thanks alot...
    For Strength And Honour..

  4. #4
    Need-a-life Member Mc Brain's Avatar
    Join Date
    Apr 2000
    Location
    Buenos Aires, Argentina
    Posts
    6,808
    It will go into an infintie loop... but so does your original code.
    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.

  5. #5
    Need-a-life Member Mc Brain's Avatar
    Join Date
    Apr 2000
    Location
    Buenos Aires, Argentina
    Posts
    6,808
    No... Actually, the "Exit Function" would stop your 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.

  6. #6

    Thread Starter
    Member
    Join Date
    Jun 2002
    Posts
    44
    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..

  7. #7
    Need-a-life Member Mc Brain's Avatar
    Join Date
    Apr 2000
    Location
    Buenos Aires, Argentina
    Posts
    6,808
    Relax... when y <> 0 And IsPrime(nE) it will exit the loop... actually it will exit the whole function.
    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.

  8. #8
    Retired VBF Adm1nistrator plenderj's Avatar
    Join Date
    Jan 2001
    Location
    Dublin, Ireland
    Posts
    10,359
    Linkesh, if you're calculating the GCD of two numbers, then this may be of intrest :

    VB Code:
    1. '
    2. ' What is the greatest common divisor of 2 given numbers ? (Recursive)
    3. '
    4. Public Function RecursiveGCD(num1 As Long, num2 As Long) As Long
    5.     If (num1 = 1) Or (num2 = 1) Then
    6.         RecursiveGCD = 1
    7.     Else
    8.         If (num1 = num2) Then
    9.             RecursiveGCD = num1
    10.         Else
    11.             If (num1 > num2) Then
    12.                 RecursiveGCD = RecursiveGCD(num1 - num2, num2)
    13.             Else
    14.                 RecursiveGCD = RecursiveGCD(num2 - num1, num1)
    15.             End If
    16.         End If
    17.     End If
    18. End Function
    Microsoft MVP : Visual Developer - Visual Basic [2004-2005]

  9. #9

    Thread Starter
    Member
    Join Date
    Jun 2002
    Posts
    44
    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..

  10. #10

    Thread Starter
    Member
    Join Date
    Jun 2002
    Posts
    44
    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..

  11. #11
    Hyperactive Member
    Join Date
    Jun 2000
    Posts
    350
    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?
    .

  12. #12

    Thread Starter
    Member
    Join Date
    Jun 2002
    Posts
    44
    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..

  13. #13
    Retired VBF Adm1nistrator plenderj's Avatar
    Join Date
    Jan 2001
    Location
    Dublin, Ireland
    Posts
    10,359
    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:
    1. Private Function nMod(ByRef n1 As Long, ByVal n2 As Long) As Long
    2.     If n1 < n2 Then
    3.         nMod = n1
    4.         Exit Function
    5.     Else
    6.         nMod = nMod(n1 - n2, n2)
    7.     End If
    8. End Function
    9.  
    10. Private Sub Form_Load()
    11.     MsgBox nMod(61, 10)
    12. End Sub
    Microsoft MVP : Visual Developer - Visual Basic [2004-2005]

  14. #14

    Thread Starter
    Member
    Join Date
    Jun 2002
    Posts
    44
    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..

  15. #15
    Retired VBF Adm1nistrator plenderj's Avatar
    Join Date
    Jan 2001
    Location
    Dublin, Ireland
    Posts
    10,359
    It makes a number between 10000000 and 99999999
    Microsoft MVP : Visual Developer - Visual Basic [2004-2005]

  16. #16

    Thread Starter
    Member
    Join Date
    Jun 2002
    Posts
    44
    do u think there is anyother way to do this cos EVB doesnt support the Random function..................
    For Strength And Honour..

  17. #17
    Hyperactive Member
    Join Date
    Jun 2000
    Posts
    350

    Thumbs down EVB = VB lite?

    What does EVB support?

    .

  18. #18
    Retired VBF Adm1nistrator plenderj's Avatar
    Join Date
    Jan 2001
    Location
    Dublin, Ireland
    Posts
    10,359
    Do you have an eVB language reference ?
    Microsoft MVP : Visual Developer - Visual Basic [2004-2005]

  19. #19

    Thread Starter
    Member
    Join Date
    Jun 2002
    Posts
    44
    no thats the problem the help file is not extensive enough...
    For Strength And Honour..

  20. #20
    Retired VBF Adm1nistrator plenderj's Avatar
    Join Date
    Jan 2001
    Location
    Dublin, Ireland
    Posts
    10,359
    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]

  21. #21
    Retired VBF Adm1nistrator plenderj's Avatar
    Join Date
    Jan 2001
    Location
    Dublin, Ireland
    Posts
    10,359
    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:
    1. Private Function generateRandomNumber() As Long
    2.     Dim i As Long, n As Long: n = Second(Time): n = n + 10
    3.     For i = 0 To (n * 2)
    4.         generateRandomNumber = generateRandomNumber + ((Second(Time) * Minute(Time)) \ (Second(Time) + Minute(Time)))
    5.         generateRandomNumber = generateRandomNumber + (Second(Time) * (i + (Second(Time))))
    6.         generateRandomNumber = generateRandomNumber + (Second(Time) * Second(Time)) \ Hour(Time)
    7.         If Second(Time) Mod 2 = 0 Then
    8.             generateRandomNumber = generateRandomNumber + (Hour(Time) \ (Second(Time) + 1))
    9.         Else
    10.             generateRandomNumber = generateRandomNumber + Second(Time) + Minute(Time)
    11.         End If
    12.         generateRandomNumber = generateRandomNumber + Day(Time)
    13.     Next
    14. End Function
    Microsoft MVP : Visual Developer - Visual Basic [2004-2005]

  22. #22

    Thread Starter
    Member
    Join Date
    Jun 2002
    Posts
    44
    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
  •  



Click Here to Expand Forum to Full Width