Having problem make last if an statement work in the code. the variables in the if statment are doubles but the ide keep telling i need a proceeding if statement. but is already there
it is in the last if statement of the code

Public Class Form1

    Dim Totals As New List(Of Double)

    Private Sub btnclear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnclear.Click

        txtbxscore.Clear()
        txtbsbest.Clear()
        txtbxnumber.Clear()
        txtbxaverage.Clear()
        Totals.Clear()

    End Sub

    Private Sub btnaverage_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnaverage.Click

        Dim BestScore As Double
        Dim Scores As Double
        Dim AverageScore As Double
        Dim FutureJob As Image = My.Resources.future
        Dim Delivery As Image = My.Resources.Delivery
        Dim Fries As Image = My.Resources.Fries
        Dim Doctor As Image = My.Resources.Doctor
        Dim Pilot As Image = My.Resources.Pilot

        If IsNumeric(txtbxscore.Text) AndAlso Val(txtbxscore.Text) >= 0.0 AndAlso Val(txtbxscore.Text) <= 100.0 Then
            Scores = Val(txtbxscore.Text)

        Else : MessageBox.Show("Either a nonnumeric value or not a number between 0 and 100")
            txtbxscore.Clear()
            txtbsbest.Clear()
            txtbxnumber.Clear()
            txtbxaverage.Clear()
            Totals.Clear()
            txtbxscore.Select()

        End If

        Totals.Add(Scores)
        AverageScore = Totals.Sum / Totals.Count
        BestScore = Totals.Max()
        txtbxnumber.Text = Totals.Count
        txtbsbest.Text = Math.Round(BestScore, 2)
        txtbxaverage.Text = Math.Round(AverageScore, 2)

        If (AverageScore) > 70.0 Then FutureJob = Fries

        ElseIf (AverageScore) >= 70.0 And (AverageScore) > 80.0 Then FutureJob = Delivery
        ElseIf (AverageScore) >= 80.0 And (AverageScore) > 90.0 Then FutureJob = Pilot 
        ElseIf (AverageScore) >= 90.0 And (AverageScore) < 100.0 Then FutureJob = Doctor

        Else FutureJob = future

        End If 

        picbxfuture.Image = FutureJob

    End Sub

    Private Sub btnexit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnexit.Click

        Me.Close()

    End Sub

End Class

Hi,

This:

Else FutureJob = future

Should be:

Else 
FutureJob = future

ok weird but does not work elseif's still says requires a precceding if of elseif

Member Avatar for Unhnd_Exception

If your trying to add the statement in one line like above then you need to add a semi colon after then when more than 1 statement. Or put the code on a seperate line like Luc001 posted.

Example

Dim Variable As Integer = 2

'Single line statement with else and elseif
If Variable = 1 Then : Variable = 4
ElseIf Variable = 2 Then : Variable = 5
ElseIf Variable = 3 Then : Variable = 6
End If


If Variable = 4 Then
      Variable = 1
ElseIf Variable = 5 Then
      Variable = 2
ElseIf Variable = 6 Then
      Variable = 3
End If

ok that works . One more question I have the form level to acceptreturn and pointed to the button containing the code i want to run . in vb. to you have to have something else; an event watcher of some kind ?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.