By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,986 Members | 1,522 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,986 IT Pros & Developers. It's quick & easy.

VB loop questions

P: 2
Please help me. I am trying to make a program using loops. What the program is meant to do is give me the amount of days when the Total2 > Total1. The restriction is that Total2 must be less then Total1. Also if the totals are over 1,000,000,000, the loop must end with a message showing that there has been a problem. This is what I have so far. Please help me.

Expand|Select|Wrap|Line Numbers
  1. Option Strict On
  2. Option Explicit On
  3. Public Class Form1
  4.     Dim Day As Double
  5.     Dim Total1 As Decimal
  6.     Dim Total2 As Decimal
  7.  
  8.     Private Sub btnCalculate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCalculate.Click
  9.         Dim SingleAmount As Decimal
  10.         Dim DoubleAmount As Decimal
  11.         SingleAmount = CDec(txtSingleInput.Text)
  12.         DoubleAmount = CDec(txtDoubleInput.Text)
  13.         If Decimal.TryParse(txtSingleInput.Text, CDec(SingleAmount)) = False Then
  14.             MessageBox.Show("Please enter a numeric amount")
  15.         End If
  16.  
  17.         If Decimal.TryParse(txtDoubleInput.Text, CDec(DoubleAmount)) = False Then
  18.             MessageBox.Show("Please enter a numeric Amount")
  19.         End If
  20.  
  21.         Do Until Total1 < Total2
  22.             Day = Day + 1
  23.             Total1 = Total1 + SingleAmount
  24.             Total2 = Total2 + (DoubleAmount * 2)
  25.             If (Total1 > 1000000000) Or (Total2 > 1000000000) Then
  26.                 MessageBox.Show("The Values you have entered are invalid.  Please re-enter.")
  27.                 End
  28.             End If
  29.         Loop
  30.  
  31.         Total1 = CDec(lblSingleOutput.Text)
  32.         Total2 = CDec(lblDoubleOutput.Text)
  33.         Day = CDbl(lblDays.Text)
  34.  
  35.     End Sub
  36. End Class
Nov 29 '07 #1
Share this Question
Share on Google+
1 Reply


Expert 5K+
P: 8,434
The only problem which really "leaps off the page" is that line 33 appears to be written backwards. You are overwriting the value in Day, when you were probably intending to move the value into the label.
Nov 30 '07 #2

Post your reply

Sign in to post your reply or Sign up for a free account.