Hey there
I need a little help!!
The following is code I have written for to add names to a list,
display who is on the list and also to search for a name on the list.
I need help with the following :
If all seats(20) are taken then the name is added to a waiting list. if someone wishes to be removed then a search is performed for their name and if found they are deleted from the array and whoever was first in the waiting list takes their place.Anyone any ideas how to do this?
Also how would a implement a parallel array for seat,
ie have two arrays of ten seats?
Apologies for the code taking up so much space but I wasnt sure which bits to leave out.
Hope someone can help!!
Regards,
Noel. VB:
Dim seat(1 To 20) As String
Dim counter As Integer
Private Sub cmdAddName_Click()
If (counter < 20) Then
counter = counter + 1
seat(counter) = UCase(Trim(txtName.Text))
txtName.Text = ""
txtName.SetFocus
Else
MsgBox "Sorry Plane is full", , ""
txtName.Text = " "
cmdDisplaySeat.SetFocus
End If
End Sub
Private Sub cmdDisplaySeat_Click()
Call SortNames
Call ShowNames
End Sub
Private Sub ShowNames()
Dim i As Integer
picSeats.Cls
picSeats.Print
For i = 1 To counter
picSeats.Print seat(i)
If i Mod 2 = 0 Then
picSeats.Print
End If
Next i
End Sub
Private Sub SortNames()
Dim gap As Integer, doneFlag As Boolean
Dim index As Integer, temp As String
gap = Int(counter / 2)
Do While gap >= 1
Do
doneFlag = True
For index = 1 To counter - gap
If seat(index) > seat(index) Then
temp = seat(index)
seat(index) = seat(index + gap)
seat(index + gap) = temp
doneFlag = False
End If
Next index
Loop Until doneFlag = True
gap = Int(gap / 2)
Loop
End Sub
Private Sub BinarySearch(name As String, result As String)
Dim foundFlag As Boolean
Dim first As Integer, middle As Integer, last As Integer
foundFlag = False
first = 1
last = counter
Do While (forst <= last) And (Not foundFlag)
middle = Int((first + last) / 2)
Select Case UCase(seat(middle))
Case name
foundFlag = True
Case Is > name
last = middle - 1
Case Is < name
first = middle + 1
End Select
Loop
If foundFlag Then
result = "is on plane"
Else
result = "is not on plane"
End If
End Sub
Private Sub cmdSearch_Click()
Dim name As String, result As String
name = UCase(Trim(txtName.Text))
Call BinarySearch(name, result)
picSeats.Cls
picSeats.Print name; " "; result
End Sub
I need a little help!!
The following is code I have written for to add names to a list,
display who is on the list and also to search for a name on the list.
I need help with the following :
If all seats(20) are taken then the name is added to a waiting list. if someone wishes to be removed then a search is performed for their name and if found they are deleted from the array and whoever was first in the waiting list takes their place.Anyone any ideas how to do this?
Also how would a implement a parallel array for seat,
ie have two arrays of ten seats?
Apologies for the code taking up so much space but I wasnt sure which bits to leave out.
Hope someone can help!!
Regards,
Noel. VB:
Dim seat(1 To 20) As String
Dim counter As Integer
Private Sub cmdAddName_Click()
If (counter < 20) Then
counter = counter + 1
seat(counter) = UCase(Trim(txtName.Text))
txtName.Text = ""
txtName.SetFocus
Else
MsgBox "Sorry Plane is full", , ""
txtName.Text = " "
cmdDisplaySeat.SetFocus
End If
End Sub
Private Sub cmdDisplaySeat_Click()
Call SortNames
Call ShowNames
End Sub
Private Sub ShowNames()
Dim i As Integer
picSeats.Cls
picSeats.Print
For i = 1 To counter
picSeats.Print seat(i)
If i Mod 2 = 0 Then
picSeats.Print
End If
Next i
End Sub
Private Sub SortNames()
Dim gap As Integer, doneFlag As Boolean
Dim index As Integer, temp As String
gap = Int(counter / 2)
Do While gap >= 1
Do
doneFlag = True
For index = 1 To counter - gap
If seat(index) > seat(index) Then
temp = seat(index)
seat(index) = seat(index + gap)
seat(index + gap) = temp
doneFlag = False
End If
Next index
Loop Until doneFlag = True
gap = Int(gap / 2)
Loop
End Sub
Private Sub BinarySearch(name As String, result As String)
Dim foundFlag As Boolean
Dim first As Integer, middle As Integer, last As Integer
foundFlag = False
first = 1
last = counter
Do While (forst <= last) And (Not foundFlag)
middle = Int((first + last) / 2)
Select Case UCase(seat(middle))
Case name
foundFlag = True
Case Is > name
last = middle - 1
Case Is < name
first = middle + 1
End Select
Loop
If foundFlag Then
result = "is on plane"
Else
result = "is not on plane"
End If
End Sub
Private Sub cmdSearch_Click()
Dim name As String, result As String
name = UCase(Trim(txtName.Text))
Call BinarySearch(name, result)
picSeats.Cls
picSeats.Print name; " "; result
End Sub