Randomize Letters.

Discussion in 'Programming General' started by SwiftYx, Oct 14, 2008.

Randomize Letters.
  1. Unread #1 - Oct 14, 2008 at 2:00 PM
  2. SwiftYx
    Referrals:
    0

    SwiftYx Guest

    Randomize Letters.

    I've just started a I.T course at college it's pretty basic stuff but not having used VB before only for very simple thing's i haven't got a clue on some stuff.

    I'm having to create a Who Wants To Be A Millionaire style game as part of a mini project, I'm putting my questions together as i go along but before i can continue any further i have to get the life lines working.

    I have 50/50 working by disabling two of the wrong answers.

    Ask the audience displays a form from excel but i was wondering if it's possible that when i click on a command button instead of putting Result1.Show it's possible to randomize what form would pop up?

    For the phone a friend i wanted to use a drop down box with a few names in it that when chosen would display a letter between A, B, C & D.

    If any of this is possible can someone please help, Sorry for the noobishness.
     
  3. Unread #2 - Oct 14, 2008 at 5:05 PM
  4. Visual Basic Matt
    Joined:
    Jan 29, 2008
    Posts:
    647
    Referrals:
    2
    Sythe Gold:
    56
    Discord Unique ID:
    223154494878253056

    Visual Basic Matt Apprentice

    Randomize Letters.

    ^^^ Good Luck ^^^

    I also whipped up this code just for your phone a friend. :p
    Code:
    Dim StrValue As Integer
    Dim CData As Integer
    Dim CDefaultAnswer As String
    Dim CFinalAnswer As String
    Private Sub Command1_Click()
    'Declares actual answer
    CDefaultAnswer = Label1.Caption 'You can change that to your answer to be held.
    '-Declare Dificulties
    'You can declare more names with an (ElseIf) but keep the range from 1-3
    If Combo1.Text = "Bob" Then 'Example Name (You can Change)
    GetData 1 'Highest Chance to get correct
    ElseIf Combo1.Text = "Sarah" Then 'Example Name (You can Change)
    GetData 2 'Low Chance to get correct
    ElseIf Combo1.Text = "Sam" Then 'Example Name (You can Change)
    GetData 1
    Else
    GetData 3 'Completely Random Chance to get correct
    End If
    '-Start answering
    If Combo1.Text = "Original Combo Text" Then 'meaning if the user hasent picked someone to call...
    MsgBox "Please choose someone to call", vbCritical
    Exit Sub
    End If
    If CFinalAnswer = CDefaultAnswer Then
    MsgBox (CFinalAnswer) & " (Correct)"
    Else
    MsgBox (CFinalAnswer) & " (Incorrect)"
    End If
    End Sub
    
    Public Function GetData(Level)
    GetAnswer
    If Level = 1 And Not CFinalAnswer = CDefaultAnswer Then
    GetAnswer
    ElseIf Level = 2 And CFinalAnswer = CDefaultAnswer Then
    GetAnswer
    Else
    'Simply do noting and answer
    End If
    End Function
    Public Function GetAnswer()
    'Randomization Code
    Randomize
    StrValue = Int(5 * Rnd) 'Number 5 = Max Number + 1 or 4
    'Start Answering
    If StrValue = 1 Then
    CFinalAnswer = "A"
    ElseIf StrValue = 2 Then
    CFinalAnswer = "B"
    ElseIf StrValue = 3 Then
    CFinalAnswer = "C"
    ElseIf StrValue = 4 Then
    CFinalAnswer = "D"
    End If
    End Function
    
     
  5. Unread #3 - Oct 14, 2008 at 8:59 PM
  6. Nullware
    Joined:
    Jan 30, 2007
    Posts:
    1,761
    Referrals:
    4
    Sythe Gold:
    0

    Nullware Guru

    Randomize Letters.

    Your phone a friend should not be purely random either. It should give the correct response 50-70% of the time I think.
     
  7. Unread #4 - Oct 14, 2008 at 9:39 PM
  8. SuF
    Joined:
    Jan 21, 2007
    Posts:
    14,212
    Referrals:
    28
    Sythe Gold:
    1,234
    Discord Unique ID:
    203283096668340224
    <3 n4n0 Two Factor Authentication User Community Participant Spam Forum Participant Sythe's 10th Anniversary

    SuF Legend
    Pirate Retired Global Moderator

    Randomize Letters.

    Yes I agree, because most of the time when they phone a friend, the friend is right.
     
  9. Unread #5 - Oct 14, 2008 at 11:48 PM
  10. Blupig
    Joined:
    Nov 23, 2006
    Posts:
    7,145
    Referrals:
    16
    Sythe Gold:
    1,609
    Discord Unique ID:
    178533992981594112
    Valentine's Singing Competition Winner Member of the Month Winner MushyMuncher Gohan has AIDS Extreme Homosex World War 3 I'm LAAAAAAAME
    Off Topic Participant

    Blupig BEEF TOILET
    $5 USD Donor

    Randomize Letters.

    A long way of doing it could be with arrays:

    Code:
    Dim Letters As String
    Dim strOut As String
    
        Letters = Array("a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z")
        Randomize
        strOut = Int(26 * Rnd)
    
    Or a little easier:
    Code:
    Chr(Rand(45, 90))
    
    ^^Picks a random upper case letter.
     
< visual studio 2008 tutorial #1 | What commands would I use to execute this? >

Users viewing this thread
1 guest


 
 
Adblock breaks this site