- #1
Calculus!
- 20
- 0
Hey. This is what I have to do:
Fix the IF conditions inside the DO loop to handle ALL possible combinations of first name and last name searches (it is missing at least one right now) and see if you can make the code more efficient.
Dim searchFname As String, searchLname As String
Type Employee
Fname As String
Lname As String
Manager As String
Office As String
Phone As String
Hired As String
Salary As Single
End Type
Dim inEmp As Employee
Dim fuzzyFirst As Boolean, fuzzyLast As Boolean
Dim found As Boolean
fuzzyFirst = False
fuzzyLast = False
found = False
FileOpen(1, "Employee")
'Get data
If txtFname.Text = "" And txtLname.Text = "" Then
MsgBox ("Please provide search criteria")
Else
If txtFname.Text <> "" Then searchFname = txtFname.Text
If txtLname.Text <> "" Then searchLname = txtLname.Text
'Determine if fuzzy search
If InStr(searchFname, "*") > 0 Then
fuzzyFirst = True
'Reset search name
If Left(searchFname, 1) = "*" Then searchFname = Mid(searchFname, 2)
If Right(searchFname, 1) = "*" Then searchFname = Left(searchFname, Len(searchFname) - 1)
End If
If InStr(searchLname, "*") > 0 Then
fuzzyLast = True
'Reset search name
If Left(searchLname, 1) = "*" Then searchLname = Mid(searchLname, 2)
If Right(searchLname, 1) = "*" Then searchLname = Left(searchLname, Len(searchLname) - 1)
End If
'Loop through file
Do Until (EOF(1) Or found = True)
FileGet(1, inEmp)
'search first name
If fuzzyFirst Then
If InStr(inEmp.Fname, searchFname) > 0 Then found = True
Else
If inEmp.Fname = searchFname Then found = True
End If
'Check last name
If found And searchLname <> "" Then
If fuzzyLast Then
If InStr(inEmp.Lname, searchLname) = 0 Then found = False
Else
inEmp.Lname <> searchLname then found = False
End If
End If
If found = False Then
'check last name
If fuzzyLast Then
If InStr(inEmp.Lname, searchLname) > 0 Then found = True
Else
inEmp.Lname = searchLname then found = true
End If
End If
Loop
If found Then
'Set output text boxes
txtManager.Text = inEmp.Manager
txtDOH.Text = inEmp.Hired
txtSalary.Text = FormatCurrency(inEmp.Salary)
Else
MsgBox("There are no employees with that name")
End If
End If
Me.Refresh()
End If
FileClose(1)
Fix the IF conditions inside the DO loop to handle ALL possible combinations of first name and last name searches (it is missing at least one right now) and see if you can make the code more efficient.
Dim searchFname As String, searchLname As String
Type Employee
Fname As String
Lname As String
Manager As String
Office As String
Phone As String
Hired As String
Salary As Single
End Type
Dim inEmp As Employee
Dim fuzzyFirst As Boolean, fuzzyLast As Boolean
Dim found As Boolean
fuzzyFirst = False
fuzzyLast = False
found = False
FileOpen(1, "Employee")
'Get data
If txtFname.Text = "" And txtLname.Text = "" Then
MsgBox ("Please provide search criteria")
Else
If txtFname.Text <> "" Then searchFname = txtFname.Text
If txtLname.Text <> "" Then searchLname = txtLname.Text
'Determine if fuzzy search
If InStr(searchFname, "*") > 0 Then
fuzzyFirst = True
'Reset search name
If Left(searchFname, 1) = "*" Then searchFname = Mid(searchFname, 2)
If Right(searchFname, 1) = "*" Then searchFname = Left(searchFname, Len(searchFname) - 1)
End If
If InStr(searchLname, "*") > 0 Then
fuzzyLast = True
'Reset search name
If Left(searchLname, 1) = "*" Then searchLname = Mid(searchLname, 2)
If Right(searchLname, 1) = "*" Then searchLname = Left(searchLname, Len(searchLname) - 1)
End If
'Loop through file
Do Until (EOF(1) Or found = True)
FileGet(1, inEmp)
'search first name
If fuzzyFirst Then
If InStr(inEmp.Fname, searchFname) > 0 Then found = True
Else
If inEmp.Fname = searchFname Then found = True
End If
'Check last name
If found And searchLname <> "" Then
If fuzzyLast Then
If InStr(inEmp.Lname, searchLname) = 0 Then found = False
Else
inEmp.Lname <> searchLname then found = False
End If
End If
If found = False Then
'check last name
If fuzzyLast Then
If InStr(inEmp.Lname, searchLname) > 0 Then found = True
Else
inEmp.Lname = searchLname then found = true
End If
End If
Loop
If found Then
'Set output text boxes
txtManager.Text = inEmp.Manager
txtDOH.Text = inEmp.Hired
txtSalary.Text = FormatCurrency(inEmp.Salary)
Else
MsgBox("There are no employees with that name")
End If
End If
Me.Refresh()
End If
FileClose(1)