Hello,
I'm not sure where else to turn, though my code works, there are some issues that I don't comprehend.
First, my assignment was to:
Read a file, from the keyboard, of employees First Name, Last Name, and Salary. The first record indicates how many records follow. Store the data in array data structure(s). Once all of the records are input, sort and display the records in ascending order by salary to the console.
---------------------
So my first attempt to do this worked fairly well. I have no errors, but my print out (or output to console) is disjointed. I'd like to have the columns displayed next to each other, but we've never been taught how to do that.
Aside from that, the other issue is that I felt as if I cheated. I made my code specifically to solve the problem, so I tried to write the code again. This time my first input would determine the row cycles, sort cycles and so forth. I couldn't figure out how to create an array size based on input, but that wasn't required so I let that slide.
My 2nd time through worked but I have a list of exceptions. I have no clue why it works with all these exceptions, or why the first one doesn't have ANY exceptions. I know I'm new at this whole thing, but I'm trying to learn even if it means doing my assignment again and again!
First Code without exceptions:
Module Module1
Dim sarray(4, 2)
Dim Fname As String
Dim Lname As String
Dim Salary As Integer
Dim Record As Integer
Dim Col As Single
Dim Row As Single
Dim High As Single
Dim Cycles As Single
Dim HFname As String
Dim HLname As String
Dim TotRow As Single
Dim TotCol As Single
Sub Main()
Console.Write("Enter number of files to process: ")
Record = Console.ReadLine()
Cycles = Record
Row = 0
Do While Row <= 4
Console.Write("Enter First Name: ")
Fname = Console.ReadLine()
Console.Write("Enter Last Name: ")
Lname = Console.ReadLine()
Console.Write("Enter Salary: ")
Salary = Console.ReadLine()
Call Input()
Call RowStep()
Loop
Call Sort()
Call Output()
Console.ReadLine()
End Sub
Sub Input()
sarray(Row, 0) = Fname
sarray(Row, 1) = Lname
sarray(Row, 2) = Salary
End Sub
Sub RowStep()
Row = Row + 1
End Sub
Sub Sort()
Do While Cycles > 0
Row = 4
Do While Row > 0
HFname = sarray(Row, 0)
HLname = sarray(Row, 1)
High = sarray(Row, 2)
Row = Row - 1
If sarray(Row, 2) > High Then
sarray((Row + 1), 0) = sarray(Row, 0)
sarray((Row + 1), 1) = sarray(Row, 1)
sarray((Row + 1), 2) = sarray(Row, 2)
sarray(Row, 0) = HFname
sarray(Row, 1) = HLname
sarray(Row, 2) = High
Else
End If
Loop
Cycles = Cycles - 1
Loop
End Sub
Sub Output()
Console.WriteLine()
Console.WriteLine()
Col = 0
Do While Col <= 2
Row = 0
Do While Row <= 4
Console.WriteLine((sarray(Row, Col)))
Row = Row + 1
Loop
Col = Col + 1
Loop
End Sub
End Module
Second Code With Exceptions (yet working):
Module Module1
Dim sarray(4, 2)
Dim Fname As String
Dim Lname As String
Dim Salary As Decimal
Dim Record As Decimal
Dim Row As Decimal
Dim High As Decimal
Dim SortCycle As Decimal
Dim SortOut As Decimal
Dim HFname As String
Dim HLname As String
Dim TotRow As Decimal
Sub Main()
Console.Write("Enter number of files to process: ")
Record = Console.ReadLine()
SortCycle = Record
SortOut = Record
TotRow = Record - 1
Row = TotRow
Do While Row >= 0
Console.Write("Enter First Name: ")
Fname = Console.ReadLine()
Console.Write("Enter Last Name: ")
Lname = Console.ReadLine()
Console.Write("Enter Salary: ")
Salary = Console.ReadLine()
Call Input()
Call RowStep()
Loop
Call Sort()
Call Output()
Console.ReadLine()
End Sub
Sub Input()
sarray(Row, 0) = Fname
sarray(Row, 1) = Lname
sarray(Row, 2) = Salary
End Sub
Sub RowStep()
Row = Row - 1
End Sub
Sub Sort()
Do While SortCycle > 0
Row = TotRow
Do While Row > 0
HFname = sarray(Row, 0)
HLname = sarray(Row, 1)
High = sarray(Row, 2)
Row = Row - 1
If sarray(Row, 2) > High Then
sarray((Row + 1), 0) = sarray(Row, 0)
sarray((Row + 1), 1) = sarray(Row, 1)
sarray((Row + 1), 2) = sarray(Row, 2)
sarray(Row, 0) = HFname
sarray(Row, 1) = HLname
sarray(Row, 2) = High
Else
End If
Loop
SortCycle = SortCycle - 1
Loop
End Sub
Sub Output()
Console.WriteLine()
Console.WriteLine()
Row = 0
Do While Row < SortOut
Console.WriteLine((sarray(Row, 0)))
Console.WriteLine((sarray(Row, 1)))
Console.WriteLine((sarray(Row, 2)))
Row = Row + 1
Loop
End Sub
End Module
I'm not sure where else to turn, though my code works, there are some issues that I don't comprehend.
First, my assignment was to:
Read a file, from the keyboard, of employees First Name, Last Name, and Salary. The first record indicates how many records follow. Store the data in array data structure(s). Once all of the records are input, sort and display the records in ascending order by salary to the console.
---------------------
So my first attempt to do this worked fairly well. I have no errors, but my print out (or output to console) is disjointed. I'd like to have the columns displayed next to each other, but we've never been taught how to do that.
Aside from that, the other issue is that I felt as if I cheated. I made my code specifically to solve the problem, so I tried to write the code again. This time my first input would determine the row cycles, sort cycles and so forth. I couldn't figure out how to create an array size based on input, but that wasn't required so I let that slide.
My 2nd time through worked but I have a list of exceptions. I have no clue why it works with all these exceptions, or why the first one doesn't have ANY exceptions. I know I'm new at this whole thing, but I'm trying to learn even if it means doing my assignment again and again!
First Code without exceptions:
Module Module1
Dim sarray(4, 2)
Dim Fname As String
Dim Lname As String
Dim Salary As Integer
Dim Record As Integer
Dim Col As Single
Dim Row As Single
Dim High As Single
Dim Cycles As Single
Dim HFname As String
Dim HLname As String
Dim TotRow As Single
Dim TotCol As Single
Sub Main()
Console.Write("Enter number of files to process: ")
Record = Console.ReadLine()
Cycles = Record
Row = 0
Do While Row <= 4
Console.Write("Enter First Name: ")
Fname = Console.ReadLine()
Console.Write("Enter Last Name: ")
Lname = Console.ReadLine()
Console.Write("Enter Salary: ")
Salary = Console.ReadLine()
Call Input()
Call RowStep()
Loop
Call Sort()
Call Output()
Console.ReadLine()
End Sub
Sub Input()
sarray(Row, 0) = Fname
sarray(Row, 1) = Lname
sarray(Row, 2) = Salary
End Sub
Sub RowStep()
Row = Row + 1
End Sub
Sub Sort()
Do While Cycles > 0
Row = 4
Do While Row > 0
HFname = sarray(Row, 0)
HLname = sarray(Row, 1)
High = sarray(Row, 2)
Row = Row - 1
If sarray(Row, 2) > High Then
sarray((Row + 1), 0) = sarray(Row, 0)
sarray((Row + 1), 1) = sarray(Row, 1)
sarray((Row + 1), 2) = sarray(Row, 2)
sarray(Row, 0) = HFname
sarray(Row, 1) = HLname
sarray(Row, 2) = High
Else
End If
Loop
Cycles = Cycles - 1
Loop
End Sub
Sub Output()
Console.WriteLine()
Console.WriteLine()
Col = 0
Do While Col <= 2
Row = 0
Do While Row <= 4
Console.WriteLine((sarray(Row, Col)))
Row = Row + 1
Loop
Col = Col + 1
Loop
End Sub
End Module
Second Code With Exceptions (yet working):
Module Module1
Dim sarray(4, 2)
Dim Fname As String
Dim Lname As String
Dim Salary As Decimal
Dim Record As Decimal
Dim Row As Decimal
Dim High As Decimal
Dim SortCycle As Decimal
Dim SortOut As Decimal
Dim HFname As String
Dim HLname As String
Dim TotRow As Decimal
Sub Main()
Console.Write("Enter number of files to process: ")
Record = Console.ReadLine()
SortCycle = Record
SortOut = Record
TotRow = Record - 1
Row = TotRow
Do While Row >= 0
Console.Write("Enter First Name: ")
Fname = Console.ReadLine()
Console.Write("Enter Last Name: ")
Lname = Console.ReadLine()
Console.Write("Enter Salary: ")
Salary = Console.ReadLine()
Call Input()
Call RowStep()
Loop
Call Sort()
Call Output()
Console.ReadLine()
End Sub
Sub Input()
sarray(Row, 0) = Fname
sarray(Row, 1) = Lname
sarray(Row, 2) = Salary
End Sub
Sub RowStep()
Row = Row - 1
End Sub
Sub Sort()
Do While SortCycle > 0
Row = TotRow
Do While Row > 0
HFname = sarray(Row, 0)
HLname = sarray(Row, 1)
High = sarray(Row, 2)
Row = Row - 1
If sarray(Row, 2) > High Then
sarray((Row + 1), 0) = sarray(Row, 0)
sarray((Row + 1), 1) = sarray(Row, 1)
sarray((Row + 1), 2) = sarray(Row, 2)
sarray(Row, 0) = HFname
sarray(Row, 1) = HLname
sarray(Row, 2) = High
Else
End If
Loop
SortCycle = SortCycle - 1
Loop
End Sub
Sub Output()
Console.WriteLine()
Console.WriteLine()
Row = 0
Do While Row < SortOut
Console.WriteLine((sarray(Row, 0)))
Console.WriteLine((sarray(Row, 1)))
Console.WriteLine((sarray(Row, 2)))
Row = Row + 1
Loop
End Sub
End Module