I think this will finish this project. I am creating a budget calculator that has two listboxes. One is for expenses, and the other is for income. I am populating these list boxes with a textbox and a button to add to the listbox. I would like to have it set so that even if the user enters "500" in the text box and clicks the populate button, it will show in the list box as "$500.00". Is there a way to do this, and how? So I know where to go with this, I am entering the entire code for the program.
Code:
Public Class budgetCalculator
Dim StringToPrint As String
Private Sub OpenToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OpenToolStripMenuItem.Click
Dim str_folder As String
str_folder = "Computer" ' folder to open
Call Shell("explorer.exe " & str_folder, vbNormalFocus)
End Sub
Private Sub SaveToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SaveToolStripMenuItem.Click
End Sub
Private Sub SaveAsToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SaveAsToolStripMenuItem.Click
Dim saveFileDialog1 As New SaveFileDialog
saveFileDialog1.InitialDirectory = "C:\"
saveFileDialog1.Title = "Save text Files"
saveFileDialog1.CheckFileExists = True
saveFileDialog1.CheckPathExists = True
saveFileDialog1.DefaultExt = "txt"
saveFileDialog1.Filter = "Text files (*.txt)|*.txt|All files (*.*)|*.*"
saveFileDialog1.FilterIndex = 2
saveFileDialog1.RestoreDirectory = True
If (saveFileDialog1.ShowDialog() = DialogResult.OK) Then
Me.Text = saveFileDialog1.FileName
End If
End Sub
Private Sub PrintToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PrintToolStripMenuItem.Click
Dim printDlg As New PrintDialog()
Dim printDoc As New Printing.PrintDocument()
printDoc.DocumentName = "Print Document"
printDlg.Document = printDoc
printDlg.AllowSelection = True
printDlg.AllowSomePages = True
If (printDlg.ShowDialog() = DialogResult.OK) Then
printDoc.Print()
End If
End Sub
Private Sub QuitToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles QuitToolStripMenuItem.Click
Me.Close()
End Sub
Private Sub HelpToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles HelpToolStripMenuItem.Click
System.Diagnostics.Process.Start("C:\Users\Daniel Toomey\Desktop\Budget Calculator\Budget Calculator\My Project\Index.html")
End Sub
Private Sub AboutToolStripMenuItem1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AboutToolStripMenuItem1.Click
MessageBox.Show("Mortgage Calculator 1.0. Copyright 2013. All Rights Reserved", "About")
End Sub
Private Sub expenseTypeButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles expenseTypeButton.Click
If expenseTypeTextBox.Text = "" Then
MessageBox.Show("Please type weekly, bi-weekly, or monthly income in box, then click Income Amount Button",
"Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
Else
expenseTypeListBox.Items.Add(expenseTypeTextBox.Text)
expenseTypeTextBox.Text = ""
End If
End Sub
Private Sub cleButton1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cleButton1.Click
expenseTypeListBox.Items.Remove(expenseTypeListBox.SelectedItem)
End Sub
Private Sub caButton1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles caButton1.Click
expenseTypeListBox.Items.Clear()
End Sub
Private Sub expenseAmountButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles expenseAmountButton.Click
If expenseAmountTextBox.Text = "" Then
MessageBox.Show("Please type weekly, bi-weekly, or monthly income in box, then click Income Amount Button",
"Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
Else
expenseAmountListBox.Items.Add(expenseAmountTextBox.Text)
expenseAmountTextBox.Text = ""
End If
End Sub
Private Sub cleButton2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cleButton2.Click
expenseAmountListBox.Items.Remove(expenseAmountListBox.SelectedItem)
End Sub
Private Sub caButton2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles caButton2.Click
expenseAmountListBox.Items.Clear()
End Sub
Private Sub incomeAmountButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles incomeAmountButton.Click
If incomeAmountTextBox.Text = "" Then
MessageBox.Show("Please type weekly, bi-weekly, or monthly income in box, then click Income Amount Button",
"Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
Else
incomeListBox.Items.Add(incomeAmountTextBox.Text)
incomeAmountTextBox.Text = ""
End If
End Sub
Private Sub cleButton3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cleButton3.Click
incomeListBox.Items.Remove(incomeListBox.SelectedItem)
End Sub
Private Sub caButton3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles caButton3.Click
incomeListBox.Items.Clear()
End Sub
Private Sub calculateButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles calculateButton.Click
Dim total1 As Decimal
Dim total2 As Decimal
Dim total3 As Decimal
For x As Integer = 0 To expenseAmountListBox.Items.Count - 1
total1 += CDbl(expenseAmountListBox.Items(x))
Next
totalExpenseTextBox.Text = total1.ToString("C")
For x As Integer = 0 To incomeListBox.Items.Count - 1
total2 += CDbl(incomeListBox.Items(x))
Next
totalIncomeTextBox.Text = total2.ToString("C")
total3 += total2 - total1
surplusDeficitTextBox.Text = total3.ToString("C")
If total3 < 0 Then
surplusDeficitTextBox.ForeColor = Color.Red
Else
surplusDeficitTextBox.ForeColor = Color.Black
End If
End Sub
Private Sub clearSheetButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles clearSheetButton.Click
Dim result = MessageBox.Show("Are you sure you want to clear all data from this sheet? If sheet isn't saved, all data will be lost.",
"Confirmation", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Stop)
If result = DialogResult.Yes Then
expenseTypeListBox.Items.Clear()
expenseAmountListBox.Items.Clear()
incomeListBox.Items.Clear()
expenseTypeTextBox.Clear()
expenseAmountTextBox.Clear()
incomeAmountTextBox.Clear()
totalExpenseTextBox.Clear()
totalIncomeTextBox.Clear()
surplusDeficitTextBox.Clear()
End If
End Sub
End Class