Solved

IndexOutofRangeException was unhandled

Posted on 2006-06-14
38
1,071 Views
Last Modified: 2008-01-09
I am having a problem with my program.  I recently took on the task of trying to create a Windows form program.  The back end code was already written by somebody else, but he wrote everything in a module.  He didn't make things object oriented or easy to use, so now I am running into problems nearing the end of this program.  I recently ran into a "IndexOutofRangeException was unhandled" problem and it's stopping me from finishing the program.  The following was said in the Troubleshooting tips section:

1)Make sure that the maximum index on a list is less than the list size.

2)Make sure data column names are correct.

3) Make sure the index is not a negative number

4) Get general help for this section.

Can anybody help?

Below is the code in the sub section in the module that was handed to me.

 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 - 1
            buildString &= strInput(k)

        Next
    End Sub

I declared strInput at the top of the module as the following which is not in the sub above.
Dim strInput As String = ""

Can anybody help please?  Thank you!
0
Comment
Question by:VBBRett
  • 20
  • 17
38 Comments
 
LVL 17

Expert Comment

by:ZeonFlash
ID: 16902834
The function isn't going to really do anything.  You're passing buildString in by reference, but inside the for loop you're appending nothing to it (since strInput is an empty string).  You're sure that strInput isn't a public variable being pulled from somewhere else?
0
 

Author Comment

by:VBBRett
ID: 16902860
Well, I am passing something to it from another file called Form1.  Here is how it would look in Form1.

Do  'Process 114
            strInput = TextBox1.Text
            If strInput Is Nothing Then Exit Do
            strOutput = "11401002496   "

            ' Social Security Number
            'employeeSSN = ""
            'employeeSSN = String.Empty
            Dim employeeSSN As New String("")
            MoveIt(1, 9, employeeSSN)
            strOutput &= employeeSSN & Space(12)

            'Employee Deferral
            'strWorkField = ""
            Dim strWorkField As New String("")
            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)
0
 

Author Comment

by:VBBRett
ID: 16903180
Anybody have the answer?  500 points sounds like a lot of points..LOL!
0
 
LVL 62

Expert Comment

by:Fernando Soto
ID: 16903306
Hi VBBRett;

Well two things I see that are a problem.
1. Dim strInput As String = "" Needs to be an array and not a just one string
2. Your Subroutine can throw an error if the values are outside the range of the array. The code below shows how I would handle it.

    ' Test Data
    Dim strInput() As String = {"One ", "Two ", "Three "}

    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

        ' Check to see if the intFrom and the intTo are valid values.
        If intFrom < 0 Or intTo > strInput.Length Then
            MessageBox.Show("Index is outside the valid range of the array")
            buildString = "Range ERROR"
            Return
        End If

        For k As Integer = intFrom To intTo - 1
            buildString &= strInput(k)
        Next

    End Sub


I hope that this was of some help.

Fernando
0
 
LVL 62

Expert Comment

by:Fernando Soto
ID: 16903596
Hi VBBRett;

Looking at your second post is this subroutine looking to move certain columns of the field from the TextBox1.Text to a new variable?

Fernando
0
 

Author Comment

by:VBBRett
ID: 16903620
Hi Fernando,

To be quite honest with you Fernando it is reading from a text file that has the file directory location in one of the text files.

textbox1.text = "C:\textfilewithinformation.txt"

Does that make it clearer?
0
 

Author Comment

by:VBBRett
ID: 16903630
Should I just post all of the code for you to see in the form and the module?
0
 
LVL 62

Expert Comment

by:Fernando Soto
ID: 16903867
Yes if you can post it that will be great. And a couple of the lines from that data file.
0
 

Author Comment

by:VBBRett
ID: 16903879
OK, here is the module

module 2------------------------------------------------------------------------------------------
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 = ""
    'Dim strInput = New ArrayList
    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
-----------------------------------------------------------------------------------
0
 

Author Comment

by:VBBRett
ID: 16903978
And here is the form code.  I know I am doing something wrong, but I'm trying to find my way.

form1------------------------------------------------------------------------------------------------------------
Imports System
Imports System.IO
Imports System.Collections
Imports NIPWindowsApplication.Module2

