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")
sw.WriteLine(calculate)
sw.Close()``````

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?

3
Contributors
7
Replies
8
Views
7 Years
Discussion Span
Last Post by afaque01

Hi!

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

``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()``````

l8.text is a form of a string not a numeric value -_-

did you check that ???

Edited by ShahanDev: didn't see expert name

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

Hmm...

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";
etc.....

Awsome .. thanks!