Results 1 to 14 of 14

Thread: Randomize

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Nov 1999
    Posts
    184
    ok.. there is a loop..
    It looks just dandy to me..
    Whats the problem it??

    ALL the code..

    ------------------------

    Dim RndNum As Integer
    Dim RecordRndNum(200) As Integer
    Dim KeepRecordPlace As Integer
    Dim Matches As Integer
    Dim looper As Integer

    Startover:

    Randomize
    RndNum = Int(Rnd * 84) + 1

    RecordRndNum(KeepRecordPlace) = RndNum
    KeepRecordPlace = KeepRecordPlace + 1

    Do While looper <= 200
    If RndNum = RecordRndNum(looper) Then
    Matches = Matches + 1
    End If
    looper = looper + 1
    Loop

    If Matches > 1 Then
    KeepRecordPlace = KeepRecordPlace - 1
    Matches = 0
    GoTo Startover
    End If

    Counter = RndNum
    -------------------------------------------
    Evan Duffield --------
    --- [email protected]
    - -
    VB6 - Learning Edition
    - -


  2. #2
    Addicted Member
    Join Date
    Aug 1999
    Location
    Ottawa,ON,Canada
    Posts
    217

    Thumbs down

    Goto!!
    Goto!!!
    GOTO!!!!

    ahhhhhhhhhhh!!!!!!!!
    Run away!!!
    Dan PM
    Analyst Programmer

    VB6 SP3 (also VB4 16-bit sometimes )

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Nov 1999
    Posts
    184
    lol thankyou
    Evan Duffield --------
    --- [email protected]
    - -
    VB6 - Learning Edition
    - -


  4. #4

    Thread Starter
    Addicted Member
    Join Date
    Nov 1999
    Posts
    184
    What do I write to make it go back to the
    Original place 'startover'????
    Evan Duffield --------
    --- [email protected]
    - -
    VB6 - Learning Edition
    - -


  5. #5
    Fanatic Member
    Join Date
    Mar 2000
    Location
    That posh bit of England known as Buckinghamshire
    Posts
    658
    You're a braver man than me, posting a goto liek that on this forum. Everyone seems to hate it with a passion.

    Also i can't see where you set looper back to zero any where in the loop.
    Code:
      Dim RndNum As Integer
      Dim RecordRndNum(200) As Integer
      Dim KeepRecordPlace As Integer
      Dim Matches As Integer
      Dim looper As Integer
      
      While Matches <> 1
        Matches = 0
        
        Randomize
        RndNum = Int(Rnd * 84) + 1
      
        RecordRndNum(KeepRecordPlace) = RndNum
        KeepRecordPlace = KeepRecordPlace + 1
      
        Do While looper <= 200
          If RndNum = RecordRndNum(looper) Then
            Matches = Matches + 1
          End If
          looper = looper + 1
        Loop
      
        If Matches > 1 Then
          KeepRecordPlace = KeepRecordPlace - 1
        End If
        
      Wend
      
      Counter = RndNum
    Iain, thats with an i by the way!

  6. #6
    Conquistador
    Join Date
    Dec 1999
    Location
    Australia
    Posts
    4,527
    why do you want it to startover again?

  7. #7

  8. #8
    Conquistador
    Join Date
    Dec 1999
    Location
    Australia
    Posts
    4,527
    i hate the randomize function,
    when i was writing a little program, it was a pain in the arse

  9. #9
    Addicted Member
    Join Date
    Feb 2000
    Location
    London, UK
    Posts
    145

    Goto

    I just wonder why everybody seems to be so upset about Goto?
    Ok, I knowe it makes the code hard tu understand, maintain and change, but sometimes it's just the easiest way to solve a problem.

    Maybe only the brave dare to use Goto?
    And btw, we all use On Error Goto, don't we?
    What's the difference between that and other Goto:s?

    If Angry, Do Not Goto Pentax.
    Wilhelm Tunemyr,
    Swede in London

    [email protected]

    "Dort, wo man Bücher verbrennt, verbrennt man am Ende auch Menschen"
    Heinrich Heine (1797-1856)

    Pravda vítezi!
    (Truth prevails!)

  10. #10
    Conquistador
    Join Date
    Dec 1999
    Location
    Australia
    Posts
    4,527
    because it is annoying, and it does not always do what you want

  11. #11
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221

    Thumbs up GOTO

    Goto have been pretty useless since i programmed in gwbasic, but there can be handy in Exiting more than one loop
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  12. #12
    Addicted Member
    Join Date
    Aug 1999
    Location
    Ottawa,ON,Canada
    Posts
    217

    Exclamation

    Try programming in Assembly and you'll quickly understand why Goto is looked down upon so much. One little change and your entire logic structure is blown to sh!†, plus it's confusing and completely un-necessary in VB! Everything that needs to be accomplished with Gotos can be re-written using stronger logic and better planning. You can use loops, switches, flag variables, functions/subs, and recursion (not the best alternative). Just sit and do some Flow Charts, Data Diagrams, and Desk Checks before you start plugging away at your code. You'll appreciate this advice so much more when you come back to this app in a few years and try to understand what the hell you were smoking when you wrote it, and trust me, you will come back to it eventually if it was worth your time to write.
    Dan PM
    Analyst Programmer

    VB6 SP3 (also VB4 16-bit sometimes )

  13. #13

    Thread Starter
    Addicted Member
    Join Date
    Nov 1999
    Posts
    184
    Thanks Guys!!

    You know what.. Acutally I fingured out
    what was wrong.. I learned something
    valuable. NEVER NAME YOUR FUNCTION RANDOMIZE.
    lol.. I must have been out of my mind!!
    Did you guys know that if you name your
    function after a call in vb your program
    goes nuts?
    Evan Duffield --------
    --- [email protected]
    - -
    VB6 - Learning Edition
    - -


  14. #14
    Conquistador
    Join Date
    Dec 1999
    Location
    Australia
    Posts
    4,527
    you can always use exit do

    for exit for

    if you are using those loops

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