Public Class frmNIP


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


    Private Sub mnuOpen_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuOpen.Click
        Dim strFileName As String
        Dim DidWork As Integer


        OpenFD.InitialDirectory = "C:\PRU401k"
        OpenFD.Title = "Open a text File"
        OpenFD.Filter = "Text Files(*.txt)|*******R.txt"
        OpenFD.ShowDialog()

        If DidWork = DialogResult.Cancel Then
            MsgBox("Cancel button Clicked")
        Else
            strFileName = OpenFD.FileName
            MsgBox(strFileName)
            TextBox1.Text = strFileName
        End If
    End Sub

    Private Sub mnuOpen2text_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuOpen2text.Click
        Dim strFileName2 As String
        Dim DidWork2 As Integer

        OpenFD2.InitialDirectory = "C:\PRU401k"
        OpenFD2.Title = "Open a text File"
        OpenFD2.Filter = "Text Files(*.txt)|*******L.txt"
        OpenFD2.ShowDialog()

        If DidWork2 = DialogResult.Cancel Then
            MsgBox("Cancel button Clicked")
        Else
            strFileName2 = OpenFD2.FileName
            MsgBox(strFileName2)
            TextBox2.Text = strFileName2
        End If
    End Sub


    Private Sub mnu401k_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnu401k.Click
        Dim strFileName3 As String
        Dim DidWork3 As Integer

        OpenFD3.InitialDirectory = "C:\PRU401k"
        OpenFD3.Title = "Open the 401k File"
        OpenFD3.Filter = "CSV Files(.csv)|*.csv"
        OpenFD3.ShowDialog()

        If DidWork3 = DialogResult.Cancel Then
            MsgBox("Cancel button Clicked")
        Else
            strFileName3 = OpenFD3.FileName
            MsgBox(strFileName3)
            TextBox3.Text = strFileName3
        End If
    End Sub


    Private Sub btnFileFind1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnFileFind1.Click
        Dim strFileName As String
        Dim DidWork As Integer


        OpenFD.InitialDirectory = "C:\PRU401k"
        OpenFD.Title = "Open a text File"
        OpenFD.Filter = "Text Files(*.txt)|*******R.txt"
        OpenFD.ShowDialog()

        If DidWork = DialogResult.Cancel Then
            MsgBox("Cancel button Clicked")
        Else
            strFileName = OpenFD.FileName
            MsgBox(strFileName)
            TextBox1.Text = strFileName
        End If

    End Sub

    Private Sub btnFileFind2_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnFileFind2.Click
        Dim strFileName2 As String
        Dim DidWork2 As Integer

        OpenFD2.InitialDirectory = "C:\PRU401k"
        OpenFD2.Title = "Open a text File"
        OpenFD2.Filter = "Text Files(*.txt)|*******L.txt"
        OpenFD2.ShowDialog()

        If DidWork2 = DialogResult.Cancel Then
            MsgBox("Cancel button Clicked")
        Else
            strFileName2 = OpenFD2.FileName
            MsgBox(strFileName2)
            TextBox2.Text = strFileName2
        End If

    End Sub

    Private Sub btnFileFind3_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnFileFind3.Click
        Dim strFileName3 As String
        Dim DidWork3 As Integer

        OpenFD3.InitialDirectory = "C:\PRU401k"
        OpenFD3.Title = "Open the 401k File"
        OpenFD3.Filter = "CSV Files(.csv)|*.csv"
        OpenFD3.ShowDialog()

        If DidWork3 = DialogResult.Cancel Then
            MsgBox("Cancel button Clicked")
        Else
            strFileName3 = OpenFD3.FileName
            MsgBox(strFileName3)
            TextBox3.Text = strFileName3
        End If

    End Sub

    Private Sub btnRun_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnRun.Click
        'Dim srChart As StreamReader = New StreamReader(TextBox3.Text)
        Try
            'Create an instance of StreamReader to read from a file.
            Using srChart As StreamReader = New StreamReader(TextBox3.Text)
                Dim line As String
                Dim lineArray() As String
                Dim sourceArray As Hashtable = New Hashtable
                '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 Ex As Exception
            'Let the user know what went wrong.
            Console.WriteLine("The file could not be read:")
            Console.WriteLine(Ex.Message)
            'Return -1
        End Try

        Dim strRunDate
        Dim dtRun As Date = Now()
        strRunDate = dtRun.Date.Year.ToString("0000") & dtRun.Date.Month.ToString("00") & _
        dtRun.Date.Day.ToString("00")

        Dim strOutput As String
        Dim swOutput As StreamWriter
        Dim strRunTime As String
        Dim detailRecordCount As String
        Dim strInput As String
        Dim totalContributionAmount As Long
        Dim sr114Input As StreamReader
        ' Dim employeeSSN As String
        '  Dim strWorkField As String
        Dim employeeDeferral As Long
        Dim employerMatching As Long
        Dim strWorkChar As String
        Dim lngCalcField As Long

        strOutput = "001COMBINED  002496   " & strRunDate & strRunTime & "C" & Space(593)
        swOutput = New StreamWriter(strOutput)


        detailRecordCount = 0
        totalContributionAmount = 0

        Do  'Process 114
            strInput = TextBox1.Text
            If strInput Is Nothing Then Exit Do
            strOutput = "11401002496   "

            ' Social Security Number
            'employeeSSN = ""
            'employeeSSN = String.Empty
            Dim employeeSSN As New String("")
            MoveIt(1, 9, employeeSSN)
            strOutput &= employeeSSN & Space(12)

            'Employee Deferral
            'strWorkField = ""
            Dim strWorkField As New String("")
            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 114p


    End Sub

    Private Sub btnDone_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDone.Click
        Me.Close()
    End Sub
