473,671 Members | 2,570 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 ticketsDesiredT otal>0 then checkbox.checke d = 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 TicketsDesiredT otal 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.Checke d = True Then
lblAlliesTtl.Te xt = (txtQtyAllies.T ext * 50.0)
decTtl += lblAlliesTtl.Te xt
End If
If cbWardaddy.Chec ked = True Then
lblWarTtl.Text = 0.0
decTtl += lblWarTtl.Text
End If
lblSubTotal.Tex t = String.Format(" {0:C}", decTtl)

Dim decTxTtl = CDec(decTtl * 0.07)

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


Private Sub cbOil_CheckedCh anged(ByVal sender As System.Object, ByVal
e As System.EventArg s) Handles cbOil.CheckedCh anged
processor()
End Sub

Private Sub cbAllies_Checke dChanged(ByVal sender As System.Object,
ByVal e As System.EventArg s) Handles cbAllies.Checke dChanged
processor()

End Sub

Private Sub cbWardaddy_Chec kedChanged(ByVa l sender As System.Object,
ByVal e As System.EventArg s) Handles cbWardaddy.Chec kedChanged
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 1448
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******** ********@tk2msf tngp13.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 ticketsDesiredT otal>0 then checkbox.checke d = 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 TicketsDesiredT otal 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.Checke d = True Then
lblAlliesTtl.Te xt = (txtQtyAllies.T ext * 50.0)
decTtl += lblAlliesTtl.Te xt
End If
If cbWardaddy.Chec ked = True Then
lblWarTtl.Text = 0.0
decTtl += lblWarTtl.Text
End If
lblSubTotal.Tex t = String.Format(" {0:C}", decTtl)

Dim decTxTtl = CDec(decTtl * 0.07)

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


Private Sub cbOil_CheckedCh anged(ByVal sender As System.Object, ByVal
e As System.EventArg s) Handles cbOil.CheckedCh anged
processor()
End Sub

Private Sub cbAllies_Checke dChanged(ByVal sender As System.Object,
ByVal e As System.EventArg s) Handles cbAllies.Checke dChanged
processor()

End Sub

Private Sub cbWardaddy_Chec kedChanged(ByVa l sender As System.Object,
ByVal e As System.EventArg s) Handles cbWardaddy.Chec kedChanged
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 ticketsDesiredT otal>0 then checkbox.checke d = 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 TicketsDesiredT otal 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.Checke d = True Then
lblAlliesTtl.Te xt = (txtQtyAllies.T ext * 50.0)
decTtl += lblAlliesTtl.Te xt
End If
If cbWardaddy.Chec ked = True Then
lblWarTtl.Text = 0.0
decTtl += lblWarTtl.Text
End If
lblSubTotal.Tex t = String.Format(" {0:C}", decTtl)

Dim decTxTtl = CDec(decTtl * 0.07)

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


Private Sub cbOil_CheckedCh anged(ByVal sender As System.Object, ByVal
e As System.EventArg s) Handles cbOil.CheckedCh anged
processor()
End Sub

Private Sub cbAllies_Checke dChanged(ByVal sender As System.Object,
ByVal e As System.EventArg s) Handles cbAllies.Checke dChanged
processor()

End Sub

Private Sub cbWardaddy_Chec kedChanged(ByVa l sender As System.Object,
ByVal e As System.EventArg s) Handles cbWardaddy.Chec kedChanged
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
2222
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. Any ideas how to solve this (other than using 'filterwarnings')? Thanks.
8
2191
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 C#. However, it's a real hassle that the book has no index, just a table of contents. For example, as early as page 8, the book teaches that C#'s "using" statement is the equivalent of VB.NET's "imports" statement. However, that concept...
2
1308
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 could no longer edit it in older versions of Visual Studio. What does this conversion entail. It seems like a 1 way path.
5
9660
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 throwing an exception. Is there a plan at Microsoft VB .NET team to include a keyword equivalent to "as"?
1
11262
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 and disable "Automatic ANSI to OEM conversion": - This only affects isql from the command line, and no gui applications - http://support.microsoft.com/?scid=kb;EN-US;153449 - Start the "Client Network Utility" C:\WINDOWS\system32\cliconfg.exe
0
1358
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 to convert a xml file into another xml file ( lets us say it as my )standard format "GG" using XSLT .Additinoally i need to add some extra information via "USER" " INPUT " to final xml .
26
6271
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 of values to them based on data submitted from POST Fields. Code below: $_SESSION = array();
11
2232
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: // conversion of temperature // using Centigrade and Fahrenheit #include <iostream> int main() {
0
8485
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8930
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8605
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7446
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
4227
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4417
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2819
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2062
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1816
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.