473,324 Members | 2,548 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,324 software developers and data experts.

Trouble with conversion of "" in an equation

I have written a simple program that calculates a running $ total. This
program uses a checkbox to acknowledge that that version of the ticket
is desired and it checks the Qty box to see how many tickets are
desired. Based upon the checkbox being checked and the number of tickets
desired directly affects the running grand total (of course!). OK I
have set where if ticketsDesiredTotal>0 then checkbox.checked = true.
The only problem I have is that if the user deletes the number of
tickets and the user does not enter a number and “ ” is in the tickets
desired box the program crashes. It crashes because it is taking the
value of TicketsDesiredTotal and multiplying it by the per ticket cost.
And the debugger says it can’t convert “” to use it in the equation.
How can I make this thing work??? Here is the code and the function it
calls:

Function processor()

Dim decTtl As Decimal = 0.0

Dim strOil As String = txtQtyOil.Text
If cbOil.Checked = True Then
lblOilTtl.Text = (txtQtyOil.Text * 150.0)
decTtl += lblOilTtl.Text
End If
If cbAllies.Checked = True Then
lblAlliesTtl.Text = (txtQtyAllies.Text * 50.0)
decTtl += lblAlliesTtl.Text
End If
If cbWardaddy.Checked = True Then
lblWarTtl.Text = 0.0
decTtl += lblWarTtl.Text
End If
lblSubTotal.Text = String.Format("{0:C}", decTtl)

Dim decTxTtl = CDec(decTtl * 0.07)

lblTaxTtl.Text = String.Format("{0:C}", decTxTtl)
lblGrandTtl.Text = String.Format("{0:C}", (decTxTtl + decTtl))
End Function


Private Sub cbOil_CheckedChanged(ByVal sender As System.Object, ByVal
e As System.EventArgs) Handles cbOil.CheckedChanged
processor()
End Sub