End Class

---------------------------------------------------------------------------------------------------------------------------------

And just for your information.  Here is what would go into the first text box....two records here...edited for security purposes.
The following information would go into a text file named I060406R.txt.  This would be pulled into the first text box via an openfiledialog and the text file directory would be shown in that text box.
1253068400000001836200000001913200606021001MARCUS                 BOFINKLE LOL     25 TREEBEARD DRIVE                                                        PARLIN                  NJ08859     1940062519980309SFA        B0000000000000015301520060602  21282.90
1478474170000002119000000001766200606021001CUBA JR               GOODING     C305 SEPTEMBER ROAD                                                   CLARK                   NJ07066     1958020819990802MMA        B000-200000000014126520060602  25728.90

The second file would be a text file that would be called I060406L.txt.  The filedirectory information would be located in the second text box.
148568148000000073761001
147583027000000118641001

And the last text box would house the directory information for the .csv file which would have the following records.  This file would be called 401k Chart.csv.
6      1001      Comment area
C      1015      Comment area
C      1017      Comment area
C      1020      Comment area
C      2008      Comment area
6      2019      Comment area
6      2021      Comment area
6      2022      Comment area
6      2027      Comment area
6      2040      Comment area
6      2048      Comment area
D      2051      Comment area
6      3001      Comment area
6      3101      Comment area
6      4012      Comment area
none      4017      No Matching
none      4018      Comment area
6      4049      Comment area
6      4062      Comment area
6      4065      Comment area
D      4080      Comment area
6      4084      Comment area
C      4085      Comment area
6      4086      Comment area
6      4088      Comment area
4      4094      Comment area
6      4098      Comment area
6      4106      Comment area
6      4109      Comment area
6      4113      Comment area
6      4116      Comment area
6      4119      Comment area
C      4126      Comment area
6      4128      Comment area
6      4133      
6      4138      Comment area
6      4140      Comment area
6      4141      Comment area
C      4148      Comment area
6      4164      Comment area
6      4174      Comment area
6      4175      Comment area
6      4177      Comment area
none      4178      Comment area
6      4179      Comment area
C      4180      Comment area
6      4182      Comment area
P      4183      Comment area
6      4196      Comment area
C      4200      Comment area
C      4201      Comment area
6      4210      Comment area
6      4211      Comment area
none      4212      Comment area
6      4213      Comment area
6      4215      Comment area
6      4226      Comment area
P      4227      Comment area
P      4228      Comment area
P      4234      Comment area
P      4235      Comment area
6      4237      Comment area
6      4238      Comment area
C      4243      Comment area
6      4248      Comment area
C      4252      Comment area
D      4253      Comment area
6      4258      Comment area
C      4263      Comment area
C      4271      Comment area
none      4274      Comment area
none      4275      Comment area
6      4280      Comment area
C      4301      Comment area
6      4282      
6      4297      Comment area
none      4298      
none      4308      Comment area


The next two records would
0
 
LVL 62

Expert Comment

by:Fernando Soto
ID: 16904295
Hi VBBRett;

Yes you are trying to parse the input of the file. Try changing the MoveIt Sub to look something like this. I added error checking so that the input is not accessed outside its range. You will need to change the code in the If statement to fit your needs. I changes the For loop to a more OOP's way of doing this.

    Sub MoveIt(ByVal inpStartLoc As Integer, ByVal outLength As Integer, _
        ByRef buildString As String)

        Dim intFrom As Integer = inpStartLoc - 1
        Dim intTo As Integer = outLength

        If intFrom < 0 Or (intFrom + intTo) > strInput.Length Then
           ' Do what ever you need to do if the line does not have the right number of characters you wanted
           MessageBox.Show("Index is outside the valid range of the array")
            Return
        End If

        buildString = strInput.Substring(intFrom, intTo)

    End Sub


