-
I trying to do this...
Make a program that once the user presses the command button a text message appears..and then if he presses he/she command button again, a different message appears.
I have the user interface finished,also i have the code done for the first message that appears,but what code/else do i do??
I appreciate any help.
-
Private Sub Command1_Click
Static blnState As Boolean
If not blnState Then
MsgBox "Message 1"
else
MsgBox "Message 2"
End If
blnState = blnState + 1
End Sub
-
-
Sascha's code switches btween message 1 and message 2 each time the command button is pressed
if you want message 2 to be displayed for all presses >1 then set blnState to true after the first press
I expect you worked this out for yourself anyway :)
Code:
Private Sub Command1_Click()
Static blnState As Boolean
If Not blnState Then
MsgBox "Message 1"
blnState = True
Else
MsgBox "Message 2"
End If
End Sub
-
Ok this is probably needless, but try it out ;)
Code:
Private Sub Command1_Click()
Static blnState%
select case blnState
case blnstate 1
Msgbox "Message 1"
case blnstate 2
Msgbox "Message 1"
case blnstate 3 to 5
Msgbox "Messages for 3 to 5"
case blnstate else
Msgbox "Messages after that"
end select
blnState=blnState+1
End Sub
-
Dim Check as Boolean
Private Sub Command1_Click()
If Check = False Then
Msgbox "Message 1"
Check = True
Else
Msgbox "Message 2"
Check = False
End if
End Sub
When you click the first time, Message 1 will be shown. The second time you click Message 2 will be shown. The third time you click Message 1 will be shown, and so on....
/Smirre
-
If you want to use the code in multiple CommandButtons, you can Declare it as Public or Global, in a module then use Kedaman's Code. (without the Static variable)
-
If you don't want any more answer lock this thread