Hello, I'm in a Visual Basic 2010 class and I haven't had any major road blocks until now.
I'm trying to get rid of a decimal place on a user input text box.
My Program Runs just fine but it will round the number of years up instead of dropping the remainder, and with my understanding the integer division should have kicked the remainder out?
Here is the important part of my code, and I know that i don't know anything but any help would be great.
(Also I did ask my instructor and I think is was a case of "If you cant help 'em baffle 'em")
'Declarations
Dim intYear As Integer
Dim strYear As String
Dim dblPrinciple As Double
Dim intLoops As Integer
Dim dblRate As Double
Dim dblAmount As Double
'Checks data
If (txtYears.Text <> "") AndAlso IsNumeric(txtYears.Text) AndAlso (txtYears.Text >= 1) Then
intYear = Convert.ToString(txtYears.Text) '<the problem is between here
intYear = intYear \ 1
intLoops = Convert.ToInt32(intYear) '< and here....(I think)
If (txtPrincipal.Text <> "") AndAlso IsNumeric(txtPrincipal.Text) AndAlso (txtPrincipal.Text > 0) Then
dblPrinciple = Convert.ToDouble(txtPrincipal.Text)
If (txtRate.Text > "") AndAlso IsNumeric(txtRate.Text) AndAlso (txtRate.Text > 0) Then
dblRate = Convert.ToDouble(txtRate.Text)
'Calculates and displays each year
For intYear = 1 To intLoops
dblPrinciple = dblPrinciple * (1 + dblRate)
dblAmount = dblPrinciple.ToString("C2")
lstDisplay.Items.Add("Year: " & intYear & " $" & dblAmount)
Next
I'm trying to get rid of a decimal place on a user input text box.
My Program Runs just fine but it will round the number of years up instead of dropping the remainder, and with my understanding the integer division should have kicked the remainder out?
Here is the important part of my code, and I know that i don't know anything but any help would be great.
(Also I did ask my instructor and I think is was a case of "If you cant help 'em baffle 'em")
'Declarations
Dim intYear As Integer
Dim strYear As String
Dim dblPrinciple As Double
Dim intLoops As Integer
Dim dblRate As Double
Dim dblAmount As Double
'Checks data
If (txtYears.Text <> "") AndAlso IsNumeric(txtYears.Text) AndAlso (txtYears.Text >= 1) Then
intYear = Convert.ToString(txtYears.Text) '<the problem is between here
intYear = intYear \ 1
intLoops = Convert.ToInt32(intYear) '< and here....(I think)
If (txtPrincipal.Text <> "") AndAlso IsNumeric(txtPrincipal.Text) AndAlso (txtPrincipal.Text > 0) Then
dblPrinciple = Convert.ToDouble(txtPrincipal.Text)
If (txtRate.Text > "") AndAlso IsNumeric(txtRate.Text) AndAlso (txtRate.Text > 0) Then
dblRate = Convert.ToDouble(txtRate.Text)
'Calculates and displays each year
For intYear = 1 To intLoops
dblPrinciple = dblPrinciple * (1 + dblRate)
dblAmount = dblPrinciple.ToString("C2")
lstDisplay.Items.Add("Year: " & intYear & " $" & dblAmount)
Next