Fernando
0
 

Author Comment

by:VBBRett
ID: 16905461
Thanks Fernando.  It appears that I have to do something here.  The program runs as an executable, but when I include the form, it does not work.  I think I have to write this thing over to be honest with you.  It's a complete mess.  
0
 
LVL 62

Accepted Solution

by:
Fernando Soto earned 500 total points
ID: 16905965
Hi VBBRett;

Well the Module2 code looks like a Console application and no where in that code do you tranfer control to the forms message loop and so the frmNIP will never start. If the project was created as a Windows form and you added the module2 and started the application then the form would start but the Module2 code will never execute because the form does not create a class of modulke2.

Fernando
0
 

Author Comment

by:VBBRett
ID: 16906354
You are right Fernando.  Is it a better idea for me to start over and just write it as an object oriented programmed class?  I was thinking that way it would work so much better.
0
 
LVL 62

Expert Comment

by:Fernando Soto
ID: 16906533
I would design it around the form create a class for parsing the files with its functions keeping the interface for controlling the application. I may take a little longer but in the long run for program maintenance point of view it will be better. The parsing of the lines can be done more efficiently by making one call to the function and not multiple calls once for each field. But that is what I would do if I was handed something like that but not that my way is what the boss wants.
0
 

Author Comment

by:VBBRett
ID: 16906830
Would you be able to help me with that?  I am going to be working on it tonight.
0
 
LVL 62

Expert Comment

by:Fernando Soto
ID: 16906867
No problem, I will be away from my system for a little while but will be checking in.
0
 

Author Comment

by:VBBRett
ID: 16908076
Hi Fernando, I was curious how would you put together a class in order to organize this program?
0
 
LVL 62

Expert Comment

by:Fernando Soto
ID: 16908309
Something like this:

Add a new class :

1.      In the New Sub initialize the class variables and the stream readers.

2.      Create functions for reading the input files into memory and parsing the data. On function for each file.

3.      Create the MoveIt subroutine.

4.      Create the FormatIt function

5.      Create the ConvertToEBCDIC function

Basically turn the Module2 into a class. Then in the Form

Create an instance of the class Parse and call the functions and subroutine as needed.

0
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 

Author Comment

by:VBBRett
ID: 16908334
OK, I'm going to get started on that right now.  I will post what I have in a little bit.  My fingers are crossed :-).  I really appreciate your help Fernando.
0
 
LVL 62

Expert Comment

by:Fernando Soto
ID: 16908345
No problem
0
 

Author Comment

by:VBBRett
ID: 16908673
I'm curious, what does lastindexof do in vb.net?
0
 
LVL 62

Expert Comment

by:Fernando Soto
ID: 16908788
In an Array, Array.LastIndexOf(Array, Object)
Returns the index of the array where the Object is found for the last time.
Dim ar() As String = {“1”, “2”, “1”, “3”, “1”}
Dim idx As Integer = Array.LastIndexOf( ar, “1”)
idx = to the value of 4

In a String, String.LastIndexOf( String )
Returns the zero base index of the location within the string that the value is found.
Dim str As String = “This is a TesT”
Dim idx As Integer = str.LastIndexOf(“T”)
idx is equal to the value of 13
 
0
 

Author Comment

by:VBBRett
ID: 16908867
How do you call subs into your program that were left in a class?
0
 
LVL 62

Expert Comment

by:Fernando Soto
ID: 16908898
Lets say you have a form Form1 with a button click event something like this

Public Class Form1

    Dim myClass As New Foo

    Private Sub Button1_Click(ByVal sender As Object, ByVal e As Arg)
        myClass.Bar()  ' This calls Sub Bar in Class Foo
    End Sub

End Class

Public Class Foo

    Public Sub Bar( )
        MessageBox.Show("This is Bar in Class Foo")
    End Sub

End Class

I will be leaving now. If you have any other question I will get to them in the mornning. Good Night.

Fernando
0
 

Author Comment

by:VBBRett
ID: 16908931
Thanks Fernando.  Have a good night.
0
 

Author Comment

by:VBBRett
ID: 16930502
Moderator,

Why did you edit this IndexOutofRangeException was unhandled comment section and delete some of the posts for this particular question?  I needed to look at every single comment so I can refer back to what I was doing.  Please add back all the comments that were previously here.  Thank you!
0
 
LVL 62

Expert Comment

by:Fernando Soto
ID: 16930614
Hi VBBRett;

