How could I turn this console application into a Windows Form? PLEASE HELP!!

BRS0903

Member
Joined
Jun 12, 2006
Messages
11
Programming Experience
3-5
I am having trouble turning a console application into a windows application. Basically, the form would have 4 text boxes. Each text box would house the file path of two three boxes and one csv file. Each text box would have a button right next to it that would prompt the user to open a file path, 2 for txt and one for csv..the last text box and button would be the export file which would have a save dialog attached. How would I do this? I have been trying for a week now and still not getting it to work. Any takers? I would really appreciate it! Thanks! Below is the console application Module.

VB.NET:
Imports System
Imports System.IO
Imports System.Collections
 
Module Module2
Dim sr114Input As StreamReader
Dim sr385Input As StreamReader
Dim swOutput As StreamWriter
Dim strRunDate As String
Dim strRunTime As String
Dim strInput As String
Dim strWorkField As String
Dim strWorkChar As String
Dim lngCalcField As Long
Dim employeeDeferral As Long
Dim employerMatching As Long
Dim employeeSSN As String
Dim strOutput As String
Dim detailRecordCount As Integer
Dim totalContributionAmount As Long
Dim loanRepaymentAmount As Long
Dim sourceArray As Hashtable = New Hashtable
 
Function Main(ByVal cmdArgs() As String) As Integer
If cmdArgs.Length = 3 Then
Try
sr114Input = New StreamReader(cmdArgs(0))
sr385Input = New StreamReader(cmdArgs(1))
 
swOutput = New StreamWriter(cmdArgs(2))
 
Catch e As Exception
Console.WriteLine(e.Message)
Return -1
End Try
Else
Console.WriteLine("usage: Extensis401K <file114.txt> <file385.txt> <pruout.txt>")
Return -1
End If
 
Try
' Create an instance of StreamReader to read from file.
Using srChart As StreamReader = New StreamReader("401K Chart.csv")
Dim line As String
Dim lineArray() As String
'read and display the lines from the file until the end
'of the file is reached
Do
line = srChart.ReadLine()
If line Is Nothing Then Exit Do
lineArray = line.Split(",")
If lineArray.Length = 3 Then
sourceArray.Add(lineArray(1), lineArray(0))
Else
Console.WriteLine("Invalid 401K Chart.csv format")
Return -1
End If
Loop
srChart.Close()
End Using
Catch e As Exception
'Let the user know what went wrong.
Console.WriteLine("The file could not be read:")
Console.WriteLine(e.Message)
Return -1
End Try
 
Dim dtRun As Date = Now()
strRunDate = dtRun.Date.Year.ToString("0000") & dtRun.Date.Month.ToString("00") & dtRun.Date.Day.ToString("00")
strRunTime = dtRun.Hour.ToString("00") & dtRun.Minute.ToString("00") & dtRun.Second.ToString("00")
 
strOutput = "001COMBINED 002496 " & strRunDate & strRunTime & "C" & Space(593)
swOutput.WriteLine(strOutput)
 
detailRecordCount = 0
totalContributionAmount = 0
Do 'Process 114
strInput = sr114Input.ReadLine()
If strInput Is Nothing Then Exit Do
strOutput = "11401002496 "
 
' Social Security Number
employeeSSN = ""
MoveIt(1, 9, employeeSSN)
strOutput &= employeeSSN & Space(12)
 
'Employee Deferral
strWorkField = ""
MoveIt(12, 9, strWorkField)
employeeDeferral = Convert.ToInt64(FormatIt(strWorkField))
strWorkField = "000000000" & ConvertToEBCDIC(employeeDeferral)
strOutput &= "**A" & strWorkField.Substring(strWorkField.Length - 9, 9)
 
'Employer Matching
strWorkField = ""
MoveIt(23, 9, strWorkField)
employerMatching = Convert.ToInt64(FormatIt(strWorkField))
strWorkField = "000000000" & ConvertToEBCDIC(employerMatching)
strWorkField = strWorkField.Substring(strWorkField.Length - 9, 9)
 
totalContributionAmount += employeeDeferral
totalContributionAmount += employerMatching
 
strWorkChar = ""
MoveIt(40, 4, strWorkChar) ' Sub Plan Number Character for hashtable
strWorkChar = sourceArray(strWorkChar)
 
