Hello. My name is Jennifer. I am new to the world of programming and to this forum. Please be kind. I have an assignment for my intro to programming class due tonight by midnight and i cannot figure out what is wrong with this code. I feel like i am over my head with this class. Someone please help me. I have attached my coding below so you can see what i am doing wrong. I believe it is a calculation error, not a programming error. But like i said, i am new and have no clue what i am doing.
Private Sub calc_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles calc.Click
Dim north As Integer
Dim south As Integer
Dim east As Integer
Dim west As Integer
Dim LastYearSales As Double
Dim NextYearSales As Double = 0
Dim IncreaseAmount As Double = 0
LastYearSales = Val(lastY.Text)
north = 0.05
south = 0.08
east = 0.03
west = 0.06
If NSEW.Text.ToUpper = "NORTH" Then
IncreaseAmount = north * LastYearSales
ElseIf NSEW.Text.ToUpper = "SOUTH" Then
IncreaseAmount = south * LastYearSales
ElseIf NSEW.Text.ToUpper = "EAST" Then
IncreaseAmount = east * LastYearSales
ElseIf NSEW.Text.ToUpper = "WEST" Then
IncreaseAmount = west * LastYearSales
NextYearSales = IncreaseAmount + LastYearSales
lblAns.Text = NextYearSales
Thank you for your time. This has been most frustrating to say the least!!
Last edited by DataMiser; March 5th, 2013 at 10:07 PM.
Reason: added code tags
You have declared your 4 variables as Integer but you are assigning decimal values to them so you have a problem before you get to the calculations. Integers can hold whole numbers only so those values are all rounded off as soon as they are assigned. These should be defined as Decimal rather than Integer
For the sake of readability you should use a Select Case structure rather than If Then ElseIf structure.
On your last line you are assigning a value from a numeric var to a string. Apparently you have Option Strict turned off or this would give you an error message. You should get in the habit of doing proper conversions in this case when you want to assign a value from a numeric var to a variable of type string such as the Text property of a Label you should use the .ToString method
Also the code you have posted is not VB6 code but is .Net code which should be posted in the VB.Net section of the forum.
<-- Thread moved to Vb.Net area -->
Last edited by DataMiser; March 5th, 2013 at 10:04 PM.
Thank you for the quick responses. The code is now corrected but the it won't calculate. If I put (for example) region - north and 100 for last years sales I get an answer of 100. What am I doing wrong?