I do not think any Moderator removed any comments from this thread. But if you are missing something ask and I will try to answer, without breaking the rules, LOL.

Fernando
0
 

Author Comment

by:VBBRett
ID: 16930883
Hi Fernando,
Perhaps I was asking the wrong questions, but I took  Module and tried to apply it to a form..which still does not work.  Could I take the following Module, add the code to a form class..pass the values from the form to be added to the module functions for everything to work?  Here is the code in the module that I tried to break up into a class, but I am still at a loss.  Could I take string1 from textbox1(which contains the filepath to be passed as cmdArgs(0)), take string2 from textbox2(which contains the filepath to be passed as cmdArgs(1)), and take the filepath of textbox3(which contains the filepath to be passed as cmdArgs(2)), pass them all to Function Main and get everything to work?

The following is the module I am talking about.  Of course I would probably change the name of the Function Name Main to something else right?

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
0
 
LVL 62

Expert Comment

by:Fernando Soto
ID: 16931056
To your question:
"Perhaps I was asking the wrong questions, but I took  Module and tried to apply it to a form..which still does not work.  Could I take the following Module, add the code to a form class..pass the values from the form to be added to the module functions for everything to work?"

You say that the module works as a console program and you want to use that module in your forms application. This is what I would do then.

1. I would change the name of the function Main in the module to something else so that no one maintaining the code will get confused thinking it is a console program.

2. Create the form as needed.

3. When you want to execute the code in the module as you did as a executable pass the needed parameters in an array.

For example when you ran the program as an executable on the command line you typed in something like this

    Extensis401K file114.txt file385.txt pruout.txt

In step 1 I said to change the name of the main function to something else, let’s say you named it Extensis401K. Now when you are ready to execute the module then do it like this:

    ' Set up parameters for the function
    Dim prams() As String = { TextBox1.Text, TextBox2.Text, TextBox3.Text }
    ' Call the function
    Extensis401K( prams )

When you come back from the function call you are done.
0
 

Author Comment

by:VBBRett
ID: 16931144
Where would I set up parameters for the function and when I tried to do it the way you displayed, I got an error.  Sorry for all the questions, but I never took a console application and tried to convert it to a Windows app.
0
 
LVL 62

Expert Comment

by:Fernando Soto
ID: 16931260
In the form the user enters the data into TextBox1, TextBox2, and TextBox3. At some point the user will click  a button to process the data. When the user click the button but befor the call to the function set up the parameters as outined in the above post. Then make the call.
0
 

Author Comment

by:VBBRett
ID: 16931491
I did that. Before I can even fully test my program, the form froze up on me.  When I pressed the button to open up the filedialog for textbox1, the whole program froze on me.  why would it do something like that?  Any way to fix it?
0
 
LVL 62

Expert Comment

by:Fernando Soto
ID: 16931554
Depending on how much data the module is processing the form may seem to be able to do anything. The system is handleing other events. If you want to have the form do other things while the module is processing data then you will have to do Thread programming so that the module would be executing in one thread and the form in another.

If the module executes as a console program without any problem then doing what I have instructed should also work.
0
 

Author Comment

by:VBBRett
ID: 16931605
Now I have an ArgumentOutofRangeException was Unhandled at this line...this is driving me insane.

            strOutput &= strWorkField.Substring(strWorkField.Length = 6, 6)
0
 
LVL 62

Expert Comment

by:Fernando Soto
ID: 16934462
Looking at this line of code closely you will get that error in one condition and that condition is when strWorkField.Length is equal to the length of 6. Now why is that? The reason is that the Length property is a Read Only property so when you say, strWorkField.Length = 6, the result is a Boolean operation. So when the string strWorkField is not equal to 6 then the value that Substring uses to begin is 0 or the boolean False. In other words it takes the first 6 characters of the string and returns it. Now when the Length of strWorkField is 6 the value is -1 or True Boolean. The index -1 is outside the range of characters which in this case would be 0 through 5.

strOutput &= strWorkField.Substring(strWorkField.Length = 6, 6)
0
 

Author Comment

by:VBBRett
ID: 16934488
Hi Fernando,

It appears the this line should have been strOutput &= strWorkField.Substring(strWorkField.Length - 6, 6) am I correct?  It works now.  LOL!
0
 
LVL 62

Expert Comment

by:Fernando Soto
ID: 16934544
If the objective is to peel off the last 6 characters of the string strWorkField no matter how long it is then you are correct otherwise maybe not. It is impossible to say without seeing the algorithm used to construct this part of the code.
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
This video discusses moving either the default database or any database to a new volume.
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now