Yahtzee Totals

jjss_19
12-03-2009, 03:08 PM
Hi I'm creating a modified version of Yahtzee game. I have a textbox in which when all the dice roll their totals all added up are shown in the textbox. I have the user rolling three times then the third roll's totals are shown. At the end of one round the total is shown. A problem i am having is when i start a new round the total is wiped out. How can i make it so that the total of a new round is added to the players existing total?

The code I have right now is:

'randomizing my 5 dice
Randomize
a=Int(Rnd * 6) + 1
b=Int(Rnd * 6) + 1
c=Int(Rnd * 6) + 1
d=Int(Rnd * 6) + 1
e=Int(Rnd * 6) + 1

t = a + b + c + d + e

imgDice1(a).Visible = True
imgDice2(b).Visible = True
imgDice3(c).Visible = True
imgDice4(d).Visible = True
imgDice5(e).Visible = True

If ct = 3 Then
txtsum.text = t
msgbox "begin new round"
cmdRoll.Enabled = true
Form_load
End If

Qua
12-03-2009, 05:01 PM
I can't tell directly from your code why the total is being wiped out, however, I do have a feeling that calling Form_load is the wrong approach inside this function. If the variable t contains the total of a round, are you sure that you've declared this variable on a class scope, so it maintains it's value even the the function ends? Once the function ends all variables are "deleted" and thus their values will be reset next time this function is called.

jjss_19
12-03-2009, 06:49 PM
The reason I am calling on form_load is because if I don't when I get into later rounds the dice eventually just stop randomizing and they sit on six. By calling on form_load its randomizing each and every round.

Iceplug
12-03-2009, 07:28 PM
Is the total being stored directly into the textbox? Perhaps you should store the total in a variable. If you are indeed reloading the form, you should have the total in a Module.
Then, you store the value of total in the textbox (or label).

jjss_19
12-03-2009, 08:03 PM
I'm slightly new to VB6, how can i do that?

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum