Question:
Need HELP Visual Basics!!?
anonymous
2009-05-08 19:22:43 UTC
Sub BtnQuit_Click
Sub btnCompute_Click
Sub ClearScreen
Sub CalculateWH
Function GetTheFileName
Sub ReadPayrollData
Sub SavePayrollData
Sub Form1_Load
Sub btnRead_Click
Sub btnSave_Click
Sub Missing
Sub btnSave_Click
Sub Form1_Closing


Private Sub btnQuit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnQuit.Click
Me.Close()
End Sub

Private Sub btnCompute_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCompute.Click
CalculateWH()
End Sub

Sub ClearScreen()
Dim Temp As String
Temp = mskSSN.Mask
mskSSN.Mask = ""
mskSSN.CtlText = ""
mskSSN.Mask = Temp
txtName.Text = ""
lblIncome.Text = ""
txtCurrentIncome.Text = ""
lblPrevIncome.Text = ""
lblPrevWithholdings.Text = ""
lblCurrentIncome.Text = ""
lblCurrentWithholdings.Text = ""
End Sub

Sub CalculateWH()
Dim CurrentIncome As Double
Dim PrevIncome As Double
Dim CurrentWithholding As Double
Dim TotalWithholding As Double
Dim PrevWithholding As Double
Dim TotalIncome As Double

CurrentIncome = Val(txtCurrentIncome.Text)
If IsNumeric(lblPrevIncome.Text) Then
PrevIncome = CDbl(lblPrevIncome.Text)
End If
TotalIncome = CurrentIncome + PrevIncome

If PrevIncome < 45000 Then
PrevWithholding = (PrevIncome * 0.062)
Else
'Max SST
PrevWithholding = 45000 * 0.062
End If
'For Meidicare tax
If PrevIncome < 120000 Then
PrevWithholding += (PrevIncome * 0.0145)
Else
'Max MT
PrevWithholding += 120000 * 0.0145
End If

If TotalIncome < 45000 Then
TotalWithholding = (TotalIncome * 0.062)
Else
TotalWithholding = (45000 * 0.062)
End If
'For MT
If TotalIncome < 120000 Then
TotalWithholding += (TotalIncome * 0.0145)
Else
TotalWithholding += 120000 * 0.0145
End If
CurrentWithholding = TotalWithholding - PrevWithholding

lblPrevIncome.Text = Format(PrevIncome, "Standard")
lblCurrentIncome.Text = Format(CurrentIncome, "Standard")
lblPrevWithholdings.Text = Format(PrevWithholding, "Standard")
lblCurrentWithholdings.Text = Format(CurrentWithholding, "Standard")
End Sub

Private Function GetTheFileName(ByVal TheDialog As FileDialog, ByVal TheTitle As String, ByVal TheFilter As String) As String
With TheDialog
.Title = TheTitle
.Filter = TheFilter
.ShowDialog()
Return (.FileName)
End With
End Function

Sub ReadPayrollData()
Dim Response As Integer

Dim PayData As String
Dim P0, P As Integer
Dim Temp As String

If PayrollReader.Peek() = -1 Then
MsgBox("No More Records")
ClearScreen()
Exit Sub
End If
PayData = PayrollReader.ReadLine()
P = InStr(PayData, ",")
Temp = mskSSN.Mask
mskSSN.Mask = ""
mskSSN.CtlText = Microsoft.VisualBasic.Left(PayData, P - 1)
mskSSN.Mask = Temp
P0 = P
P = InStr(P + 1, PayData, ",")
txtName.Text = Mid(PayData, P0 + 1, P - P0 - 1)
P0 = P
P = InStr(P + 1, PayData, ",")
lblPrevIncome.Text = Format(CDbl(Mid(PayData, P0 + 1, P - P0 - 1)), "Standard")
lblIncome.Text = lblPrevIncome.Text
Temp = Mid(PayData, P + 2)
If Missing(Temp) Then
Temp = "0"
End If
lblPrevWithholdings.Text = Format(CDbl(Temp), "Standard")
End Sub

Sub SavePayrollData()
Dim OutputLine As String
Dim TotalIncome, totalWH As Double

TotalIncome = CDbl(lblCurrentIncome.Text) + CDbl(lblPrevIncome.Text)
totalWH = CDbl(lblPrevWithholdings.Text) + CDbl(lblCurrentWithholdings.Text)
OutputLine = mskSSN.CtlText & ", " & txtName.Text & ", " & TotalIncome & ", " & totalWH
PayrollWriter.WriteLine(OutputLine)
End Sub

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim InFileName As String
Dim OutFileName As String
InFileName = GetTheFileName(cdlOpenFile, "Where is the payroll y-t-d file?", FileFilter)
OutFileName = GetTheFileName(cdlSaveFile, "Specify filename to save", FileFilter)
PayrollReader = New System.IO.StreamReader(InFileName)
PayrollWriter = New System.IO.StreamWriter(OutFileName)
End Sub

