Hello there. I made a menu strip item for word wrap and I want to have it trigger word wrap (on and off) in my textbox1... but I get the error 'Else' must be preceded by a matching 'If' or 'ElseIf'. I also get 'If' must be preceded by a matching 'If'.
On top of all that, I am not even sure my coding is right because I am not able to compile with the erros.
Private Sub WordWrapToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles WordWrapMenuItem.Click
Dim Textbox1 As TextBox
If (WordWrapMenuItem.CheckState = CheckState.Checked) Then TextBox1.WordWrap = True
Else : TextBox1.WordWrap = False End If
End Sub
End
Class
If's and Elseif's
Guru
RC_SSIS
I believe if you put the 'then' and the following code all on the same line, then no end if is required, which means the else and end if are orphaned. Try putting the lines that set the values of the Textbox below the lines that contain if and else statement.
I also did not think that a colon came after the else.
// Dim Textbox1 As TextBox
This is a waste of time, you're creating a local textbox which will disappear when the function goes out of scope. There should be a text box member variable, which you should be modifying,
If (WordWrapMenuItem.CheckState = CheckState.Checked) Then
TextBox1.WordWrap = True
ElseTextBox1.WordWrap = False
End IfOr better yet:
TextBox1.WordWrap = (WordWrapMenuItem.CheckState = CheckState.Checked)