If employerMatching <> 0 And strWorkChar = "none" Then
Console.WriteLine("No Matching Plan for non-zero deferral for record")
Return -1
End If
strOutput &= "**P"
If strWorkChar = "P" Then
strOutput &= strWorkField 'Employer Matching
Else
strOutput &= "000000000"
End If
strOutput &= "**6"
If strWorkChar = "6" Then
strOutput &= strWorkField 'Employer Matching
Else
strOutput &= "000000000"
End If
strOutput &= "**4"
If strWorkChar = "4" Then
strOutput &= strWorkField 'Employer Matching
Else
strOutput &= "000000000"
End If
 
strOutput &= "**D"
If strWorkChar = "D" Then
strOutput &= strWorkField 'Employer Matching
Else
strOutput &= "000000000"
End If
 
strOutput &= "**C"
If strWorkChar = "C" Then
strOutput &= strWorkField 'Employer Matching
Else
strOutput &= "000000000"
End If
 
' Pay Period End Date
MoveIt(32, 8, strOutput)
strOutput &= " "
 
'Sub Plan Number
MoveIt(40, 4, strOutput)
 
'Formatted Name
strWorkField = ""
MoveIt(44, 24, strWorkField) 'Last Name
strWorkField = strWorkField.Trim & ", "
MoveIt(68, 12, strWorkField) 'First Name
strWorkField = strWorkField.Trim & " "
MoveIt(80, 1, strWorkField) 'Middle Initial
strWorkField &= Space(30)
strOutput &= strWorkField.Substring(0, 30)
 
'Address 1
MoveIt(81, 30, strOutput)
 
'Address 2
MoveIt(117, 30, strOutput)
 
'City
MoveIt(153, 18, strOutput)
 
'State
MoveIt(177, 2, strOutput)
 
' Zip Code
MoveIt(179, 9, strOutput)
 
 
'Date of Birth
MoveIt(189, 8, strOutput)
 
'Original Date of Hire
MoveIt(197, 8, strOutput)
strOutput &= Space(8)
 
'Marital Status
strWorkField = ""
MoveIt(205, 1, strWorkField) 'Marital Status
Select Case strWorkField
Case "S"
strOutput &= "1"
Case "M"
strOutput &= "2"
Case Else
Console.WriteLine("Invalid marital status for record " & strOutput)
Return -1
End Select
 
'Gender Code
strWorkField = ""
MoveIt(206, 1, strWorkField)
Select Case strWorkField
Case "M"
strOutput &= "1"
Case "F"
strOutput &= "2"
Case Else
Console.WriteLine("Invalid gender code for record " & strOutput)
Return -1
End Select
 
'EE Status
strWorkField = ""
MoveIt(207, 1, strWorkField)
Select Case strWorkField
Case "A"
strOutput &= "00"
MoveIt(197, 8, strOutput) ' Original Date of Hire
Case "T"
strOutput &= "32"
MoveIt(208, 8, strOutput) ' Termination Date
Case Else
Console.WriteLine("Invalid EE status for record " & strOutput)
Return -1
End Select
 
'Payroll Frequencey
strWorkField = ""
MoveIt(216, 1, strWorkField)
Select Case strWorkField
Case "Q"
strOutput &= "3"
Case "M"
strOutput &= "4"
Case "S"
strOutput &= "5"
Case "B"
strOutput &= "6"
Case "W"
strOutput &= "7"
Case Else
Console.WriteLine("Invalid payroll frequency for record " & strOutput)
Return -1
End Select
 
strOutput &= Space(14)
 
'Current Pay Period hours
strWorkField = ""
MoveIt(219, 4, strWorkField)
lngCalcField = Convert.ToInt64(FormatIt(strWorkField))
strWorkField = "000000" & ConvertToEBCDIC(lngCalcField)
strOutput &= strWorkField.Substring(strWorkField.Length = 6, 6)
 
'Current Pay Period Gross Pay
strWorkField = ""
MoveIt(226, 11, strWorkField)
lngCalcField = Convert.ToInt64(FormatIt(strWorkField))
strWorkField = "000000000000000" & ConvertToEBCDIC(lngCalcField)
strOutput &= strWorkField.Substring(strWorkField.Length - 15, 15)
strOutput &= Space(40)
 
' Check Date
MoveIt(237, 8, strOutput)
strOutput &= Space(98)
 
' Market Salary
strWorkField = ""
MoveIt(245, 10, strWorkField)
strWorkField = strWorkField.Trim.Replace(".", "")
lngCalcField = Convert.ToInt64(FormatIt(strWorkField))
strWorkField = "00000000000" & ConvertToEBCDIC(lngCalcField)
strOutput &= strWorkField.Substring(strWorkField.Length - 11, 11)
strOutput &= Space(163)
 
'Print Record
swOutput.WriteLine(strOutput)
detailRecordCount += 1
Loop 'End of process 114
 