Private Sub btnRead_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnRead.Click
ReadPayrollData()
End Sub
Four answers:
topherG
2009-05-08 20:36:40 UTC
Go learn visual basic. No one is going to tell you what each line of this program is doing...
rk
2009-05-09 13:32:10 UTC
Public Class Form1

'decalres variables that are common for more than one sub or functions



Dim PayrollReader As System.IO.StreamReader ' new line added in the global section so that other subs can access it

Dim PayrollWriter As System.IO.StreamWriter ' new line added in the global section so that other subs can access it

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

'gets the file name for opening and saving from the respective dialog boxes through GetTheFileName function

Dim InFileName As String

Dim OutFileName As String

Dim FileFilter As String ' new line added

FileFilter = "Text files (*.txt)|*.txt|All files (*.*)|*.*" 'file filter defined

InFileName = GetTheFileName(cdlOpenFile, "Where is the payroll y-t-d file?", FileFilter)

'MessageBox.Show(" input file selected")

PayrollReader = New System.IO.StreamReader(InFileName)

OutFileName = GetTheFileName(cdlSaveFile, "Specify filename to save", FileFilter)

PayrollWriter = New System.IO.StreamWriter(OutFileName)

End Sub

Private Function GetTheFileName(ByVal TheDialog As FileDialog, ByVal TheTitle As String, ByVal TheFilter As String) As



String

'returns the selected name from either the file open dialog or file save as dialog box



With TheDialog

.Title = TheTitle

.Filter = TheFilter

.ShowDialog()

Return (.FileName)

End With

End Function



Private Sub BtnQuit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnQuit.Click

PayrollWriter.Close() ' new line added - all streams must be closed before exit

PayrollReader.Close() ' new line added - all streams must be closed before exit

Me.Close()

End Sub



Private Sub btnCompute_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCompute.Click

CalculateWH()

End Sub

Sub CalculateWH()

Dim CurrentIncome As Double

Dim PrevIncome As Double

Dim CurrentWithholding As Double

Dim TotalWithholding As Double

Dim PrevWithholding As Double

Dim TotalIncome As Double

' processes the various components of payroll from the data stored in local variables and in controls

CurrentIncome = Val(txtCurrentIncome.Text)' user entry for current income in a text box

If IsNumeric(lblPrevIncome.Text) Then

PrevIncome = CDbl(lblPrevIncome.Text)

End If

TotalIncome = CurrentIncome + PrevIncome

' the IF statement calculates SST

If PrevIncome < 45000 Then

PrevWithholding = (PrevIncome * 0.062)

Else

'Max SST

PrevWithholding = 45000 * 0.062

End If

'For Meidicare tax

'' the IF statement calculates medicare tax

If PrevIncome < 120000 Then

PrevWithholding += (PrevIncome * 0.0145)

Else

'Max MT

PrevWithholding += 120000 * 0.0145

End If

' calculates the total WH

If TotalIncome < 45000 Then

TotalWithholding = (TotalIncome * 0.062)

Else

TotalWithholding = (45000 * 0.062)

End If

'For MT

' includes MT for total WH

If TotalIncome < 120000 Then

TotalWithholding += (TotalIncome * 0.0145)

Else

TotalWithholding += 120000 * 0.0145

End If

' determine what must be the current WH

CurrentWithholding = TotalWithholding - PrevWithholding

' display all the calculated data in respective controls

lblPrevIncome.Text = Format(PrevIncome, "Standard")

lblCurrentIncome.Text = Format(CurrentIncome, "Standard")

lblPrevWithholdings.Text = Format(PrevWithholding, "Standard")

lblCurrentWithholdings.Text = Format(CurrentWithholding, "Standard")

End Sub



Sub ReadPayrollData()

'removed this line since it is not used Dim Response As Integer

Dim PayData As String

Dim P0, P As Integer

Dim Temp As String

' if no more record are present, show message, clear screen and exit from sub

If PayrollReader.Peek() = -1 Then

MsgBox("No More Records")

ClearScreen()

Exit Sub

End If

' if recorda are there, read one record which is of the form 100-10-1111,stephens,1000,500

PayData = PayrollReader.ReadLine()

P = InStr(PayData, ",")'find index of first , and extract SSN 100-10-1111 from the data and display it in the masked



edit box

Temp = mskSSN.Mask

mskSSN.Mask = ""

' mskSSN.CtlText = Microsoft.VisualBasic.Left(PayData, P - 1) - property ctltext is not found in VB2008,



instead text property is used

mskSSN.Text = Microsoft.VisualBasic.Left(PayData, P - 1) ' incorporates the above
Ask Expert 6
2009-05-09 05:21:32 UTC
You may contact a VB expert live at freelance websites like http://ijug.net/ , http://getafreelnacer.com/ ,etc .
spiller
2009-05-09 02:30:13 UTC
What's the problem?


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...