Iam trying to Calculate The values From 2 Comoboboxes.....But sometimes its calculating and sometimes its Showing BOOLEAN conversion problem... Plz SEE the code .

If C1.Text = "Agra Fort" Andalso C3.Text = "Delhi" Then
            l8.Text = 800
        ElseIf C1.Text = "agra fort" Andalso C3.Text = "bangalore" Then
            l8.Text = 1200
        ElseIf C1.Text = "agra fort" Andalso C3.Text = "gaya" Then
            l8.Text = 600
        ElseIf C1.Text = "agra fort" Andalso C3.Text = "goa" Then
            l8.Text = 350
        ElseIf C1.Text = "agra fort" Andalso C3.Text = "howrah" Then
            l8.Text = 270
        End If

        Dim child = l8.Text / 2
        Dim child2 As Double
        child2 = child * Cb3.Text

        Dim adult As Double = Cb1.Text * l8.Text
        Dim calculate As Double = child2 + adult
        Label12.Text = calculate
        Label15.Text = child
        Dim sw As New IO.StreamWriter("c:/fare.txt")

in child iam making the value half as compared to Amount of Adult fare , then in child2 storing value child{which contains Fare of Per child} multiplying by value entered in combobox{cb3} which can be 1,2,3...etc
Now iam storing the total calculation {adult fare + child fare} in calculate.
after that simply display and store...

Here iam getting Error On boolean conversion .. but some times it is converting...
and its only taking value of 1st expression :

If C1.Text = "Agra Fort" And C3.Text = "Delhi" Then
            l8.Text = 800

if i sellect any other expression its not doin any thing...
where am i getting wrong?

6 Years
Discussion Span
Last Post by afaque01


I found some problems in your code i.e., declare variable(s) with appropriate type and consider conversion where necessary

Your line 13 should be:

Dim child as Double = CDbl(l8.Text) / 2

and Line 15:

child2 = child * CDbl(Cb3.Text)

Similarly line 17 - 20:

Dim adult As Double = CDbl(Cb1.Text) * CDbl(l8.Text)
Dim calculate As Double = child2 + adult
Label12.Text = calculate.ToString()
Label15.Text = child.ToString()
Votes + Comments

HI..! thanks Friends...
Same error Still presists... at line 13 showing type conversion to double not valid..
but its calculating the amount for 1st expression that is Agra to delhi... if iam selecting any other station its showing Conversion error


Done ... friends.....
I more Question Why is STRING So case sensitive?....... another Error was due to Lower case letters i was putting.....
Thank u very much friends @ Engr. Shahan Ayyub



So for case-insensitive comparison, do like this:

If C1.Text.ToLower() = "Agra Fort".ToLower() AndAlso C3.Text.ToLower() = "Delhi".ToLower() Then
	l8.Text = "800"
End If

It will work for such kind of samples as well:

C1.Text = "AgrA FORT";
C1.Text = "agra FORT";
C1.Text = "AgrA FOrT";
C3.Text = "DELHI";
C3.Text = "DeLHi";

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.