Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

Visual Basic Help

  • 24-10-2003 11:19am
    #1
    Closed Accounts Posts: 1,309 ✭✭✭


    i want to print out the alphabet and randomize it so that after a few goes the same letter wont come up twice


Comments

  • Registered Users, Registered Users 2 Posts: 944 ✭✭✭nahdoic


    are you sure you really don't want your homework done?


  • Closed Accounts Posts: 25 tonysoprano


    Private Sub GetRandomAlphabet()
    Dim sAlphabet As String
    Dim nIndex As Integer
    Dim nNum As Integer


    Do While (Len(sAlphabet)) <> 26
    nNum = Int((122 - 97 + 1) * Rnd) + 97 ' Change these values to 65 + 90
    ' if you want capitals
    If InStr(sAlphabet, Chr(nNum)) = 0 Then
    sAlphabet = sAlphabet + Chr(nNum)
    End If
    Loop
    lblAlphabet.Caption = sAlphabet

    End Sub


  • Closed Accounts Posts: 1,309 ✭✭✭Kazu


    thank you looks the business


  • Moderators, Recreation & Hobbies Moderators, Science, Health & Environment Moderators, Technology & Internet Moderators Posts: 93,572 Mod ✭✭✭✭Capt'n Midnight


    What you want to do is setup an array of 26 elements
    Then step through them and randomly swap the next card with one of the remaining ones.


  • Registered Users, Registered Users 2 Posts: 2,781 ✭✭✭amen


    while the code below produces randome letter arrangements if the program is run multiple times then the 1st,2nd etc set is always the same.

    What you need to do is seed the random number generator with a random seed. Normally the date/time is used.
    Place Randomize before the Do While Loop
    You can pass a value to Randomize if you want but the default is date/time so normally nothing is passed.


  • Advertisement
  • Closed Accounts Posts: 1,309 ✭✭✭Kazu


    would you code it please as iam getting more lost


  • Moderators, Recreation & Hobbies Moderators, Science, Health & Environment Moderators, Technology & Internet Moderators Posts: 93,572 Mod ✭✭✭✭Capt'n Midnight


    Pseudo Code
    
    dim l(26)
    Do 
     incr x
    loop until bored or muppet presses a key 
    
    randomize x 
    
    for n = 26 to 2 step -1
     a = rnd(n) ' pick one of the remaining cards
     swap l(a) , l(n)
    next
    

    Imagine you want to carve out some egyption lettering in a Welsh valley only to find out that someone has beaten you to it..

    Quartz glyph job vex'd by cwm finks


  • Closed Accounts Posts: 1,309 ✭✭✭Kazu


    i got it working thanks


  • Registered Users, Registered Users 2 Posts: 21,264 ✭✭✭✭Hobbes


    Originally posted by Capt'n Midnight
    Pseudo Code
    
    dim l(26)
    Do 
     incr x
    loop until bored or muppet presses a key 
    
    randomize x 
    

    Or just randomize timer at the start of your code should do the trick as well.


  • Moderators, Recreation & Hobbies Moderators, Science, Health & Environment Moderators, Technology & Internet Moderators Posts: 93,572 Mod ✭✭✭✭Capt'n Midnight


    Radomise timer - yeah that's what they do in Freecell..

    to set time in batch file

    Echo 15:15>15
    time<15
    program.exe


  • Advertisement
  • Registered Users, Registered Users 2 Posts: 21,264 ✭✭✭✭Hobbes


    Echo 15:15>15
    time<15
    program.exe
    

    Freecell you can just type in the game number. All that does is totally screw up your time on your machine.

    Anyway as far as I remember timer generates on milliseconds (could be wrong though). So the random number would vary based on the speed of your machine and what is running.

    If he was using it as part of a security check then he should be checking for time changes (amoung other things), otherwise randomize timer is fine.


  • Moderators, Recreation & Hobbies Moderators, Science, Health & Environment Moderators, Technology & Internet Moderators Posts: 93,572 Mod ✭✭✭✭Capt'n Midnight


    AFAIK timer might be linked to the 18.2 ms timer - the one that causes win95/98 to die after 49.7 days

    Point is it's only pseudo random - and cheap tricks can get around it..


  • Registered Users, Registered Users 2 Posts: 21,264 ✭✭✭✭Hobbes


    Random itself is only pseudo random.


Advertisement