Results 1 to 11 of 11

Thread: Help a university student, PT 2

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Nov 2003
    Posts
    24

    Help a university student, PT 2

    I decided to make a second thread about it. Getting too long

    Anyway, this is what i've done so far, and its got to be shown on a week on thusday.

    VB Code:
    1. Option Explicit
    2. Dim money As Integer
    3. Dim intSpin As Integer
    4. Dim intPicture As Integer
    5. Dim Spin As Integer
    6. Dim Var1 As Integer
    7. Dim Var2 As Integer
    8. Dim Var3 As Integer
    9. Dim winnings
    10.  
    11.  
    12. Private Sub cmdbet_Click()
    13. If money > 0 Then
    14. money = money - 20
    15. txtMoneyamount.Text = money
    16. Else
    17. cmddecrement.Visible = False
    18. MsgBox "Insert more money!"
    19. End If
    20.  
    21. End Sub
    22.  
    23. Private Sub cmdinsertcoin_Click()
    24. money = 100
    25. txtMoneyamount.Text = money
    26.  
    27.  
    28. End Sub
    29.  
    30. Private Sub cmdspin_Click()
    31.      Randomize
    32. Call Form_Load
    33.      txtwinnings.Text = winnings
    34. If Var1 = 1 Then
    35. winnings = 20
    36. End If
    37. If money > 0 Then
    38. money = money - 20
    39. txtMoneyamount.Text = money
    40. Else
    41. cmddecrement.Visible = False
    42. MsgBox "Insert more money!"
    43. End If
    44. tmrspin.Enabled = True
    45. Spin = money / 20
    46. txtturnsavalible.Text = money
    47. End Sub
    48.  
    49.  
    50. Private Sub Form_Load()
    51. Randomize
    52. Select Case Int(8 * Rnd) ' Generates 0 to 7
    53.     Case 0
    54.         imgbox1.Picture = LoadPicture("F:\MyWork\My Pictures\bell.jpg")
    55.     Case 1
    56.         imgbox1.Picture = LoadPicture("F:\MyWork\My Pictures\cherry.jpg")
    57.     Case 2
    58.         imgbox1.Picture = LoadPicture("F:\MyWork\My Pictures\cherry.jpg")
    59.     Case 3
    60.         imgbox1.Picture = LoadPicture("F:\MyWork\My Pictures\wildberry.jpg")
    61.     Case 4
    62.         imgbox1.Picture = LoadPicture("F:\MyWork\My Pictures\fruitsmoothy.jpg")
    63.     Case 5
    64.         imgbox1.Picture = LoadPicture("F:\MyWork\My Pictures\grape.jpg")
    65.     Case 6
    66.         imgbox1.Picture = LoadPicture("F:\MyWork\My Pictures\melon.jpg")
    67.     Case 7
    68.         imgbox1.Picture = LoadPicture("F:\MyWork\My Pictures\blackberry.jpg")
    69.        
    70. End Select
    71. Select Case Int(8 * Rnd)
    72.     Case 0
    73.         imgbox2.Picture = LoadPicture("F:\MyWork\My Pictures\bell.jpg")
    74.     Case 1
    75.         imgbox2.Picture = LoadPicture("F:\MyWork\My Pictures\cherry.jpg")
    76.     Case 2
    77.         imgbox2.Picture = LoadPicture("F:\MyWork\My Pictures\cherry.jpg")
    78.     Case 3
    79.         imgbox2.Picture = LoadPicture("F:\MyWork\My Pictures\wildberry.jpg")
    80.     Case 4
    81.         imgbox2.Picture = LoadPicture("F:\MyWork\My Pictures\fruitsmoothy.jpg")
    82.     Case 5
    83.         imgbox2.Picture = LoadPicture("F:\MyWork\My Pictures\grape.jpg")
    84.     Case 6
    85.         imgbox2.Picture = LoadPicture("F:\MyWork\My Pictures\melon.jpg")
    86.     Case 7
    87.         imgbox2.Picture = LoadPicture("F:\MyWork\My Pictures\blackberry.jpg")
    88. End Select
    89.  
    90. Randomize
    91.  
    92. Select Case Int(8 * Rnd) ' Generates 0 to 7
    93.     Case 0
    94.         imgbox3.Picture = LoadPicture("F:\MyWork\My Pictures\bell.jpg")
    95.     Case 1
    96.         imgbox3.Picture = LoadPicture("F:\MyWork\My Pictures\cherry.jpg")
    97.     Case 2
    98.         imgbox3.Picture = LoadPicture("F:\MyWork\My Pictures\cherry.jpg")
    99.     Case 3
    100.         imgbox3.Picture = LoadPicture("F:\MyWork\My Pictures\wildberry.jpg")
    101.     Case 4
    102.         imgbox3.Picture = LoadPicture("F:\MyWork\My Pictures\fruitsmoothy.jpg")
    103.     Case 5
    104.         imgbox3.Picture = LoadPicture("F:\MyWork\My Pictures\grape.jpg")
    105.     Case 6
    106.         imgbox3.Picture = LoadPicture("F:\MyWork\My Pictures\melon.jpg")
    107.     Case 7
    108.         imgbox3.Picture = LoadPicture("F:\MyWork\My Pictures\blackberry.jpg")
    109. End Select
    110.  
    111. End Sub
    112.  
    113. Private Sub imgbox1_Click()
    114. Randomize
    115.  
    116. Select Case Int(8 * Rnd) ' Generates 0 to 7
    117.     Case 0
    118.         imgbox1.Picture = LoadPicture("F:\MyWork\My Pictures\bell.jpg")
    119.     Case 1
    120.         imgbox1.Picture = LoadPicture("F:\MyWork\My Pictures\cherry.jpg")
    121.     Case 2
    122.         imgbox1.Picture = LoadPicture("F:\MyWork\My Pictures\cherry.jpg")
    123.     Case 3
    124.         imgbox1.Picture = LoadPicture("F:\MyWork\My Pictures\wildberry.jpg")
    125.     Case 4
    126.         imgbox1.Picture = LoadPicture("F:\MyWork\My Pictures\fruitsmoothy.jpg")
    127.     Case 5
    128.         imgbox1.Picture = LoadPicture("F:\MyWork\My Pictures\grape.jpg")
    129.     Case 6
    130.         imgbox1.Picture = LoadPicture("F:\MyWork\My Pictures\melon.jpg")
    131.     Case 7
    132.         imgbox1.Picture = LoadPicture("F:\MyWork\My Pictures\blackberry.jpg")
    133. End Select
    134.  
    135. End Sub
    136.  
    137.  
    138. Private Sub imgbox2_Click()
    139. Randomize
    140.  
    141. Select Case Int(8 * Rnd) ' Generates 0 to 7
    142.     Case 0
    143.         imgbox2.Picture = LoadPicture("F:\MyWork\My Pictures\bell.jpg")
    144.     Case 1
    145.         imgbox2.Picture = LoadPicture("F:\MyWork\My Pictures\cherry.jpg")
    146.     Case 2
    147.         imgbox2.Picture = LoadPicture("F:\MyWork\My Pictures\cherry.jpg")
    148.     Case 3
    149.         imgbox2.Picture = LoadPicture("F:\MyWork\My Pictures\wildberry.jpg")
    150.     Case 4
    151.         imgbox2.Picture = LoadPicture("F:\MyWork\My Pictures\fruitsmoothy.jpg")
    152.     Case 5
    153.         imgbox2.Picture = LoadPicture("F:\MyWork\My Pictures\grape.jpg")
    154.     Case 6
    155.         imgbox2.Picture = LoadPicture("F:\MyWork\My Pictures\melon.jpg")
    156.     Case 7
    157.         imgbox2.Picture = LoadPicture("F:\MyWork\My Pictures\blackberry.jpg")
    158. End Select
    159.  
    160. End Sub
    161.  
    162.  
    163. Private Sub imgbox3_Click()
    164. Randomize
    165.  
    166. Select Case Int(8 * Rnd) ' Generates 0 to 7
    167.     Case 0
    168.         imgbox3.Picture = LoadPicture("F:\MyWork\My Pictures\bell.jpg")
    169.     Case 1
    170.         imgbox3.Picture = LoadPicture("F:\MyWork\My Pictures\cherry.jpg")
    171.     Case 2
    172.         imgbox3.Picture = LoadPicture("F:\MyWork\My Pictures\cherry.jpg")
    173.     Case 3
    174.         imgbox3.Picture = LoadPicture("F:\MyWork\My Pictures\wildberry.jpg")
    175.     Case 4
    176.         imgbox3.Picture = LoadPicture("F:\MyWork\My Pictures\fruitsmoothy.jpg")
    177.     Case 5
    178.         imgbox3.Picture = LoadPicture("F:\MyWork\My Pictures\grape.jpg")
    179.     Case 6
    180.         imgbox3.Picture = LoadPicture("F:\MyWork\My Pictures\melon.jpg")
    181.     Case 7
    182.         imgbox3.Picture = LoadPicture("F:\MyWork\My Pictures\blackberry.jpg")
    183. End Select
    184.  
    185. End Sub
    186.  
    187. Private Sub txtMoneyamount_Change()
    188.  
    189. If txtMoneyamount.Text = 0 Then
    190. cmdinsertcoin.Enabled = True
    191. Else
    192. txtMoneyamount.Text = 100
    193. cmdinsertcoin.Enabled = False
    194. End If
    195. txtMoneyamount.Text = money
    196. End Sub


    Now one of the basic make i need is to get the winnings to show. So if a melon appears, the winner gets 20 credits and so on. How do i do this?

  2. #2
    Frenzied Member ober0330's Avatar
    Join Date
    Dec 2001
    Location
    OH, USA
    Posts
    1,945
    OK, I see a giant need for simplifying your code. Do you notice how your code repeats A LOT??

    You can put all that code in each click event and the form load event into one procedure or function and call it from the others.

    Then, to get the winnings to show correctly, you'll want to set a variable in the case statement to whatever it was that was shown... like in Case 3, set a global variable to 3 or something. Then pass that back to the function that will show the winnings.
    format your code!! - [vbcode] [/vbcode]

    ANSWERS CAN BE FOUND HERE!!

    my personal company

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Nov 2003
    Posts
    24
    umm, i'm a complete new student with VB, so i don't know a thing about vb. Only very simple things.

    Would you be able to write the code in aid for this work i have to do?

  4. #4
    INXSIVE Bruce Fox's Avatar
    Join Date
    Sep 2001
    Location
    Melbourne, Australia
    Posts
    7,429
    Just a side point. As the routine to load your ImagBox is the same (just a different ImageBox each time), you could write ONE sub like:
    VB Code:
    1. Option Explicit
    2.  
    3. Private Sub Form_Load()
    4.  
    5.     Load_Reals imgBox1
    6.     Load_Reals imgBox2
    7.     Load_Reals imgBox3
    8.     Load_Reals imgBox4
    9.     Load_Reals imgBox5
    10.     Load_Reals imgBox6
    11.     Load_Reals imgBox7
    12.  
    13. End Sub
    14.  
    15. Private Sub Load_Reals(ByVal imgBox As Image)
    16.  
    17.     Select Case Int(8 * Rnd) ' Generates 0 to 7
    18.         Case 0
    19.             imgBox.Picture = LoadPicture("F:\MyWork\My Pictures\bell.jpg")
    20.         Case 1
    21.             imgBox.Picture = LoadPicture("F:\MyWork\My Pictures\cherry.jpg")
    22.         Case 2
    23.             imgBox.Picture = LoadPicture("F:\MyWork\My Pictures\cherry.jpg")
    24.         Case 3
    25.             imgBox.Picture = LoadPicture("F:\MyWork\My Pictures\wildberry.jpg")
    26.         Case 4
    27.             imgBox.Picture = LoadPicture("F:\MyWork\My Pictures\fruitsmoothy.jpg")
    28.         Case 5
    29.             imgBox.Picture = LoadPicture("F:\MyWork\My Pictures\grape.jpg")
    30.         Case 6
    31.             imgBox.Picture = LoadPicture("F:\MyWork\My Pictures\melon.jpg")
    32.         Case 7
    33.             imgBox.Picture = LoadPicture("F:\MyWork\My Pictures\blackberry.jpg")
    34.     End Select
    35.  
    36. End Sub




    Bruce.

  5. #5

    Thread Starter
    Junior Member
    Join Date
    Nov 2003
    Posts
    24
    right, ive copied all of that and when i load it all up it gives me an error on "vairble not defined"

  6. #6
    Frenzied Member ober0330's Avatar
    Join Date
    Dec 2001
    Location
    OH, USA
    Posts
    1,945
    can you tell us what variable it is saying is not defined? It's probably because the code Bruce posted refers to 7 image boxes and you only have 3. Take out 4-7.
    format your code!! - [vbcode] [/vbcode]

    ANSWERS CAN BE FOUND HERE!!

    my personal company

  7. #7

    Thread Starter
    Junior Member
    Join Date
    Nov 2003
    Posts
    24
    now it works!

    So about the winnings?

    Any thing i need to add?

  8. #8
    Frenzied Member ober0330's Avatar
    Join Date
    Dec 2001
    Location
    OH, USA
    Posts
    1,945
    did you read what I posted before about that?
    format your code!! - [vbcode] [/vbcode]

    ANSWERS CAN BE FOUND HERE!!

    my personal company

  9. #9

    Thread Starter
    Junior Member
    Join Date
    Nov 2003
    Posts
    24
    Then, to get the winnings to show correctly, you'll want to set a variable in the case statement to whatever it was that was shown... like in Case 3, set a global variable to 3 or something. Then pass that back to the function that will show the winnings.
    Sorry mate this means nothing to me. All i know by what you say is that:
    In my case 3,
    VB Code:
    1. imgBox.Picture = LoadPicture("F:\MyWork\My Pictures\wildberry.jpg")
    somehow add a "key" ,so when that picture loads up, it will add 20 credits.
    Am i correct?
    If so how do it then?

  10. #10

    Thread Starter
    Junior Member
    Join Date
    Nov 2003
    Posts
    24

    Angry

    bump

  11. #11
    Frenzied Member ober0330's Avatar
    Join Date
    Dec 2001
    Location
    OH, USA
    Posts
    1,945
    No need to use the mad smilie... damn. Chill out.

    As I said before, (if I'm understanding this), in your select statement, you assign a global variable called "winnings" or something to be whatever value you want so that whenever that picture shows up, a certain amount gets added to the prize.

    I don't know... it's hard for me to understand what you're trying to do or how you want to do it. Sorry. Don't get pissed at me. Explain it better.
    format your code!! - [vbcode] [/vbcode]

    ANSWERS CAN BE FOUND HERE!!

    my personal company

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