Results 1 to 29 of 29

Thread: Module counter / calculating between forms

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Jan 2007
    Posts
    27

    Module counter / calculating between forms

    Hello. this is my 3rd post about the same project in one day anyways, I have a program which i have made for a term project that is due Tuesday January 23rd :S

    The program is based on the game show "Deal or No Deal". As some of you may be aware the game show consists of 26 cases with different values in each case ranging from 0.01 to 1 million dollars. I am currently working on perfecting my randomization function on another forum ( randomizing array WITHOUT REPEAT) as well as another forum involving the user selecting
    their case (if statement dilemma involving command buttons). Now there is only two main thing for me to cover. And they are the rounds of the game (Module counter) and generating an offer (calculating between forms)

    For the purpose of my program i need to use a module to keep count of the rounds of my game. As many of you may have seen on the gameshow, "Deal or No Deal" the game is split up into rounds.

    they operate as follows in this chart
    Round Setup
    round 1 = 6 cases are opened and then offer is generated
    round 2 = 5 cases are opened and then offer is generated
    round 3 = 4 cases are opened and then offer is generated
    round 4 = 3 Cases are opened and then offer is generated
    round 5 = 2 cases are opened and then offer is generated
    round 6 = 1 case is opened and then offer is generated
    round 7= 1 case is opened and then offer is generated
    round 8 = 1 case is opened and then offer is generated
    round 9 = 1 case is opened and then offer is generated
    round 10 = User allowed to swap their case with remaining case

    What i need to do, is every time a case is chosen (case command button is clicked) a count is added to the module counter. When the counter reaches 6
    the user is shown their offer, and if they accept the game is over, if not they continue. now they choose 5 cases at the end of which they are prompted again with another offer, and this process continues according to the Round Setup i posted above.


    On another note i need to generate an offer. The calculations to formulate the offer is simple, coding it is the hard part. All you do is start off with the combined total of all the case values together ( $3,418,416.01) and as you open the cases you subtract the value of each case from the overall total. When it comes time to generate an offer (after opening 6 cases for instance) The new total ( $3,418,416.01 - values of all cases chosen to that point) is then divided by the number of remaining cases left in play. If the user denies the offer, the number is set back to before it was divided, and the subtraction of cases continues until the next round is over (5 cases chosen). The new total after round 2 is then divided by the remaining number of cases. This cycle continues until the user either excepts the offer, ending the game, or takes their case. Now that you understand the formula of generating an offer let me now briefly explain how i need it to work.

    When a case command is clicked it opens up a "Caseval" form that displays a randomized value for that case in a text box. (the value of the case was pre- determined when the form loads and the command button merely makes "Caseval" visible and it's form "Formcases" invisible) What i need to do is subtract this randomized value from the overall value. The overall value ($3,418,416.01) is stored in a text box in the form "Calculator". Then display the answer in a text box on the form "Money" .Within the Money form i would divide the value of the textbox by the remaining number of cases. obviously for the program to subtract values it has to recognize the characters as numerical values so i would string them as values in my module "DealGenerator"

    My project is too big to zip to the forum (contains bitmaps) but here is some of the code if generated so far.

    This is code from my opening form that contains all my cases

    VB Code:
    1. Private Sub Case1_Click() ' this code is the same for all 26 cases
    2. Formcases.Visible= False  
    3. Caseval.Visible = True          '  where i add one to counter (not sure how)
    4. Case1.Visible = true
    5.  
    6.  
    7. Private Sub Form_Activate()  ' random function (working on abolishing repeats)
    8. Dim Mnyval(25) As String
    9.     Dim CaseCollection As New Collection
    10.     Dim intRand As Integer
    11.     Mnyval(0) = "0.01"
    12.     Mnyval(1) = "1"
    13.     Mnyval(2) = "5"
    14.     Mnyval(3) = "10"
    15.     Mnyval(4) = "25"
    16.     Mnyval(5) = "50"
    17.     Mnyval(6) = "75"
    18.     Mnyval(7) = "100"
    19.     Mnyval(8) = "200"
    20.     Mnyval(9) = "300"
    21.     Mnyval(10) = "400"
    22.     Mnyval(11) = "500"
    23.     Mnyval(12) = "750"
    24.     Mnyval(13) = "1000"
    25.     Mnyval(14) = "5000"
    26.     Mnyval(15) = "10000"
    27.     Mnyval(16) = "25000"
    28.     Mnyval(17) = "50000"
    29.     Mnyval(18) = "75000"
    30.     Mnyval(19) = "100000"
    31.     Mnyval(20) = "200000"
    32.     Mnyval(21) = "300000"
    33.     Mnyval(22) = "400000"
    34.     Mnyval(23) = "500000"
    35.     Mnyval(24) = "750000"
    36.     Mnyval(25) = "1000000"
    37.  
    38.    
    39.     On Error Resume Next
    40.  
    41.    
    42.     Randomize
    43.     Do Until CaseCollection.Count = UBound(Mnyval) + 1
    44.         intRand = Int(Rnd * (UBound(Mnyval) + 1))
    45.         CaseCollection.Add Item:=CStr(intRand), Key:=CStr(intRand)
    46.     Loop
    47.    
    48.     For intRand = 1 To CaseCollection.Count
    49.         Caseval.Text1.Text = Mnyval(CaseCollection.Item(intRand))
    50.     Next
    51.  
    52. End Sub



    This is code from my Caseval form where all the randomized values are displayed.

    VB Code:
    1. Dim cnt As Integer
    2.  
    3. Private Sub CmdOK_Click()
    4.  
    5. Scoreboard.Visible = True
    6. Caseval.Visible = False
    7. Scoretime.Enabled = True
    8. cnt = 0
    9. If Text1.Text = "0.01" Then
    10. Scoreboard.Label1.BackStyle = Transparent
    11. ElseIf Text1.Text = "1" Then
    12. Scoreboard.Label2.BackStyle = Transparent
    13. ElseIf Text1.Text = "5" Then
    14. Scoreboard.Label3.BackStyle = Transparent
    15. ElseIf Text1.Text = "10" Then
    16. Scoreboard.Label4.BackStyle = Transparent
    17. ElseIf Text1.Text = "25" Then
    18. Scoreboard.Label5.BackStyle = Transparent
    19. ElseIf Text1.Text = "50" Then
    20. Scoreboard.Label6.BackStyle = Transparent
    21. ElseIf Text1.Text = "75" Then
    22. Scoreboard.Label7.BackStyle = Transparent
    23. ElseIf Text1.Text = "100" Then
    24. Scoreboard.Label8.BackStyle = Transparent
    25. ElseIf Text1.Text = "200" Then
    26. Scoreboard.Label9.BackStyle = Transparent
    27. ElseIf Text1.Text = "300" Then
    28. Scoreboard.Label10.BackStyle = Transparent
    29. ElseIf Text1.Text = "400" Then
    30. Scoreboard.Label11.BackStyle = Transparent
    31. ElseIf Text1.Text = "500" Then
    32. Scoreboard.Label12.BackStyle = Transparent
    33. ElseIf Text1.Text = "750" Then
    34. Scoreboard.Label13.BackStyle = Transparent
    35. ElseIf Text1.Text = "1000" Then
    36. Scoreboard.Label14.BackStyle = Transparent
    37. ElseIf Text1.Text = "5000" Then
    38. Scoreboard.Label15.BackStyle = Transparent
    39. ElseIf Text1.Text = "10000" Then
    40. Scoreboard.Label16.BackStyle = Transparent
    41. ElseIf Text1.Text = "25000" Then
    42. Scoreboard.Label17.BackStyle = Transparent
    43. ElseIf Text1.Text = "50000" Then
    44. Scoreboard.Label18.BackStyle = Transparent
    45. ElseIf Text1.Text = "75000" Then
    46. Scoreboard.Label19.BackStyle = Transparent
    47. ElseIf Text1.Text = "100000" Then
    48. Scoreboard.Label20.BackStyle = Transparent
    49. ElseIf Text1.Text = "200000" Then
    50. Scoreboard.Label21.BackStyle = Transparent
    51. ElseIf Text1.Text = "300000" Then
    52. Scoreboard.Label22.BackStyle = Transparent
    53. ElseIf Text1.Text = "400000" Then
    54. Scoreboard.Label23.BackStyle = Transparent
    55. ElseIf Text1.Text = "500000" Then
    56. Scoreboard.Label24.BackStyle = Transparent
    57. ElseIf Text1.Text = "750000" Then
    58. Scoreboard.Label25.BackStyle = Transparent
    59. ElseIf Text1.Text = "1000000" Then
    60. Scoreboard.Label26.BackStyle = Transparent
    61. End If
    62.  
    63.  
    64. End Sub
    65.  
    66. Private Sub Form_Load()
    67. Scoretime.Enabled = False
    68.  
    69.  
    70. End Sub
    71.  
    72. Private Sub Scoretime_Timer()
    73. cnt = cnt + 1
    74. If cnt = 1 Then
    75. Scoreboard.Visible = False
    76. FormCases.Visible = True
    77.  
    78. End If
    79. End Sub
    80. End Sub




    This is the module code i have created so far, however it doesn't seem to work


    VB Code:
    1. Dim z As Double, s As Double, r As Double
    2.  
    3. Public Sub Offercalc()
    4.  
    5.     z = Val(Calculator.Calc.Text)
    6.     Calculator.Calc.Text = Str(z)
    7.    
    8.     r = Val(Money.Offer.Text)
    9.     Money.Offer.Text = Str(r)
    10.    
    11.     s = Var(Caseval.Text1.Text)
    12.     Caseval.Text1.Text = Str(s)
    13. r = z - s
    14. Money.Offer.Text = r
    15. End Sub


    First off, Thanks even for reading all of this. Secondly i know its alot to take in but i need as much input as i can get for this term project as it is worth a HUGE portion of my mark and it is due on TUESDAY JAN 23

    please dont take me as being a procrastinator who calls for help when they are rushing to finish. I have spent a huge amount of time just figuring out the complex vb script to write this program, seeing as i am learning Vb script for the first time this year in school. HELP is MUCH appreciated. Thank you all

  2. #2

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Jan 2007
    Posts
    27

    Re: Module counter / calculating between forms

    Calculator is an invisible form that is used to subtract the selected values from the overall total. Within this textbox is the overall value at the beginning of the game ($3,418,416.01). What i need to happen is , that when a random case value is inputed into my Caseval form Textbox it is subtracted from this total. I attempted at doing this by subtracting the value in the text (s) from the value in the text box of my Calculator form (z)

    also let me post my new and improved code with the proper working randomize function

  4. #4

  5. #5

    Thread Starter
    Junior Member
    Join Date
    Jan 2007
    Posts
    27

    Re: Module counter / calculating between forms

    well first off. i dont think i need the calculator form because i can prob do the calculations using only two textboxes.
    This is the equation i wnat to occur (edited to add the other one)

    r = z - s

    n = r - s

    z= $3,418,416.01

    ex. s= 10,000 (one of the case values)

    ex. r= $3,418,416.01 - 10,000 = $3,408,416.01

    ex . r ($3,408,416.01) - 5,000 = $3,403,416.01

    ex. n ($3,403,416.01) - 200 = $3,403,216.01

    cycle continues

    z would be the beginning total $3,418,416.01 and s would be the value of case chosen. r would be the new number formed from this equation. i would then need s to be subtracted from r when another value was chosen. this subtraction of values would have to repeat 6 times ( round 1 complete) and an offer would be generated the equation for the offer being : current total ($3,418,416.01-amount of cases chosen to that point) divided by the number of remaining cases (20). if they accept the offer ("Deal") the game ends . if they decline the offer current total would go back to what it was before the division and the game would continue on and this time 5 cases would be chosen and the equation would repeat again: current total ($3,418,416.01-amount of cases chosen to that point) divided by the number of remaining cases (15). if they decline the offer again the game continues and this time they select 4 cases and this cycle continues (reference to my chart on my first post showing the amount of cases picked each round).

    i hope you now understand what i wish for this to do.
    Last edited by koolnewb; Jan 20th, 2007 at 06:46 PM.

  6. #6
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431

    Re: Module counter / calculating between forms

    Too much information Let's try something simple. What am I doing wrong here in this simplified code?

    VB Code:
    1. Dim z As Double, s As Double, r As Double
    2.  
    3.     z = 3418416.01
    4.    
    5. '    r = ???
    6.    
    7.     s = 10000
    8.  
    9. r = z - s
    10.  
    11. MsgBox FormatCurrency(r) ' which is $3,408,416.01

  7. #7

    Thread Starter
    Junior Member
    Join Date
    Jan 2007
    Posts
    27

    Re: Module counter / calculating between forms

    well from what i can tell.

    FormatCurrency isnt declared

    r doesnt have a value

    z, r, s arent strung as values (not to sure about that)

    and possibly nothing is activating the r = z -s (command button, etc.)

  8. #8
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431

    Re: Module counter / calculating between forms

    FormatCurrency isnt declared ==> Do you use VB6?

    r doesnt have a value ==> Aren't we calculating r?

    z, r, s arent strung as values (not to sure about that) ==> for the purposes of my example it shouldn't matter

    and possibly nothing is activating the r = z -s (command button, etc.) ==> Ditto

  9. #9

    Thread Starter
    Junior Member
    Join Date
    Jan 2007
    Posts
    27

    Re: Module counter / calculating between forms

    using vb 5.0

  10. #10

  11. #11

    Thread Starter
    Junior Member
    Join Date
    Jan 2007
    Posts
    27

    Re: Module counter / calculating between forms

    so if i put the

    r = z - s into a command button it would work the equation would calculate?

  12. #12

  13. #13

    Thread Starter
    Junior Member
    Join Date
    Jan 2007
    Posts
    27

    Re: Module counter / calculating between forms

    Is there another way i can send you my project so i can send a bigger zipped file. If you see my program you can understand what im trying to do

  14. #14
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431

    Re: Module counter / calculating between forms

    Quote Originally Posted by koolnewb
    Is there another way i can send you my project so i can send a bigger zipped file. If you see my program you can understand what im trying to do
    How big is it when it is put in zip or rar format?

  15. #15

    Thread Starter
    Junior Member
    Join Date
    Jan 2007
    Posts
    27

    Re: Module counter / calculating between forms

    548 kb

  16. #16

    Thread Starter
    Junior Member
    Join Date
    Jan 2007
    Posts
    27

    Re: Module counter / calculating between forms

    548 kb

  17. #17

  18. #18

    Thread Starter
    Junior Member
    Join Date
    Jan 2007
    Posts
    27

    Re: Module counter / calculating between forms

    Bitmaps in my forms and command buttons

  19. #19

  20. #20

    Thread Starter
    Junior Member
    Join Date
    Jan 2007
    Posts
    27

    Re: Module counter / calculating between forms

    k ill do that. heres first part
    Attached Files Attached Files

  21. #21

    Thread Starter
    Junior Member
    Join Date
    Jan 2007
    Posts
    27

    Re: Module counter / calculating between forms

    this is part 2
    Attached Files Attached Files

  22. #22
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431

    Re: Module counter / calculating between forms

    Okay I've downloaded both parts. When I ran it I found a few things that I would change if it were my program.
    • The blue text against the yellow/brown bitmap is hard to read so I'd make it some other color, and
    • I would change "Input, into the Text box Number of the Case you wish to be Yours" to something like "Please enter the Case (1 to 26) you wish to be yours", and
    • validate the in fact the user enters a number between 1 and 26
    But you probably want me to help fix problems you already know about so please tell me exactly (with specific numbers, button clicks, etc.) what it takes to produce a wrong result, what that result is, and what it should be.

  23. #23

    Thread Starter
    Junior Member
    Join Date
    Jan 2007
    Posts
    27

    Re: Module counter / calculating between forms

    very good tips. i wanna keep the bitmap because it is the deal or no deal background, but i think im gonna change it.

    Well as you saw in my program. When you click a case it sends you to a new form where the value of that case is displayed. and there is a command button entitled "OK" upon pressing this command button would be when the calculations are made. The number in the text box above it (the case value) would be subtracted from the overall total (3418416.01). THen the scoreboard appears and then it returns to the main form. the user clicks another case. they are sent to the caseval you form again. THe value of their case is displayed in the text box. THey press OK and the number in the text box is subtracted from the new total ( 3418416.01 - the value of the first case) scoreboard appears and then returns back to main form. This cycle continues. When 6 cases are open the current total (3418416.01
    - the 6 case values) is divided by 20 (the number of remaining cases) creating the first offer which is displayed in the form entitled "Money" . if they accept the offer the game ends. If not the game continues and the user picks 5 cases this time. This cycle follows this order:

    round 1. 6 cases till offer is generated
    round 2. 5 cases till offer is generated
    round 3. 4 cases till offer is generated
    round 4. 3 cases till offer is generated
    round 5. 2 cases till offer is generated
    round 6. 1 cases till offer is generated
    round 7. 1 cases till offer is generated
    round 8. 1 cases till offer is generated
    round 9. 1 cases till offer is generated
    round 10. They take the value of their case.

    I am currently working on the writeup for this project. My teacher said hed help me with this problem at school but your input would be extremely helpful. I will definatly use those tips you gave me

    and again THanks for all you help throughout this weekend

  24. #24

  25. #25

    Thread Starter
    Junior Member
    Join Date
    Jan 2007
    Posts
    27

    Re: Module counter / calculating between forms

    well, with the code i have set up in the program i sent you

    the result.. is nothing

    nothing happens

    the calculations arent made

    and it doesnt recognize when a round is over

    Most of the code i set up for this is in my module. I think the problem lies there. For some reason the code doesnt execute

    the result i wish to happen is what i explained in my last post. For the value of the case (displayed in the Form "Caseval") to be subtracted from the overall total (3418416.01). after 6 casevalues were subtracted from the total it would be divided by the number of remaining cases.. and so on according to my last post.

  26. #26

  27. #27

    Thread Starter
    Junior Member
    Join Date
    Jan 2007
    Posts
    27

    Re: Module counter / calculating between forms

    sorry I am currently busy studying for exams. My teacher is planning to help me out after his exam so if i figure this problem out completely i will submit the answer on this forum

    Id also like to thank you Martin very much for you help this past week

  28. #28

  29. #29

    Thread Starter
    Junior Member
    Join Date
    Jan 2007
    Posts
    27

    Re: Module counter / calculating between forms

    well i already had to submit it today (teacher will help me after his exam on friday), but for future reference i am not entirely sure how i would go about doing that and where i would input the code.

    thank you

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