Private Sub cbAllies_CheckedChanged(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles cbAllies.CheckedChanged
processor()

End Sub

Private Sub cbWardaddy_CheckedChanged(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles cbWardaddy.CheckedChanged
processor()

End Sub
Mike_Mac

*** Sent via Devdex http://www.devdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 20 '05 #1
2 1435
I think you gave us the wrong code or not enough of it. Nonetheless, there
are many different ways of handling an empty string that represents zero.
Two simple methods: either exit the sub when you have an empty string or
convert all empty strings to zero before doing the math. There are endless
permutations of textbox validation of course, including creating an extended
textbox class that has all the validation built-in.

"Michael MacDonald" <ma***********@yahoo.com> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
I have written a simple program that calculates a running $ total. This
program uses a checkbox to acknowledge that that version of the ticket
is desired and it checks the Qty box to see how many tickets are
desired. Based upon the checkbox being checked and the number of tickets
desired directly affects the running grand total (of course!). OK I
have set where if ticketsDesiredTotal>0 then checkbox.checked = true.
The only problem I have is that if the user deletes the number of
tickets and the user does not enter a number and " " is in the tickets
desired box the program crashes. It crashes because it is taking the
value of TicketsDesiredTotal and multiplying it by the per ticket cost.
And the debugger says it can't convert "" to use it in the equation.
How can I make this thing work??? Here is the code and the function it
calls:

Function processor()

Dim decTtl As Decimal = 0.0

Dim strOil As String = txtQtyOil.Text
If cbOil.Checked = True Then
lblOilTtl.Text = (txtQtyOil.Text * 150.0)
decTtl += lblOilTtl.Text
End If
If cbAllies.Checked = True Then
lblAlliesTtl.Text = (txtQtyAllies.Text * 50.0)
decTtl += lblAlliesTtl.Text
End If
If cbWardaddy.Checked = True Then
lblWarTtl.Text = 0.0
decTtl += lblWarTtl.Text
End If
lblSubTotal.Text = String.Format("{0:C}", decTtl)

Dim decTxTtl = CDec(decTtl * 0.07)

lblTaxTtl.Text = String.Format("{0:C}", decTxTtl)
lblGrandTtl.Text = String.Format("{0:C}", (decTxTtl + decTtl))
End Function


Private Sub cbOil_CheckedChanged(ByVal sender As System.Object, ByVal
e As System.EventArgs) Handles cbOil.CheckedChanged
processor()
End Sub

Private Sub cbAllies_CheckedChanged(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles cbAllies.CheckedChanged
processor()

End Sub

Private Sub cbWardaddy_CheckedChanged(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles cbWardaddy.CheckedChanged
processor()

End Sub
Mike_Mac

*** Sent via Devdex http://www.devdex.com ***
Don't just participate in USENET...get rewarded for it!

Nov 20 '05 #2
Hi Michael,

Probabley the most simple thing is to set in top of your program
Option Strict On,

Than you are told that you cannot do a
myString = 1 * 3
There are a lot of simple conversions in Visual Basic which are very handy
and extends very much the single dotNet namespace. By instance Cint (convert
to integer) and Cdbl (convert to double).

If you have more questions about this please reply, not any problem at all.
However place first that Option Strict On

I hope this helps?

Cor

I have written a simple program that calculates a running $ total. This
program uses a checkbox to acknowledge that that version of the ticket
is desired and it checks the Qty box to see how many tickets are
desired. Based upon the checkbox being checked and the number of tickets
desired directly affects the running grand total (of course!). OK I
have set where if ticketsDesiredTotal>0 then checkbox.checked = true.
The only problem I have is that if the user deletes the number of
tickets and the user does not enter a number and " " is in the tickets
desired box the program crashes. It crashes because it is taking the
value of TicketsDesiredTotal and multiplying it by the per ticket cost.
And the debugger says it can't convert "" to use it in the equation.
How can I make this thing work??? Here is the code and the function it
calls:

Function processor()

Dim decTtl As Decimal = 0.0

Dim strOil As String = txtQtyOil.Text
If cbOil.Checked = True Then
lblOilTtl.Text = (txtQtyOil.Text * 150.0)
decTtl += lblOilTtl.Text
End If
If cbAllies.Checked = True Then
lblAlliesTtl.Text = (txtQtyAllies.Text * 50.0)
decTtl += lblAlliesTtl.Text
End If
If cbWardaddy.Checked = True Then
lblWarTtl.Text = 0.0
decTtl += lblWarTtl.Text
End If
lblSubTotal.Text = String.Format("{0:C}", decTtl)

Dim decTxTtl = CDec(decTtl * 0.07)

lblTaxTtl.Text = String.Format("{0:C}", decTxTtl)
lblGrandTtl.Text = String.Format("{0:C}", (decTxTtl + decTtl))
End Function


Private Sub cbOil_CheckedChanged(ByVal sender As System.Object, ByVal
e As System.EventArgs) Handles cbOil.CheckedChanged
processor()
End Sub

Private Sub cbAllies_CheckedChanged(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles cbAllies.CheckedChanged
processor()

End Sub

Private Sub cbWardaddy_CheckedChanged(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles cbWardaddy.CheckedChanged
processor()

End Sub
Mike_Mac

*** Sent via Devdex http://www.devdex.com ***
Don't just participate in USENET...get rewarded for it!

Nov 20 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Miki Tebeka | last post by:
Hello All, I'm shipping an application using py2exe. With Python2.3 it worked fine but when switching to Python2.4 I started getting "warning: string/unicode conversion" all over the place. ...
8
by: Dgates | last post by:
Has anyone typed up an index for the O'Reilly book "C# and VB.NET Conversion?" I'm just learning C#, and often using this little book to see which VB.NET terms translate directly to some term in...
2
by: George Durzi | last post by:
Hey folks, I just installed VS .NET 2003 on top of Windows 2003 Server. I was opening a Web Project from source control, and got a warning that the project would have to be "converted", and that I...
5
by: Hayato Iriumi | last post by:
When converting a type to another using CType and if the type conversion fails, it throw an exception. However, in C#, there is a keyword "as" which only makes the variable Nothing (null) without...
1
by: Philip Bondi | last post by:
Hello to all SQL Server junkies who work with non-English characters: For people running scripts from the command line using ANSI files with special characters, it is very important to use isql...
0
by: avidcoder | last post by:
HI all I am a beginner in XML space . Some one give me ideas about how to develop a """" Good GUI implementation with "xml conversion" using XSLT as backend solution""" Actually i want...
26
by: drako | last post by:
Hi, I'm a bit stumped as I am getting a "Notice: Array to String Conversion" error when trying to do something that on the surface should be a very simple task - create an array, and write a set...
11
by: arnuld | last post by:
i have created a new temperature conversion programme. it converts a temperature from Fahrenheit to Celsius or from Celsius to Fahrenheit at user's will. tell em if i need some improvements: ...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.