User:Cremepuff222/Sandbox
From Wikipedia, the free encyclopedia
[edit] Main Code
Option Explicit
Private Sub cmdAddIncome_Click()
On Error Resume Next 'Move Data Relocate_Income_Values 'Get Data varIncomeInformation(0, 0) = Now varIncomeInformation(0, 1) = InputBox("How much money did you make?", "Input Data") varIncomeInformation(0, 2) = InputBox("How exactly did you earn that money?", "Input Data") 'Use data lstIncomeHistory.AddItem varIncomeInformation(0, 0), 0 curIncomeTotal = curIncomeTotal + varIncomeInformation(0, 1) lblIncomeTotal.Caption = FormatCurrency(curIncomeTotal)
End Sub
Private Sub cmdAddExpense_Click()
On Error Resume Next 'Move Data Relocate_Expense_Values 'Get Data varExpenseInformation(0, 0) = Now varExpenseInformation(0, 1) = InputBox("How much money did you spend?", "Input Data") varExpenseInformation(0, 2) = InputBox("What exactly did you buy with that money?", "Input Data") 'Use data lstExpenseHistory.AddItem varExpenseInformation(0, 0), 0 curExpenseTotal = curExpenseTotal + varExpenseInformation(0, 1) lblExpenseTotal.Caption = FormatCurrency(-(curExpenseTotal))
End Sub
Private Sub cmdClearData_Click()
'Declare variable Dim varPassword As Variant Dim varAttempt As Variant Dim intIndex As Integer Dim intIndex2 As Integer varPassword = "cremepuff222iscool" 'Ask for password varAttempt = InputBox("What's the password?", "Input Data") If varAttempt <> varPassword Then MsgBox "That's not the password!", vbCritical GoTo 1 End If For intIndex = 0 To 2 Select Case intIndex Case Is = 0 curIncomeTotal = 0 Case Is = 1 curExpenseTotal = 0 Case Is = 2 curProfitTotal = 0 End Select Next intIndex intIndex = 0 Do While intIndex <= 25 intIndex2 = 0 Do While intIndex2 <= 2 varIncomeInformation(intIndex, intIndex2) = "" intIndex2 = intIndex2 + 1 Loop intIndex = intIndex + 1 Loop intIndex = 0 Do While intIndex <= 25 intIndex2 = 0 Do While intIndex2 <= 2 varExpenseInformation(intIndex, intIndex2) = "" intIndex2 = intIndex2 + 1 Loop intIndex = intIndex + 1 Loop cmdClearIncome_Click cmdClearExpense_Click cmdSave_Click Get_Data
1 'Ha, ha! Wrong password! End Sub
Private Sub cmdClearExpense_Click()
'Clear list lstExpenseHistory.Clear lblExpenseAmount.Caption = "" lblExpenseDescription = ""
End Sub
Private Sub cmdClearIncome_Click()
'Clear list lstIncomeHistory.Clear lblIncomeAmount.Caption = "" lblIncomeDescription = ""
End Sub
Private Sub cmdExit_Click()
'Save information to a file Dim intIndex As Integer Dim intMaximum As Integer 'Save income date data Open "C:\Documents and Settings\Nick\Desktop\Cash Tracker\Data\Income Data.txt" For Output As #1 intMaximum = lstIncomeHistory.ListCount - 1 For intIndex = 0 To intMaximum Write #1, lstIncomeHistory.List(intIndex) Next intIndex Close #1 'Save income amount data Open "C:\Documents and Settings\Nick\Desktop\Cash Tracker\Data\Income Amount Data.txt" For Output As #1 intMaximum = lstIncomeHistory.ListCount - 1 For intIndex = 0 To intMaximum Write #1, varIncomeInformation(intIndex, 1) Next intIndex Close #1 'Save income description data Open "C:\Documents and Settings\Nick\Desktop\Cash Tracker\Data\Income Description Data.txt" For Output As #1 intMaximum = lstIncomeHistory.ListCount - 1 For intIndex = 0 To intMaximum Write #1, varIncomeInformation(intIndex, 2) Next intIndex Close #1 'Save expense date data Open "C:\Documents and Settings\Nick\Desktop\Cash Tracker\Data\Expense Data.txt" For Output As #1 intMaximum = lstExpenseHistory.ListCount - 1 For intIndex = 0 To intMaximum Write #1, lstExpenseHistory.List(intIndex) Next intIndex Close #1 'Save expense amount data Open "C:\Documents and Settings\Nick\Desktop\Cash Tracker\Data\Expense Amount Data.txt" For Output As #1 intMaximum = lstExpenseHistory.ListCount - 1 For intIndex = 0 To intMaximum Write #1, varExpenseInformation(intIndex, 1) Next intIndex Close #1 'Save expense description data Open "C:\Documents and Settings\Nick\Desktop\Cash Tracker\Data\Expense Description Data.txt" For Output As #1 intMaximum = lstExpenseHistory.ListCount - 1 For intIndex = 0 To intMaximum Write #1, varExpenseInformation(intIndex, 2) Next intIndex Close #1 'Save summary data Open "C:\Documents and Settings\Nick\Desktop\Cash Tracker\Data\Summary Data.txt" For Output As #1 For intIndex = 0 To 2 Select Case intIndex Case Is = 0 Write #1, curIncomeTotal Case Is = 1 Write #1, curExpenseTotal Case Is = 2 Write #1, curProfitTotal End Select Next intIndex Close #1 'Close program End
End Sub
Private Sub Get_Data()
'Retrieve information from file Dim intLcv As Integer 'Get income dates Open "C:\Documents and Settings\Nick\Desktop\Cash Tracker\Data\Income Data.txt" For Input As #1 intLcv = 0 Do Until EOF(1) Input #1, varIncomeInformation(intLcv, 0) intLcv = intLcv + 1 Loop Close #1 'Get income amounts Open "C:\Documents and Settings\Nick\Desktop\Cash Tracker\Data\Income Amount Data.txt" For Input As #1 intLcv = 0 Do Until EOF(1) Input #1, varIncomeInformation(intLcv, 1) intLcv = intLcv + 1 Loop Close #1 'Get income descriptions Open "C:\Documents and Settings\Nick\Desktop\Cash Tracker\Data\Income Description Data.txt" For Input As #1 intLcv = 0 Do Until EOF(1) Input #1, varIncomeInformation(intLcv, 2) intLcv = intLcv + 1 Loop Close #1 'Get expense dates Open "C:\Documents and Settings\Nick\Desktop\Cash Tracker\Data\Expense Data.txt" For Input As #1 intLcv = 0 Do Until EOF(1) Input #1, varExpenseInformation(intLcv, 0) intLcv = intLcv + 1 Loop Close #1 'Get expense amounts Open "C:\Documents and Settings\Nick\Desktop\Cash Tracker\Data\Expense Amount Data.txt" For Input As #1 intLcv = 0 Do Until EOF(1) Input #1, varExpenseInformation(intLcv, 1) intLcv = intLcv + 1 Loop Close #1 'Get expense descriptions Open "C:\Documents and Settings\Nick\Desktop\Cash Tracker\Data\Expense Description Data.txt" For Input As #1 intLcv = 0 Do Until EOF(1) Input #1, varExpenseInformation(intLcv, 2) intLcv = intLcv + 1 Loop Close #1 'Get summary amounts Open "C:\Documents and Settings\Nick\Desktop\Cash Tracker\Data\Summary Data.txt" For Input As #1 intLcv = 0 Do While intLcv <= 2 Select Case intLcv Case Is = 0 Input #1, curIncomeTotal Case Is = 1 Input #1, curExpenseTotal Case Is = 2 Input #1, curProfitTotal End Select intLcv = intLcv + 1 Loop Close #1 Load_Lists
End Sub
Private Sub cmdSave_Click()
'Save information to a file Dim intIndex As Integer Dim intMaximum As Integer 'Save income date data Open "C:\Documents and Settings\Nick\Desktop\Cash Tracker\Data\Income Data.txt" For Output As #1 intMaximum = lstIncomeHistory.ListCount - 1 For intIndex = 0 To intMaximum Write #1, lstIncomeHistory.List(intIndex) Next intIndex Close #1 'Save income amount data Open "C:\Documents and Settings\Nick\Desktop\Cash Tracker\Data\Income Amount Data.txt" For Output As #1 intMaximum = lstIncomeHistory.ListCount - 1 For intIndex = 0 To intMaximum Write #1, varIncomeInformation(intIndex, 1) Next intIndex Close #1 'Save income description data Open "C:\Documents and Settings\Nick\Desktop\Cash Tracker\Data\Income Description Data.txt" For Output As #1 intMaximum = lstIncomeHistory.ListCount - 1 For intIndex = 0 To intMaximum Write #1, varIncomeInformation(intIndex, 2) Next intIndex Close #1 'Save expense date data Open "C:\Documents and Settings\Nick\Desktop\Cash Tracker\Data\Expense Data.txt" For Output As #1 intMaximum = lstExpenseHistory.ListCount - 1 For intIndex = 0 To intMaximum Write #1, lstExpenseHistory.List(intIndex) Next intIndex Close #1 'Save expense amount data Open "C:\Documents and Settings\Nick\Desktop\Cash Tracker\Data\Expense Amount Data.txt" For Output As #1 intMaximum = lstExpenseHistory.ListCount - 1 For intIndex = 0 To intMaximum Write #1, varExpenseInformation(intIndex, 1) Next intIndex Close #1 'Save expense description data Open "C:\Documents and Settings\Nick\Desktop\Cash Tracker\Data\Expense Description Data.txt" For Output As #1 intMaximum = lstExpenseHistory.ListCount - 1 For intIndex = 0 To intMaximum Write #1, varExpenseInformation(intIndex, 2) Next intIndex Close #1 'Save summary data Open "C:\Documents and Settings\Nick\Desktop\Cash Tracker\Data\Summary Data.txt" For Output As #1 For intIndex = 0 To 2 Select Case intIndex Case Is = 0 Write #1, curIncomeTotal Case Is = 1 Write #1, curExpenseTotal Case Is = 2 Write #1, curProfitTotal End Select Next intIndex Close #1
End Sub
Private Sub Form_Load()
'Load information Get_Data lblExpenseTotal.ForeColor = RGB(251, 89, 89) lblIncomeTotal.ForeColor = RGB(5, 237, 5)
End Sub
Private Sub lblIncomeTotal_Change()
'Change data curProfitTotal = curIncomeTotal - curExpenseTotal lblProfitTotal.Caption = FormatCurrency(curProfitTotal, 2)
End Sub
Private Sub lblExpenseTotal_Change()
'Change data curProfitTotal = curIncomeTotal - curExpenseTotal lblProfitTotal.Caption = FormatCurrency(curProfitTotal, 2)
End Sub
Private Sub lblProfitTotal_Change()
'Change color If curProfitTotal < 0 Then lblProfitTotal.ForeColor = RGB(251, 89, 89) Else lblProfitTotal.ForeColor = RGB(5, 237, 5) End If
End Sub
Private Sub lstExpenseHistory_Click()
On Error Resume Next 'Declare variables Dim intExpenseIndex As Integer 'Get data intExpenseIndex = lstExpenseHistory.ListIndex 'Use data lblExpenseAmount.Caption = FormatCurrency(varExpenseInformation(intExpenseIndex, 1)) lblExpenseDescription.Caption = varExpenseInformation(intExpenseIndex, 2)
End Sub
Private Sub lstIncomeHistory_Click()
On Error Resume Next 'Declare variables Dim intIncomeIndex As Integer 'Get data intIncomeIndex = lstIncomeHistory.ListIndex 'Use data lblIncomeAmount.Caption = FormatCurrency(varIncomeInformation(intIncomeIndex, 1)) lblIncomeDescription.Caption = varIncomeInformation(intIncomeIndex, 2)
End Sub
[edit] Module Code
Option Explicit Public varIncomeInformation(0 To 25, 0 To 2) As Variant Public varExpenseInformation(0 To 25, 0 To 2) As Variant
Public curIncomeTotal As Currency Public curExpenseTotal As Currency Public curProfitTotal As Currency
Public Sub Load_Lists()
'Declare variables Dim intLcv As Integer 'Load data frmTracker.lstIncomeHistory.Clear frmTracker.lstExpenseHistory.Clear 'Load income dates intLcv = 0 Do While intLcv <= 25 If varIncomeInformation(intLcv, 0) = "" Then Exit Do End If frmTracker.lstIncomeHistory.AddItem (varIncomeInformation(intLcv, 0)) intLcv = intLcv + 1 Loop 'Load expense dates intLcv = 0 Do While intLcv <= 25 If varExpenseInformation(intLcv, 0) = "" Then Exit Do End If frmTracker.lstExpenseHistory.AddItem (varExpenseInformation(intLcv, 0)) intLcv = intLcv + 1 Loop 'Load summary frmTracker.lblIncomeTotal.Caption = FormatCurrency(curIncomeTotal, 2) frmTracker.lblExpenseTotal.Caption = FormatCurrency(-curExpenseTotal, 2) frmTracker.lblProfitTotal.Caption = FormatCurrency(curProfitTotal, 2)
End Sub
Public Sub Relocate_Income_Values()
'Declare variables Dim intLcv As Integer Dim intLcv2 As Integer 'Relocate variables intLcv = 25 Do While intLcv >= 0 If varIncomeInformation(intLcv, 0) <> "" Then intLcv2 = 0 Do While intLcv2 <= 2 varIncomeInformation(intLcv + 1, intLcv2) = varIncomeInformation(intLcv, intLcv2) intLcv2 = intLcv2 + 1 Loop End If intLcv = intLcv - 1 Loop
End Sub
Public Sub Relocate_Expense_Values()
'Declare variables Dim intLcv As Integer Dim intLcv2 As Integer 'Relocate variables intLcv = 25 Do While intLcv >= 0 If varExpenseInformation(intLcv, 0) <> "" Then intLcv2 = 0 Do While intLcv2 <= 2 varExpenseInformation(intLcv + 1, intLcv2) = varExpenseInformation(intLcv, intLcv2) intLcv2 = intLcv2 + 1 Loop End If intLcv = intLcv - 1 Loop
End Sub