Hi all, I am working on a final project for my college level programing course. We are using VB 2010. The program I am trying to write is a program to create a monthly budget based on the information entered. The GUI includes a list box to enter text for expense description (which will not be used for anything other then to describe the amounts that are in the list box to the right) a list box that will list all expenses, and a list box that will list all income. There is a text box to enter the expense description into the expense description list box, a text box to enter the expense amount into the list text box, and a text box to enter income into the list text box. Then there is a text box that will display the sum of all items in the expense list box, a text box that will display the sum of all items in the income list box, and a text box that will display the difference between the "summed expense text box" and the "summed income text box."
I'm having is an endless loop problem during the calculation phase. I used a breakpoint after the first calculation to try to find the problem, and the error I got was "InvalidArgument=Value of '500' is not valid for 'index'.
Parameter name: index"
I have tried "Loop Until" and "Loop While" and it tells me "Expression Expected".
I haven't been able to debug any further because of that issue. So I probably have a number of other problems I haven't discovered.
I am giving you my entire code for the program. The code for some events (not needed to run the program) haven't been written yet.
Any help would be appreciated.
[Code]
Public Class Form1
Private Sub OpenToolStripMenuItem_Click(sender As System.Object, e As System.EventArgs) Handles OpenToolStripMenuItem.Click
Process.Start("explorer.exe")
End Sub
Private Sub SaveToolStripMenuItem_Click(sender As System.Object, e As System.EventArgs) Handles SaveToolStripMenuItem.Click
Dim saveFileDialog1 As New SaveFileDialog()
Dim RichTextBox1 As New RichTextBox()
If Saved() = False Then
If (saveFileDialog1.ShowDialog() = Windows.Forms.DialogResult.OK) Then
RichTextBox1.SaveFile(saveFileDialog1.FileName, RichTextBoxStreamType.TextTextOleObjs)
Me.Text = "" & saveFileDialog1.FileName & " - NoteEditor Pro"
End If
ElseIf Saved() = True Then
RichTextBox1.SaveFile(saveFileDialog1.FileName, RichTextBoxStreamType.TextTextOleObjs)
End If
End Sub
Private Sub SaveAsToolStripMenuItem_Click(sender As System.Object, e As System.EventArgs) Handles SaveAsToolStripMenuItem.Click
' Displays a SaveFileDialog so the user can save the Image
' assigned to Button2.
Dim saveFileDialog1 As New SaveFileDialog()
saveFileDialog1.Filter = "JPeg Image|*.jpg|Bitmap Image|*.bmp|Gif Image|*.gif"
saveFileDialog1.Title = "Save an Image File"
saveFileDialog1.ShowDialog()
' If the file name is not an empty string open it for saving.
If saveFileDialog1.FileName <> "" Then
' Saves the Image via a FileStream created by the OpenFile method.
Dim fs As System.IO.FileStream = CType _
(saveFileDialog1.OpenFile(), System.IO.FileStream)
' Saves the Image in the appropriate ImageFormat based upon the
' file type selected in the dialog box.
' NOTE that the FilterIndex property is one-based.
fs.Close()
End If
End Sub
Private Sub PrintToolStripMenuItem_Click(sender As System.Object, e As System.EventArgs) Handles PrintToolStripMenuItem.Click
PrintDialog1.ShowDialog()
End Sub
Private Sub HelpToolStripMenuItem_Click(sender As System.Object, e As System.EventArgs) Handles HelpToolStripMenuItem.Click
End Sub
Private Sub AboutToolStripMenuItem1_Click(sender As System.Object, e As System.EventArgs) Handles AboutToolStripMenuItem1.Click
MessageBox.Show("Budget Calculator Version 1.0. Copyright 2013. All rights Reserved", "About", MessageBoxButtons.OK, MessageBoxIcon.Information)
End Sub
Private Sub expenseTypeButton_Click(sender As System.Object, e As System.EventArgs) Handles expenseTypeButton.Click
expenseTypeListBox.Items.Add(expenseTypeTextBox.Text)
expenseTypeTextBox.Clear()
expenseTypeTextBox.Focus()
End Sub
Private Sub expenseAmoutButton_Click(sender As System.Object, e As System.EventArgs) Handles expenseAmoutButton.Click
expenseAmountListBox.Items.Add(Val(expenseAmountTextBox.Text))
expenseAmountTextBox.Clear()
expenseAmountTextBox.Focus()
End Sub
Private Sub incomeButton_Click(sender As System.Object, e As System.EventArgs) Handles incomeButton.Click
incomeListBox.Items.Add(Val(incomeTextBox.Text))
incomeTextBox.Clear()
incomeTextBox.Focus()
End Sub
Private Sub calculateBudgetButton_Click(sender As System.Object, e As System.EventArgs) Handles calculateBudgetButton.Click
Dim totalexpenses As Decimal = 0.0
Dim totalincome As Decimal = 0.0
Dim surplusdeficite As Decimal = 0.0
Dim total1 As Decimal = 0.0
Dim total2 As Decimal = 0.0
Dim total3 As Decimal = 0.0
Dim expenses As Decimal = 0.0
Dim income As Decimal = 0.0
'error message for empty expenseAmountListBox
If expenseAmountListBox.Text = 0 Then
MessageBox.Show("Please add monthly expenses by entering expense amount in enter expense amount box and click add.",
"Missing Expenses", MessageBoxButtons.OK, MessageBoxIcon.Error)
End If
'error message for empty incomeListBox
If incomeListBox.Text = 0 Then
MessageBox.Show("Please add income by entering income amount in enter income amount box and click add.",
"Missing Income", MessageBoxButtons.OK, MessageBoxIcon.Error)
End If
Do Until
'collect and add all expenses from expenseAmountListBox
expenses = expenseAmountListBox.Items.Item(expenses)
total1 += expenses
'adds all expenses from expenseAmountListBox and display result in totalExpensesTextBox
totalExpensesTextBox.Text = String.Format("{0:C}", total1)
Loop
Do Until
'collect and add all income from incomListBox
income = incomeListBox.Items.Item(income)
total2 += income
'adds all income from incomeListBox and display result in totalIncomeTextBox
totalIncomeTextBox.Text = String.Format("{0:C}", total2)
Loop
Do Until
'subtract expenses from income
total3 = income - expenses
'display result of income minus expenses showing negative result in red
surplusDeficiteTextBox.Text = String.Format("{0:C}", total3)
If surplusDeficiteTextBox.Text > 0 Then
surplusDeficiteTextBox.ForeColor = Color.Red
End If
Loop
End Sub
Private Function Saved() As Boolean
Throw New NotImplementedException
End Function
End Class
[Code]
I'm having is an endless loop problem during the calculation phase. I used a breakpoint after the first calculation to try to find the problem, and the error I got was "InvalidArgument=Value of '500' is not valid for 'index'.
Parameter name: index"
I have tried "Loop Until" and "Loop While" and it tells me "Expression Expected".
I haven't been able to debug any further because of that issue. So I probably have a number of other problems I haven't discovered.
I am giving you my entire code for the program. The code for some events (not needed to run the program) haven't been written yet.
Any help would be appreciated.
[Code]
Public Class Form1
Private Sub OpenToolStripMenuItem_Click(sender As System.Object, e As System.EventArgs) Handles OpenToolStripMenuItem.Click
Process.Start("explorer.exe")
End Sub
Private Sub SaveToolStripMenuItem_Click(sender As System.Object, e As System.EventArgs) Handles SaveToolStripMenuItem.Click
Dim saveFileDialog1 As New SaveFileDialog()
Dim RichTextBox1 As New RichTextBox()
If Saved() = False Then
If (saveFileDialog1.ShowDialog() = Windows.Forms.DialogResult.OK) Then
RichTextBox1.SaveFile(saveFileDialog1.FileName, RichTextBoxStreamType.TextTextOleObjs)
Me.Text = "" & saveFileDialog1.FileName & " - NoteEditor Pro"
End If
ElseIf Saved() = True Then
RichTextBox1.SaveFile(saveFileDialog1.FileName, RichTextBoxStreamType.TextTextOleObjs)
End If
End Sub
Private Sub SaveAsToolStripMenuItem_Click(sender As System.Object, e As System.EventArgs) Handles SaveAsToolStripMenuItem.Click
' Displays a SaveFileDialog so the user can save the Image
' assigned to Button2.
Dim saveFileDialog1 As New SaveFileDialog()
saveFileDialog1.Filter = "JPeg Image|*.jpg|Bitmap Image|*.bmp|Gif Image|*.gif"
saveFileDialog1.Title = "Save an Image File"
saveFileDialog1.ShowDialog()
' If the file name is not an empty string open it for saving.
If saveFileDialog1.FileName <> "" Then
' Saves the Image via a FileStream created by the OpenFile method.
Dim fs As System.IO.FileStream = CType _
(saveFileDialog1.OpenFile(), System.IO.FileStream)
' Saves the Image in the appropriate ImageFormat based upon the
' file type selected in the dialog box.
' NOTE that the FilterIndex property is one-based.
fs.Close()
End If
End Sub
Private Sub PrintToolStripMenuItem_Click(sender As System.Object, e As System.EventArgs) Handles PrintToolStripMenuItem.Click
PrintDialog1.ShowDialog()
End Sub
Private Sub HelpToolStripMenuItem_Click(sender As System.Object, e As System.EventArgs) Handles HelpToolStripMenuItem.Click
End Sub
Private Sub AboutToolStripMenuItem1_Click(sender As System.Object, e As System.EventArgs) Handles AboutToolStripMenuItem1.Click
MessageBox.Show("Budget Calculator Version 1.0. Copyright 2013. All rights Reserved", "About", MessageBoxButtons.OK, MessageBoxIcon.Information)
End Sub
Private Sub expenseTypeButton_Click(sender As System.Object, e As System.EventArgs) Handles expenseTypeButton.Click
expenseTypeListBox.Items.Add(expenseTypeTextBox.Text)
expenseTypeTextBox.Clear()
expenseTypeTextBox.Focus()
End Sub
Private Sub expenseAmoutButton_Click(sender As System.Object, e As System.EventArgs) Handles expenseAmoutButton.Click
expenseAmountListBox.Items.Add(Val(expenseAmountTextBox.Text))
expenseAmountTextBox.Clear()
expenseAmountTextBox.Focus()
End Sub
Private Sub incomeButton_Click(sender As System.Object, e As System.EventArgs) Handles incomeButton.Click
incomeListBox.Items.Add(Val(incomeTextBox.Text))
incomeTextBox.Clear()
incomeTextBox.Focus()
End Sub
Private Sub calculateBudgetButton_Click(sender As System.Object, e As System.EventArgs) Handles calculateBudgetButton.Click
Dim totalexpenses As Decimal = 0.0
Dim totalincome As Decimal = 0.0
Dim surplusdeficite As Decimal = 0.0
Dim total1 As Decimal = 0.0
Dim total2 As Decimal = 0.0
Dim total3 As Decimal = 0.0
Dim expenses As Decimal = 0.0
Dim income As Decimal = 0.0
'error message for empty expenseAmountListBox
If expenseAmountListBox.Text = 0 Then
MessageBox.Show("Please add monthly expenses by entering expense amount in enter expense amount box and click add.",
"Missing Expenses", MessageBoxButtons.OK, MessageBoxIcon.Error)
End If
'error message for empty incomeListBox
If incomeListBox.Text = 0 Then
MessageBox.Show("Please add income by entering income amount in enter income amount box and click add.",
"Missing Income", MessageBoxButtons.OK, MessageBoxIcon.Error)
End If
Do Until
'collect and add all expenses from expenseAmountListBox
expenses = expenseAmountListBox.Items.Item(expenses)
total1 += expenses
'adds all expenses from expenseAmountListBox and display result in totalExpensesTextBox
totalExpensesTextBox.Text = String.Format("{0:C}", total1)
Loop
Do Until
'collect and add all income from incomListBox
income = incomeListBox.Items.Item(income)
total2 += income
'adds all income from incomeListBox and display result in totalIncomeTextBox
totalIncomeTextBox.Text = String.Format("{0:C}", total2)
Loop
Do Until
'subtract expenses from income
total3 = income - expenses
'display result of income minus expenses showing negative result in red
surplusDeficiteTextBox.Text = String.Format("{0:C}", total3)
If surplusDeficiteTextBox.Text > 0 Then
surplusDeficiteTextBox.ForeColor = Color.Red
End If
Loop
End Sub
Private Function Saved() As Boolean
Throw New NotImplementedException
End Function
End Class
[Code]