|
-
Jun 30th, 2005, 05:16 AM
#1
Thread Starter
Member
Command button caption problem
hi all
i have a command button with caption = "V".
when i click, i want to toggle between "v" and "X", so here
is what i wrote in the code:
VB Code:
Private Sub cmdFillAgain_Click()
If gFillAgain = True Then
cmdFillAgain.Caption = "X"
Else
cmdFillAgain.Caption = "V"
End If
gFillAgain = Not gFillAgain
End Sub
but in the first time i click the button, the Caption remains "x" even though
the gFillAgain variable is changing as it should.. it looks like only the first time the button is clicked doesnt work, because after that i have no problems...
any idea???
thanks
-
Jun 30th, 2005, 05:25 AM
#2
Re: Command button caption problem
 Originally Posted by stingran
hi all
i have a command button with caption = "V".
when i click, i want to toggle between "v" and "X", so here
is what i wrote in the code:
VB Code:
Private Sub cmdFillAgain_Click()
If gFillAgain = True Then
cmdFillAgain.Caption = "X"
Else
cmdFillAgain.Caption = "V"
End If
gFillAgain = Not gFillAgain
End Sub
but in the first time i click the button, the Caption remains "x" even though
the gFillAgain variable is changing as it should.. it looks like only the first time the button is clicked doesnt work, because after that i have no problems...
any idea???
thanks
I am assuming that gFillAgain is a Boolean Variable. This code worked fine for me:
VB Code:
Option Explicit
Dim gFillAgain as Boolean
Private Sub Form_Load()
gFillAgain = True
cmdFillAgain.Caption = "V"
End Sub
Private Sub cmdFillAgain_Click()
If gFillAgain Then
cmdFillAgain.Caption = "X"
Else
cmdFillAgain.Caption = "V"
End If
gFillAgain = Not gFillAgain
End Sub
Regards,
Mark
Please remember to rate posts! Rate any post you find helpful. Use the link to the left - "Rate this Post". Please use [highlight='vb'] your code goes in here [/highlight] tags when posting code. When a question you asked has been resolved, please go to the top of the original post and click "Thread Tools" then select "Mark Thread Resolved."
-
Jun 30th, 2005, 05:30 AM
#3
Thread Starter
Member
Re: Command button caption problem
yes, this variable is defined as a boolean in a module:
[public gFillAgain as boolean]
and in Form Load i assign in to TRUE.
so why doesnt it work for me?
-
Jun 30th, 2005, 05:32 AM
#4
Re: Command button caption problem
In your code, just move the re-assignment from the bottom of the proc to the top:
VB Code:
Private Sub cmdFillAgain_Click()
[b]gFillAgain = Not gFillAgain[/b]
If gFillAgain = True Then
cmdFillAgain.Caption = "X"
Else
cmdFillAgain.Caption = "V"
End If
'gFillAgain = Not gFillAgain
End Sub
chem
Visual Studio 6, Visual Studio.NET 2005, MASM
-
Jun 30th, 2005, 05:34 AM
#5
Thread Starter
Member
Re: Command button caption problem
indeed!!!! it is working...
but why is it needed to assign the valua BEFORE???
is there a logic explenation?
-
Jun 30th, 2005, 05:49 AM
#6
Re: Command button caption problem
It just seemed, whatever you were doing, didnt work the first time, which meant the conditional statement wasn't to what it should be at the start. To show you, set the default caption of the button to "V". Then run it using your first lot of code.
chem
Visual Studio 6, Visual Studio.NET 2005, MASM
-
Jun 30th, 2005, 12:54 PM
#7
Re: Command button caption problem
You could eleminate an extra unnecessary variable and achieve the same in one line also like this:
VB Code:
Private Sub cmdFillAgain_Click()
cmdFillAgain.Caption = IIf(cmdFillAgain.Caption = "X", "V", "X")
End Sub
-
Jun 30th, 2005, 02:22 PM
#8
Re: Command button caption problem
When you assigned the value, it called the routine, which switched the value. I had that happen to me. I always set the initial value to the opposite of what I wanted in the form load.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|