user5717551 user5717551 - 5 months ago 14
Vb.net Question

VB ElseIf Statement Limited to 1

I was forced by college to do a application in Visual Studio (Basic) and I never had expierence with this language before so I'm confused. I did

If
statement which is working and then I've added
EleseIf
which is also working but after I've added Second
ElseIf
it doesn't work. It seems like only
If
statement and the first
ElseIf
is working for me but I need more than just 1
ElseIf
statement.

Public Class receipt
Private Sub receipt_Load(sender As Object, e As EventArgs) Handles Me.Load
Dim outputValue As Decimal = My.Settings.outputamount.Remove(4)
Dim calculation As Decimal = outputValue * My.Settings.inputamount
Dim totalwithoutcharge As String = calculation.ToString
customername.Text = "Name: " + My.Settings.Username
Label6.Text = "Entered Money: " + My.Settings.inputamount + " " + My.Settings.currency
Label7.Text = "Converted To: " + totalwithoutcharge + " " + My.Settings.outputcurrency

If calculation < 100 Then
Label8.Text = "Charge: 0%"
Label9.Text = "Total: " + totalwithoutcharge + " " + My.Settings.outputcurrency
ElseIf calculation > 100 Then
Label8.Text = "Charge: 1%"
Label9.Text = "Total: " + totalwithoutcharge + " " + My.Settings.outputcurrency
ElseIf calculation > 500 Then
Label8.Text = "Charge: 2%"
Label9.Text = "Total: " + totalwithoutcharge + " " + My.Settings.outputcurrency
ElseIf calculation > 1000 Then
Label8.Text = "Charge: 3%"
Label9.Text = "Total: " + totalwithoutcharge + " " + My.Settings.outputcurrency
Else
Label8.Text = "Something went wrong"
End If
End Sub
End Class


I've entered many values I've add over 600 and it was still showing 'Charge: 1%' where it should show 2% instead. The same happen with values higher than 1000 it will still show the 1%. But when the value is below 100 then is OK and it is showing 0%.

Over 100 works fine too
Over 500 doesn't work

I've also tried to do it with two conditions where it would look at range but it didn't work too.
I've tried 'ElseIf calculation > 100 And calculation > 500 Then' but there is no difference.

Answer

Based on my comment

    If calculation >= 1000 Then

    ElseIf calculation >= 500 Then

    ElseIf calculation >= 100 Then

    Else
        'lass than 100
    End If
Comments