loanRepaymentAmount = 0
Do 'Process 385 loan
strInput = sr385Input.ReadLine()
If strInput Is Nothing Then Exit Do
strOutput = "385 002496 "
 
'social Security Number
employeeSSN = ""
MoveIt(1, 9, employeeSSN)
strOutput &= employeeSSN & Space(6) & "1 "
 
'Loan Repayment Principal and Interest
strWorkField = ""
MoveIt(12, 9, strWorkField)
lngCalcField = Convert.ToInt64(FormatIt(strWorkField))
If lngCalcField = 0 Then
Console.WriteLine("Zero Loan Repayment for " & employeeSSN)
Continue Do
Else
loanRepaymentAmount += lngCalcField
End If
 
strWorkField = "000000000" & ConvertToEBCDIC(lngCalcField)
strOutput &= strWorkField.Substring(strWorkField.Length - 9, 9)
strOutput &= Space(10) & "2 PDED" & Space(19)
 
'Sub Plan Number
MoveIt(21, 4, strOutput)
strOutput &= Space(547)
 
'Print it out
swOutput.WriteLine(strOutput)
detailRecordCount += 1
Loop 'end of Process 385
 
Dim strTotalContributionAmount As String = "00000000000" & ConvertToEBCDIC(totalContributionAmount)
strTotalContributionAmount = strTotalContributionAmount.Substring(strTotalContributionAmount.Length - 11, 11)
Dim strLoanRepaymentAmount As String = "00000000000" & ConvertToEBCDIC(loanRepaymentAmount)
strLoanRepaymentAmount = strLoanRepaymentAmount.Substring(strLoanRepaymentAmount.Length - 11, 11)
 
strOutput = "999COMBINED 002496 " & strRunDate & strRunTime & _
detailRecordCount.ToString("000000000") & " " & _
strTotalContributionAmount & " " & strLoanRepaymentAmount & Space(561)
 
'Print it
swOutput.WriteLine(strOutput)
 
'close up shop
sr114Input.Close()
sr385Input.Close()
swOutput.Close()
 
Console.WriteLine(vbCrLf & vbCrLf & "normal Term @ " & strRunDate & " " & strRunTime & _
" with " & detailRecordCount & " records, " & vbCrLf & _
totalContributionAmount / 100 & " total contributions and " & vbCrLf & _
loanRepaymentAmount / 100 & " total principal and interest repayments.")
Return 0
End Function
Function ConvertToEBCDIC(ByVal lngNumber As Long) As String
Dim negVal As Boolean
Dim absNumber As Long
 
If lngNumber < 0 Then
negVal = True
absNumber = -1 * lngNumber
Else
negVal = False
absNumber = lngNumber
End If
 
Dim strNumber As String = absNumber.ToString()
If negVal Then
Select Case strNumber.Substring(strNumber.Length - 1, 1)
Case 0
strNumber = strNumber.Substring(0, strNumber.Length - 1) & "}"
Case 1
strNumber = strNumber.Substring(0, strNumber.Length - 1) & "J"
Case 2
strNumber = strNumber.Substring(0, strNumber.Length - 1) & "K"
Case 3
strNumber = strNumber.Substring(0, strNumber.Length - 1) & "L"
Case 4
strNumber = strNumber.Substring(0, strNumber.Length - 1) & "M"
Case 5
strNumber = strNumber.Substring(0, strNumber.Length - 1) & "N"
Case 6
strNumber = strNumber.Substring(0, strNumber.Length - 1) & "O"
Case 7
strNumber = strNumber.Substring(0, strNumber.Length - 1) & "P"
Case 8
strNumber = strNumber.Substring(0, strNumber.Length - 1) & "Q"
Case 9
strNumber = strNumber.Substring(0, strNumber.Length - 1) & "R"
Case Else
Console.WriteLine(strNumber.Substring(strNumber.Length - 1, 1) & "invalid number in ConvertToEBCDIC")
Return -1
End Select
End If
End Function
Sub MoveIt(ByVal inpStartLoc As Integer, ByVal outLength As Integer, ByRef buildString As String)
Dim intFrom As Integer = inpStartLoc - 1
Dim intTo As Integer = intFrom + outLength - 1
For k As Integer = intFrom To intTo
buildString &= strInput(k)
Next
End Sub
 
Function FormatIt(ByVal strInput As String) As String
Dim strOutput As String = strInput.Trim.TrimStart("0")
If strOutput.Length = 0 Then
Return "0"
Else
Return strOutput
End If
End Function
End Module
 
Last edited by a moderator:
Top Bottom