Public Class main
'Dry Tons definitions per metal per quarter
Dim Arsq1, Arsq2, Arsq3, Arsq4,
Cadq1, Cadq2, Cadq3, Cadq4,
Chrq1, Chrq2, Chrq3, Chrq4,
Copq1, Copq2, Copq3, Copq4,
Leaq1, Leaq2, Leaq3, Leaq4,
Merq1, Merq2, Merq3, Merq4,
Molq1, Molq2, Molq3, Molq4,
Nicq1, Nicq2, Nicq3, Nicq4,
Selq1, Selq2, Selq3, Selq4,
Zinq1, Zinq2, Zinq3, Zinq4 As Double
'DTA's definitions per metal
Dim Arsenic_dryTonsAcre,
Cadmium_dryTonsAcre,
Chrome_dryTonsAcre,
Copper_dryTonsAcre,
Lead_dryTonsAcre,
Mercury_dryTonsAcre,
Molybdenum_dryTonsAcre,
Nickel_dryTonsAcre,
Selenium_dryTonsAcre,
Zinc_dryTonsAcre As Double
'Added this year variables (dry tons per acre)
Dim ars_thisYearTotal,
cad_thisYearTotal,
chr_thisYearTotal,
cop_thisYearTotal,
lea_thisYearTotal,
mol_thisYearTotal,
mer_thisYearTotal,
nic_thisYearTotal,
sel_thisYearTotal,
zin_thisYearTotal As Double
'current totals by metal
Dim ars_currentTotal,
cad_currentTotal,
chr_currentTotal,
cop_currentTotal,
lea_currentTotal,
mer_currentTotal,
mol_currentTotal,
nic_currentTotal,
sel_currentTotal,
zin_currentTotal As Double
'previous totals
Dim ars_previousTotal,
cad_previousTotal,
chr_previousTotal,
cop_previousTotal,
lea_previousTotal,
mer_previousTotal,
mol_previousTotal,
nic_previousTotal,
sel_previousTotal,
zin_previousTotal As Double
'percentage per metal allowed load
Dim arsenicPercentage,
cadmiumPercentage,
chromePercentage,
copperPercentage,
leadPercentage,
mercuryPercentage,
molybdenumPercentage,
nickelPercentage,
seleniumPercentage,
zincPercentage As Double
'low ceiling by metal
Dim ars_lowCeiling,
cad_lowCeiling,
chr_lowCeiling,
cop_lowCeiling,
lea_lowCeiling,
mer_lowCeiling,
mol_lowCeiling,
nic_lowCeiling,
sel_lowCeiling,
zin_lowCeiling As Double
'high ceiling by metal
Dim ars_highCeiling,
cad_highCeiling,
chr_highCeiling,
cop_highCeiling,
lea_highCeiling,
mer_highCeiling,
mol_highCeiling,
nic_highCeiling,
sel_highCeiling,
zin_highCeiling As Double
'assigning variables and converting this year total to previous total
Dim ars_tempPrevious As Decimal
Dim cad_tempPrevious As Decimal
Dim chr_tempPrevious As Decimal
Dim cop_tempPrevious As Decimal
Dim lea_tempPrevious As Decimal
Dim mer_tempPrevious As Decimal
Dim mol_tempPrevious As Decimal
Dim nic_tempPrevious As Decimal
Dim sel_tempPrevious As Decimal
Dim zin_tempPrevious As Decimal
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
'input variables, converting text input to integer values for calculation (arsenic)
Arsq1 = Val(arsq1txt.Text)
Arsq2 = Val(arsq2txt.Text)
Arsq3 = Val(arsq3txt.Text)
Arsq4 = Val(arsq4txt.Text)
'dry tons text to integer to text for output
Dim ArsqTotal As Decimal = Arsq1 + Arsq2 + Arsq3 + Arsq4
Arsenic_totalDisplay.Text = ArsqTotal.ToString
'input (cadmium)
Cadq1 = Val(cadq1txt.Text)
Cadq2 = Val(cadq2txt.Text)
Cadq3 = Val(cadq3txt.Text)
Cadq4 = Val(cadq4txt.Text)
'calculation
Dim CadqTotal As Decimal = Cadq1 + Cadq2 + Cadq3 + Cadq4
Cadmium_totalDisplay.Text = CadqTotal.ToString
'chrome
Chrq1 = Val(chrq1txt.Text)
Chrq2 = Val(chrq2txt.Text)
Chrq3 = Val(chrq3txt.Text)
Chrq4 = Val(chrq4txt.Text)
'calculation
Dim chrqTotal As Decimal = Chrq1 + Chrq2 + Chrq3 + Chrq4
Chrome_totalDisplay.Text = chrqTotal.ToString
'copper
Copq1 = Val(copq1txt.Text)
Copq2 = Val(copq2txt.Text)
Copq3 = Val(copq3txt.Text)
Copq4 = Val(copq4txt.Text)
'calculation
Dim copqTotal As Decimal = Copq1 + Copq2 + Copq3 + Copq4
Copper_totalDisplay.Text = copqTotal.ToString
'lead
Leaq1 = Val(leaq1txt.Text)
Leaq2 = Val(leaq2txt.Text)
Leaq3 = Val(leaq3txt.Text)
Leaq4 = Val(leaq4txt.Text)
'calculation
Dim leaqTotal As Decimal = Leaq1 + Leaq2 + Leaq3 + Leaq4
Lead_totalDisplay.Text = leaqTotal.ToString
'mercury
Merq1 = Val(merq1txt.Text)
Merq2 = Val(merq2txt.Text)
Merq3 = Val(merq3txt.Text)
Merq4 = Val(merq4txt.Text)
'calculation
Dim merqTotal As Decimal = Merq1 + Merq2 + Merq3 + Merq4
Mercury_totalDisplay.Text = merqTotal.ToString
'molybdenum
Molq1 = Val(molq1txt.Text)
Molq2 = Val(molq2txt.Text)
Molq3 = Val(molq3txt.Text)
Molq4 = Val(molq4txt.Text)
'calculation
Dim molqTotal As Decimal = Molq1 + Molq2 + Molq3 + Molq4
Molybdenum_totalDisplay.Text = molqTotal.ToString
'nickel
Nicq1 = Val(nicq1txt.Text)
Nicq2 = Val(nicq2txt.Text)
Nicq3 = Val(nicq3txt.Text)
Nicq4 = Val(nicq4txt.Text)
'calculation
Dim nicqTotal As Decimal = Nicq1 + Nicq2 + Nicq3 + Nicq4
Nickel_totalDisplay.Text = nicqTotal.ToString
'selenium
Selq1 = Val(selq1txt.Text)
Selq2 = Val(selq2txt.Text)
Selq3 = Val(selq3txt.Text)
Selq4 = Val(selq4txt.Text)
'calculation
Dim selqTotal As Decimal = Selq1 + Selq2 + Selq3 + Selq4
Selenium_totalDisplay.Text = selqTotal.ToString
'zinc
Zinq1 = Val(zinq1txt.Text)
Zinq2 = Val(zinq2txt.Text)
Zinq3 = Val(zinq3txt.Text)
Zinq4 = Val(zinq4txt.Text)
'calculation
Dim zinqTotal As Decimal = Zinq1 + Zinq2 + Zinq3 + Zinq4
Zinc_totalDisplay.Text = zinqTotal.ToString
'calculate this year totals
'Arsenic
Dim A As Double
ars_lowCeiling = 41
A = ars_lowCeiling.ToString * 0.002
Arsenic_dryTonsAcre = A * ArsqTotal
ars_thisYearLabel.Text = Arsenic_dryTonsAcre.ToString
ars_tempPrevious = Arsenic_dryTonsAcre.ToString
'cadmium
cad_lowCeiling = 39
A = cad_lowCeiling.ToString * 0.002
Cadmium_dryTonsAcre = A * CadqTotal
cad_thisYearLabel.Text = Cadmium_dryTonsAcre.ToString
cad_tempPrevious = Cadmium_dryTonsAcre.ToString
'chromium
chr_lowCeiling = 1200
A = chr_lowCeiling.ToString * 0.002
Chrome_dryTonsAcre = A * chrqTotal
chr_thisYearLabel.Text = Chrome_dryTonsAcre.ToString
chr_tempPrevious = Chrome_dryTonsAcre.ToString
'copper
cop_lowCeiling = 1500
A = cop_lowCeiling.ToString * 0.002
Copper_dryTonsAcre = A * copqTotal
cop_thisYearLabel.Text = Copper_dryTonsAcre.ToString
cop_tempPrevious = Copper_dryTonsAcre.ToString
'lead
lea_lowCeiling = 300
A = lea_lowCeiling.ToString * 0.002
Lead_dryTonsAcre = A * leaqTotal
lea_thisYearLabel.Text = Lead_dryTonsAcre.ToString
lea_tempPrevious = Lead_dryTonsAcre.ToString
'mercury
mer_lowCeiling = 17
A = mer_lowCeiling.ToString * 0.002
Mercury_dryTonsAcre = A * merqTotal
mer_thisYearLabel.Text = Mercury_dryTonsAcre.ToString
mer_tempPrevious = Mercury_dryTonsAcre.ToString
'molybdenum
mol_lowCeiling = 18
A = mol_lowCeiling.ToString * 0.002
Molybdenum_dryTonsAcre = A * molqTotal
mol_thisYearLabel.Text = Molybdenum_dryTonsAcre.ToString
mol_tempPrevious = Molybdenum_dryTonsAcre.ToString
'nickel
nic_lowCeiling = 420
A = nic_lowCeiling.ToString * 0.002
Nickel_dryTonsAcre = A * nicqTotal
nic_thisYearLabel.Text = Nickel_dryTonsAcre.ToString
nic_tempPrevious = Nickel_dryTonsAcre.ToString
'selenium
sel_lowCeiling = 36
A = sel_lowCeiling.ToString * 0.002
Selenium_dryTonsAcre = A * selqTotal
sel_thisYearLabel.Text = Selenium_dryTonsAcre.ToString
sel_tempPrevious = Selenium_dryTonsAcre.ToString
'zinc
zin_lowCeiling = 2800
A = zin_lowCeiling.ToString * 0.002
Zinc_dryTonsAcre = A * zinqTotal
zin_thisYearLabel.Text = Zinc_dryTonsAcre.ToString
zin_tempPrevious = Zinc_dryTonsAcre.ToString
'calculate current totals
'arsenic
If ars_previousTotalLabel.Text = "" Then
ars_currentTotalLabel.Text = Arsenic_dryTonsAcre.ToString
ElseIf (ars_thisYearLabel.Text = 0) Then
ars_currentTotalLabel.Text = Arsenic_dryTonsAcre.ToString
Else
ars_currentTotalLabel.Text = Arsenic_dryTonsAcre.ToString + ars_tempPrevious.ToString
End If
'cadmium
If cad_previousTotalLabel.Text = "" Then
cad_currentTotalLabel.Text = Cadmium_dryTonsAcre.ToString
ElseIf (cad_thisYearLabel.Text = 0) Then
cad_currentTotalLabel.Text = Cadmium_dryTonsAcre.ToString
Else
cad_currentTotalLabel.Text = Cadmium_dryTonsAcre.ToString + cad_tempPrevious.ToString
End If
'chrome
If chr_previousTotalLabel.Text = "" Then
chr_currentTotalLabel.Text = Chrome_dryTonsAcre.ToString
ElseIf (chr_thisYearLabel.Text = 0) Then
chr_currentTotalLabel.Text = Chrome_dryTonsAcre.ToString
Else
chr_currentTotalLabel.Text = Chrome_dryTonsAcre.ToString + chr_tempPrevious.ToString
End If
'copper
If cop_previousTotalLabel.Text = "" Then
cop_currentTotalLabel.Text = Copper_dryTonsAcre.ToString
ElseIf (cop_thisYearLabel.Text = 0) Then
cop_currentTotalLabel.Text = Copper_dryTonsAcre.ToString
Else
cop_currentTotalLabel.Text = Copper_dryTonsAcre.ToString + cop_tempPrevious.ToString
End If
'lead
If lea_previousTotalLabel.Text = "" Then
lea_currentTotalLabel.Text = Lead_dryTonsAcre.ToString
ElseIf (lea_thisYearLabel.Text = 0) Then
lea_currentTotalLabel.Text = Lead_dryTonsAcre.ToString
Else
lea_currentTotalLabel.Text = Lead_dryTonsAcre.ToString + lea_tempPrevious.ToString
End If
'mercury
If mer_previousTotalLabel.Text = "" Then
mer_currentTotalLabel.Text = Mercury_dryTonsAcre.ToString
ElseIf (mer_thisYearLabel.Text = 0) Then
mer_currentTotalLabel.Text = Mercury_dryTonsAcre.ToString
Else
mer_currentTotalLabel.Text = Mercury_dryTonsAcre.ToString + mer_tempPrevious.ToString
End If
'molybdenum
If mol_previousTotalLabel.Text = "" Then
mol_currentTotalLabel.Text = Molybdenum_dryTonsAcre.ToString
ElseIf (mol_thisYearLabel.Text = 0) Then
mol_currentTotalLabel.Text = Molybdenum_dryTonsAcre.ToString
Else
mol_currentTotalLabel.Text = Molybdenum_dryTonsAcre.ToString + mol_tempPrevious.ToString
End If
'nickel
If nic_previousTotalLabel.Text = "" Then
nic_currentTotalLabel.Text = Nickel_dryTonsAcre.ToString
ElseIf (nic_thisYearLabel.Text = 0) Then
nic_currentTotalLabel.Text = Nickel_dryTonsAcre.ToString
Else
nic_currentTotalLabel.Text = Nickel_dryTonsAcre.ToString + nic_tempPrevious.ToString
End If
'selenium
If sel_previousTotalLabel.Text = "" Then
sel_currentTotalLabel.Text = Selenium_dryTonsAcre.ToString
ElseIf (sel_thisYearLabel.Text = 0) Then
sel_currentTotalLabel.Text = Selenium_dryTonsAcre.ToString
Else
sel_currentTotalLabel.Text = Selenium_dryTonsAcre.ToString + sel_tempPrevious.ToString
End If
'zinc
If zin_previousTotalLabel.Text = "" Then
zin_currentTotalLabel.Text = Zinc_dryTonsAcre.ToString
ElseIf (zin_thisYearLabel.Text = 0) Then
zin_currentTotalLabel.Text = Zinc_dryTonsAcre.ToString
Else
zin_currentTotalLabel.Text = Zinc_dryTonsAcre.ToString + zin_tempPrevious.ToString
End If
'calculate perentages
'arsenic
Dim PA As Decimal
ars_highCeiling = 75
PA = ars_highCeiling.ToString - Arsenic_dryTonsAcre.ToString
arsenicPercentage = PA / ars_highCeiling.ToString
'cadmium
cad_highCeiling = 85
PA = cad_highCeiling.ToString - Cadmium_dryTonsAcre.ToString
cadmiumPercentage = PA / cad_highCeiling.ToString
cad_percentTotalLabel.Text = cadmiumPercentage.ToString
'chromium
chr_highCeiling = 3000
PA = chr_highCeiling.ToString - Chrome_dryTonsAcre.ToString
chromePercentage = PA / chr_highCeiling.ToString
chr_percentTotalLabel.Text = chromePercentage.ToString
'copper
cop_highCeiling = 4300
PA = cop_highCeiling.ToString - Copper_dryTonsAcre.ToString
copperPercentage = PA / cop_highCeiling
cop_percentageTotalLabel.Text = copperPercentage.ToString
'lead
lea_highCeiling = 840
PA = lea_highCeiling.ToString - Lead_dryTonsAcre.ToString
leadPercentage = PA / lea_highCeiling.ToString
lea_percentTotalLabel.Text = leadPercentage.ToString
'mercury
mer_highCeiling = 57
PA = mer_highCeiling.ToString - Mercury_dryTonsAcre.ToString
mercuryPercentage = PA.ToString / mer_highCeiling.ToString
mer_percentTotalLabel.Text = mercuryPercentage
'molybdenum
mol_highCeiling = 75
PA = mol_highCeiling.ToString - Molybdenum_dryTonsAcre.ToString
molybdenumPercentage = PA.ToString / mer_highCeiling.ToString
mol_percentTotalLabel.Text = mercuryPercentage
'nickel
nic_highCeiling = 420
PA = nic_highCeiling.ToString - Nickel_dryTonsAcre.ToString
nickelPercentage = PA / nic_highCeiling.ToString
nic_percentTotalLabel.Text = nickelPercentage.ToString
'selenium
sel_highCeiling = 100
PA = sel_highCeiling.ToString - Selenium_dryTonsAcre.ToString
seleniumPercentage = PA / sel_highCeiling.ToString
sel_percentTotalLabel.Text = seleniumPercentage.ToString
'zinc
zin_highCeiling = 7500
PA = zin_highCeiling.ToString - Zinc_dryTonsAcre.ToString
zincPercentage = PA / zin_highCeiling.ToString
zin_percentTotalLabel.Text = zincPercentage.ToString
End Sub
Private Sub nextButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles nextButton.Click
arsq1txt.Text = ""
arsq2txt.Text = ""
arsq3txt.Text = ""
arsq4txt.Text = ""
cadq1txt.Text = ""
cadq2txt.Text = ""
cadq3txt.Text = ""
cadq4txt.Text = ""
chrq1txt.Text = ""
chrq2txt.Text = ""
chrq3txt.Text = ""
chrq4txt.Text = ""
copq1txt.Text = ""
copq2txt.Text = ""
copq3txt.Text = ""
copq4txt.Text = ""
leaq1txt.Text = ""
leaq2txt.Text = ""
leaq3txt.Text = ""
leaq4txt.Text = ""
merq1txt.Text = ""
merq2txt.Text = ""
merq3txt.Text = ""
merq4txt.Text = ""
molq1txt.Text = ""
molq2txt.Text = ""
molq3txt.Text = ""
molq3txt.Text = ""
nicq1txt.Text = ""
nicq2txt.Text = ""
nicq3txt.Text = ""
nicq4txt.Text = ""
selq1txt.Text = ""
selq2txt.Text = ""
selq3txt.Text = ""
selq4txt.Text = ""
zinq1txt.Text = ""
zinq2txt.Text = ""
zinq3txt.Text = ""
zinq4txt.Text = ""
Arsenic_totalDisplay.Text = ""
Cadmium_totalDisplay.Text = ""
Chrome_totalDisplay.Text = ""
Copper_totalDisplay.Text = ""
Lead_totalDisplay.Text = ""
Mercury_totalDisplay.Text = ""
Molybdenum_totalDisplay.Text = ""
Nickel_totalDisplay.Text = ""
Selenium_totalDisplay.Text = ""
Zinc_totalDisplay.Text = ""
ars_thisYearLabel.Text = ""
cad_thisYearLabel.Text = ""
chr_thisYearLabel.Text = ""
cop_thisYearLabel.Text = ""
lea_thisYearLabel.Text = ""
mer_thisYearLabel.Text = ""
mol_thisYearLabel.Text = ""
nic_thisYearLabel.Text = ""
sel_thisYearLabel.Text = ""
zin_thisYearLabel.Text = ""
'conversion from thisyear to previous
ars_previousTotalLabel.Text = ars_tempPrevious
cad_previousTotalLabel.Text = cad_tempPrevious
chr_previousTotalLabel.Text = chr_tempPrevious
cop_previousTotalLabel.Text = cop_tempPrevious
lea_previousTotalLabel.Text = lea_tempPrevious
mer_previousTotalLabel.Text = mer_tempPrevious
mol_previousTotalLabel.Text = mol_tempPrevious
nic_previousTotalLabel.Text = nic_tempPrevious
sel_previousTotalLabel.Text = sel_tempPrevious
zin_previousTotalLabel.Text = zin_tempPrevious
End Sub
End Class
Data type conversion
Page 1 of 18 Replies - 176 Views - Last Post: 17 February 2013 - 10:25 PM
#1
Data type conversion
Posted 16 February 2013 - 10:35 PM
I'm relatively new to programming with VB so bare with me here if the syntax is exuberantly poor. I'm working on and am almost finished with a project ive been working on for a while and am not getting the desired output as ill explain. The program takes input from the user in decimal of dry tons of certain sledge metals found in the soil. The measurements from several different elements and metals are taken and added together for 4 monthly quarters and are then calculated in the dry tons per acre of that metal and returns the values for those metal after being calculated. The code takes the measurement, determines much of that metal is in the field to determine whether or not there is too much or too little of a certain metal. The user simply enters the data and presses calculate and the program outputs the desired data. When the next year needs to be calculated, the "next" button is pressed, and the previous total , current total are figured based on the previous entries and the space is cleared for the next year's entry. Simple enough. However, im having some data conversion issues. The outputs that are supposed to be in decimal form are coming out with more than one decimal point which leads me to believe ive converted it wrong somewhere. Could someone take a peek and let me know what I'm doing wrong here? Here is the code in its entirety..
Replies To: Data type conversion
#2
Re: Data type conversion
Posted 17 February 2013 - 12:29 AM
First off, you could probably shave about 450 lines of code off of this if you learned how to use arrays. It would be time well spent. You can have arrays of text boxes, too.
Second, you're better off keeping temporary values (such as previous totals or whatever) in variables rather than testing the value of text boxes and converting back and forth. Consider doing this everywhere you have If then else constructs that test the value of text boxes.
Finally, I don't know if anyone is willing to "take a peek" at 528 lines of code to figure out what you're doing wrong. If you could put some effort into narrowing down the area that you think is causing the problem it would help everyone help you. (Are you saying that you have a text string with more than one . in it? Just the sort of reason that you should store the results of your calculations in variables and then post the variables to text boxes.)
Second, you're better off keeping temporary values (such as previous totals or whatever) in variables rather than testing the value of text boxes and converting back and forth. Consider doing this everywhere you have If then else constructs that test the value of text boxes.
Finally, I don't know if anyone is willing to "take a peek" at 528 lines of code to figure out what you're doing wrong. If you could put some effort into narrowing down the area that you think is causing the problem it would help everyone help you. (Are you saying that you have a text string with more than one . in it? Just the sort of reason that you should store the results of your calculations in variables and then post the variables to text boxes.)
This post has been edited by BobRodes: 17 February 2013 - 12:31 AM
#3
Re: Data type conversion
Posted 17 February 2013 - 01:19 AM
BobRodes, on 17 February 2013 - 12:29 AM, said:
Second, you're better off keeping temporary values (such as previous totals or whatever) in variables rather than testing the value of text boxes and converting back and forth.
I already have the previous totals and what not in variables. "ars_previousTotals" Is that not what I have here already? What do you mean?
Quote
Finally, I don't know if anyone is willing to "take a peek" at 528 lines of code to figure out what you're doing wrong.
The reason I posted the whole thing is I thought someone could benefit from seeing the rest of the code if they are trying to help..My bad
Quote
If you could put some effort into narrowing down the area that you think is causing the problem it would help everyone help you. (Are you saying that you have a text string with more than one . in it? Just the sort of reason that you should store the results of your calculations in variables and then post the variables to text boxes.)
I think I know what you mean here about the variables but could you elaborate a little more?
#4
Re: Data type conversion
Posted 17 February 2013 - 05:22 PM
Hi camouser1s ,
It is a bit confusing to try to figure this code out but, i have kinda peeked through it and i see some things that should be changed. I don`t know as it will fix your problem or not but, there are spots that you are converting doubles to strings before doing math functions to them such as :
And other lines that you are trying to give Decimal variables a string value such as :
I see this all through the code so i would go back through and change all the line that are like that. You do not need to change any of the decimals or doubles to strings with (.ToString) unless you are showing the value in a textbox or label like this line :
I would leave all decimal and double variables as they are until math functions are done and then convert them to strings to show them in the textboxes or labels.
It is a bit confusing to try to figure this code out but, i have kinda peeked through it and i see some things that should be changed. I don`t know as it will fix your problem or not but, there are spots that you are converting doubles to strings before doing math functions to them such as :
PA = ars_highCeiling.ToString - Arsenic_dryTonsAcre.ToString
'should be
PA = ars_highCeiling - Arsenic_dryTonsAcre
And other lines that you are trying to give Decimal variables a string value such as :
cad_tempPrevious = Cadmium_dryTonsAcre.ToString
'Should be
cad_tempPrevious = Cadmium_dryTonsAcre
I see this all through the code so i would go back through and change all the line that are like that. You do not need to change any of the decimals or doubles to strings with (.ToString) unless you are showing the value in a textbox or label like this line :
Lead_totalDisplay.Text = leaqTotal.ToString
I would leave all decimal and double variables as they are until math functions are done and then convert them to strings to show them in the textboxes or labels.
#5
Re: Data type conversion
Posted 17 February 2013 - 07:38 PM
Quote
there are spots that you are converting doubles to strings before doing math functions to them such as :
PA = ars_highCeiling.ToString - Arsenic_dryTonsAcre.ToString
'should be
PA = ars_highCeiling - Arsenic_dryTonsAcre
So what you are saying is that the data should be left as
PA = ars_highCeiling - Arsenic_dryTonsAcre
and then I can just leave the rest of the code in that block alone as I have already converted it to string for the textbox correct?
Quote
And other lines that you are trying to give Decimal variables a string value such as :
cad_tempPrevious = Cadmium_dryTonsAcre.ToString
'Should be
cad_tempPrevious = Cadmium_dryTonsAcre
and again here this can be left as its initial data type as I have converted it to string for the textbox already
cad_tempPrevious = Cadmium_dryTonsAcre
#6
Re: Data type conversion
Posted 17 February 2013 - 08:51 PM
It really pays to learn the difference between the various data types. A string is not a number. A string may contain the character 1, and 5 and 7, but it is not 157. It is "157", which is a string representation of a number. But calculating "157" * 2 is the equivalent of multiplying camouser1s * 2. Yes, the compiler will attempt to convert any given data type to what it thinks you want, but it doesn't always get it right, and that can result in bugs that are extremely hard to find.
Fortunately, there is a way to let Visual Studio help you. Above the Class statement, add these two lines:
The first one will cause the compiler to tell you when you have used a variable without declaring it, and the second will tell you when you are misusing something, including trying to assign something to the wrong data type, or trying to assign a wrong data type to a variable. It will let you know by underlining the error with a wiggly line.
This may seem like a hassle when you first try it, but I can tell you that if you do use these two lines, you will come to the conclusion that you really like them. They will save your bacon many times over. And better, when an error is shown, you can often get a suggestion for correcting the problem, and a little box that when clicked, will perform the correction for you, and will actually save keystrokes once you get used to using the correction facility.
Fortunately, there is a way to let Visual Studio help you. Above the Class statement, add these two lines:
Option Strict On Option Explicit On
The first one will cause the compiler to tell you when you have used a variable without declaring it, and the second will tell you when you are misusing something, including trying to assign something to the wrong data type, or trying to assign a wrong data type to a variable. It will let you know by underlining the error with a wiggly line.
This may seem like a hassle when you first try it, but I can tell you that if you do use these two lines, you will come to the conclusion that you really like them. They will save your bacon many times over. And better, when an error is shown, you can often get a suggestion for correcting the problem, and a little box that when clicked, will perform the correction for you, and will actually save keystrokes once you get used to using the correction facility.
#7
Re: Data type conversion
Posted 17 February 2013 - 09:35 PM
I am having a heck of a time going threw such a large code and seeing what is going on but, what i am trying to say is if you have a decimal or double variable and it has been assigned a value it should not be converted to a string with (.ToString) until after you are done doing the math functions to it and have the total that you want to display. Then you can assign its value to a lable or textbox using (.ToString). I think you might have the idea by the sound of your post but, like i said there are a bunch of lines in your code that have the same problems. I just picked a few that i saw just to give you an example and i can`t be positive it will fix the problem but, it is a good place to start. Also you can put break points on lines that are changing the textbox`s text that is showing two decimal points and debug it. That would really help pinpoint where the problem is.
#8
Re: Data type conversion
Posted 17 February 2013 - 09:50 PM
I think I have the idea now thanks a bunch. and the Option strict and option explicit basicly just finished the program for me lol
#9
Re: Data type conversion
Posted 17 February 2013 - 10:25 PM
Good deal,
I hope it works out but, if you have any more problems come on back. There is always someone here that will help.
I hope it works out but, if you have any more problems come on back. There is always someone here that will help.
Page 1 of 1
|
|

New Topic/Question
Reply




MultiQuote





|