Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Silly problem with a Button

Status
Not open for further replies.

tbl

Technical User
May 15, 2001
175
BE
I have created a button (called StartComms) on a form, and want the button text to change each time it is pressed. The code does NOT work if I just step through it, because although StartComms.Text does equal "Start Logging", the IF statement does not execute. If I force the execution of the second line after the IF as marked, the the code will work and continue to work perfectly until the program is re-opened !
What am I doing wrong ?

Richard

Private Sub StartComms_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles StartComms.Click

If StartComms.Text = "Start Logging" Then
StartComms.Text = "Stop Logging" 'force code here
StartComms.FlatStyle = FlatStyle.Flat
StartComms.BackColor = BackColor.Lime
ElseIf StartComms.Text = "Stop Logging" Then
StartComms.Text = "Start Logging"
StartComms.FlatStyle = FlatStyle.Standard
StartComms.BackColor = System.Drawing.SystemColors.Control
End If

End Sub
 
Code:
  If StartComms.Text.tolower = "start logging" Then
            StartComms.Text = "Stop Logging" 'force code here
            StartComms.FlatStyle = FlatStyle.Flat
            StartComms.BackColor = BackColor.Lime
        ElseIf StartComms.Text.tolower = "stop logging" Then
            StartComms.Text = "Start Logging"
            StartComms.FlatStyle = FlatStyle.Standard
            StartComms.BackColor = System.Drawing.SystemColors.Control
        End If

tell me if this works?

Christiaan Baes
Belgium

What a wonderfull world - Louis armstrong
 
Thanks Christiaan,
it didn't work but it did give me the answer !
I had somehow introduced an invisible character into my default Text under Properties. Your code made my mistake obvious.

Thanks

m.v.g.

Richard
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top