Michael Selvesakis Michael Selvesakis - 3 months ago 17
Vb.net Question

I need some correction VB.net Code Framework 2.0 making a register system

In my program, I want to to check if my app is registered when my progress bar is finished. If it is Registered (checked by the text of a label in form 1) the second textbox should appear and if is not registered the first text box should appear

The problem is that I must add an end

if
when I don't want to because it will continuously pop up the textbox.

This is my code:

Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
ProgressBar1.Value += 1
If ProgressBar1.Value =
ProgressBar1.Maximum Then
Timer1.Stop()
ProgressBar1.Value = ProgressBar1.Minimum
If Form1.Label4.Text = "Unregistered" Then
MsgBox("Exampletext", MsgBoxStyle.Information)
Me.Hide()
Else
MsgBox("Exampletext1", MsgBoxStyle.Information)
Hide()
End If
End Sub
End Class


BTW: I didn't wanted to make it in
framework 2.0
but I made it, to make it more compatible with older Windows.

Answer

This is why correct indentation is important...

The compiler thinks that the Else is related to the first If.

And actually, nothing will ever happen when your second If is correct because there is no End If. Therefore it is assuming that the instruction is on the same line.

Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
ProgressBar1.Value += 1
    If ProgressBar1.Value = ProgressBar1.Maximum Then
        Timer1.Stop()
        ProgressBar1.Value = ProgressBar1.Minimum
        If Form1.Label4.Text = "Unregistered" Then
            MsgBox("Exampletext", MsgBoxStyle.Information)
            Me.Hide()
        Else
            MsgBox("Exampletext1", MsgBoxStyle.Information)
            Hide()
        End If
    End If 'You need to add the End If here
End Sub

I am however voting to close this question as it is a typo error...

Comments