Updating a textbox

chris_clarke

New Member
Joined
Feb 11, 2006
Messages
5
Hi, i'm making a gamethat contains 2 Dice and a counter, when the "Roll Dice" button is pressed i want the Dice to show the values and then the counter to move according tot he value of the Dice.

I can get all of this done, using text boxes to display the Dice value and using a macro to work out the new dice value and then move the counter.

My problem is that the counter moves before the text boxes update with the new number. I've tried putting the Dice code in one macro and the move coutner code in another macro and then running one macro after the other, however this still doens't update the textbox values before moving the counter.

Does anybody have any idea on how i could get this done?
 

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand
I’m not quite following 100% but my suggestion would be to try using the line:
Code:
DoEvents
Somewhere in the code.

This command forces all of the calculations in the code and the worksheet to complete before the code continues. Try putting it after the part that updates your TextBox and before the part that moves the counter.
 
Upvote 0
Hasn't worked.

The code i have at the moment is

Code:
Private Sub cmd_DiceShaker_Click()
    RollDice
    DoEvents
    MoveCounter
End Sub

and the code in RollDice is

Code:
Randomize
Worksheets("Board").TextBox1.Value = Int((6 - 1 + 1) * Rnd) + 1
Worksheets("Board").TextBox2.Value = Int((6 - 1 + 1) * Rnd) + 1

I just don't get why it won't update the values straight away before it runs MoveCounter
 
Upvote 0
I'm still stumped by it, i've tried using a label instead of a textbox and the value updates instantly, however i can't get the formatting of the label the way it needs to be so it's no good really :(
 
Upvote 0
Sounds like a Label might be the way to go then. How do you need it formatted? This might be easier to achieve than figuring out why your TextBox doesn’t update.
 
Upvote 0
Changing the format of the label seems to be a no go as well. If i use a form control label then it updates when I want it to, however i can't seem to do any kind of formatting to it. if i use an active x label then i can format it however i want but it won't update.

I take it this means it must be the active x controls that don't update until all macros have been completed. Surely there must be some way of getting around this?
 
Upvote 0

Forum statistics

Threads
1,214,661
Messages
6,120,797
Members
448,994
Latest member
rohitsomani

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top