home *** CD-ROM | disk | FTP | other *** search
- Type ListBoxMasterForm From SampleMasterForm
- Dim Label1 As New Label
- Dim lstNames As New ListBox
- Dim txtFirstName As New TextBox
- Dim Label2 As New Label
- Dim btnDelete As New Button
- Dim btnChange As New Button
- Dim btnReset As New Button
- Dim lblTotal As New Label
- Dim lblFriendMessage As New Label
- Dim btnInsert As New Button
- Dim Label3 As New Label
- Dim chkSorted As New CheckBox
- Dim txtLastName As New TextBox
- Dim btnAppend As New Button
- Dim Label4 As New Label
- Dim Label5 As New Label
-
- ' METHODS for object: ListBoxMasterForm
- Sub btnAppend_Click()
- If txtFirstName.Text = "" Or txtLastName.Text = "" Then
- InfoBox.Message("", "Name information is incomplete.")
- Else
- ' GetName function makes sure we only get the first token in each box
- lstNames.AddItem(GetName(txtFirstName.Text) & " " & GetName(txtLastName.Text))
- txtFirstName.Text = ""
- txtLastName.Text = ""
- txtFirstName.SetFocus
- UpdateTotals
- End If
- End Sub
-
- Sub btnChange_Click()
- Dim first_name As String
- Dim last_name As String
- Dim list_entry As String
-
- list_entry = lstNames.Text
-
- ' parse the list entry to get the first and last names
- ' format for GetToken <string> <token> <separator>
- first_name = GetToken(list_entry, 1, " ")
- last_name = GetToken(list_entry, 2, " ")
-
- ' copy the first and last names into the edit boxes
- txtFirstName.Text = first_name
- txtLastName.Text = last_name
-
- ' Remove the current list entry
- btnDelete_Click
-
- ' Select the first name
- txtFirstName.SetFocus
- txtFirstName.SelStart = 0
- txtFirstName.SelLength = Len(txtFirstName.Text)
- End Sub
-
- Sub btnDelete_Click()
- lstNames.RemoveItem(lstNames.ListIndex)
- UpdateTotals
- End Sub
-
- Sub btnInsert_Click()
- Dim name_entry As String
-
- If txtFirstName.Text = "" Or txtLastName.Text = "" Then
- InfoBox.Message("", "Name information is incomplete.")
- ElseIf lstNames.ListIndex = -1 Then
- InfoBox.Message("", "No name entry selected in list.")
- Else
- name_entry = GetName(txtFirstName.Text) & " " & GetName(txtLastName.Text)
- lstNames.InsertItem(name_entry, lstNames.ListIndex)
- txtFirstName.Text = ""
- txtLastName.Text = ""
- UpdateTotals
- End If
- End Sub
-
- Sub btnReset_Click()
- lstNames.Clear
- txtFirstName.Text = ""
- txtLastName.Text = ""
- UpdateTotals
- End Sub
-
- Sub chkSorted_Click()
- If chkSorted.Value = 0 Then
- lstNames.Sorted = False
- Else
- lstNames.Sorted = True
- End If
-
- lstNames.Refresh
- End Sub
-
- Function GetName (name_entry As String) As String
- Dim entry As String
- Dim found_blank As Integer
-
- ' Get what ever the user keys into the first/last name textbox
- ' and return only the first word in each box
- ' If the name_entry is empty, don't bother exit fast
- If Len(name_entry) = 0 Then
- GetName = ""
- Exit Function
- End If
-
- ' Since a blank space is our default separator, we add one so we know we have one
- ' And strip off any leading or trailing spaces
- entry = Trim(name_entry) & " "
-
- ' Find the first blank space
- found_blank = Instr(0, entry, " ")
-
- ' Return the first word
- GetName = Left(entry, found_blank - 1)
-
- End Function
-
- Function GetToken(string_entry As String, token_count As Integer, separator As String) As String
- ' This function accepts a string and a token count value and returns the token string
- ' A string separator is also passed
- Dim counter As Integer
- Dim found As Integer
- Dim foundpos As Integer
- Dim startpos As Integer
-
- found = 0
- counter = 0
- startpos = 1
-
- ' Add a separator to the end of the passed string
- string_entry = string_entry & separator
-
- Do Until found = 1
- counter = counter + 1
- foundpos = Instr(startpos, string_entry, separator)
- If counter = token_count Then
- GetToken = Mid(string_entry, startpos, foundpos - startpos)
- found = 1
- Else
- startpos = foundpos + 1
- End If
- Loop
-
- End Function
-
- Sub ResetApplication_Click ()
-
- ' Initialize the Listbox demo form
- txtFirstName.Text = ""
- txtLastName.Text = ""
- txtFirstName.SetFocus
-
- lstNames.Clear
- lblTotal.Caption = ""
- lblFriendMessage.Caption = ""
-
- ' Set the sorted property
- chkSorted.Value = 1
- lstNames.Sorted = True
-
- End Sub
-
- Sub UpdateTotals()
- ' When ever the listbox changes, update the friends
- ' message and total label
- lblTotal.Caption = lstNames.ListCount
- If lstNames.ListCount > 6 Then
- lblFriendMessage.Caption = "You sure have a lot of friends!"
- Else
- lblFriendMessage.Caption = ""
- End If
- txtFirstName.SetFocus
- End Sub
-
- End Type
-
- Begin Code
- ' Reconstruction commands for object: ListBoxMasterForm
- '
- With ListBoxMasterForm
- .Caption := "ListBox Demonstration"
- .Move(4035, 1200, 6330, 5280)
- .DefaultButton := ListBoxMasterForm.btnAppend
- .SampleDir := "C:\ENVELOP\bootcamp\basic\listbox\"
- .SampleName := "LISTBOX"
- With .Label1
- .Caption := "Key in names of some of your friends."
- .ForeColor := 13107200
- .ZOrder := 1
- .Move(300, 300, 4050, 300)
- End With 'ListBoxMasterForm.Label1
- With .lstNames
- .Caption := "lstNames"
- .ZOrder := 2
- .Move(120, 1875, 4740, 1470)
- .TabStop := False
- End With 'ListBoxMasterForm.lstNames
- With .txtFirstName
- .ZOrder := 3
- .Move(300, 1050, 2100, 360)
- End With 'ListBoxMasterForm.txtFirstName
- With .Label2
- .Caption := "Total Friends:"
- .ZOrder := 4
- .Move(2250, 3660, 1500, 300)
- .Alignment := "Right"
- End With 'ListBoxMasterForm.Label2
- With .btnDelete
- .Caption := "&Delete"
- .ZOrder := 5
- .Move(4950, 900, 1050, 450)
- .TabStop := False
- End With 'ListBoxMasterForm.btnDelete
- With .btnChange
- .Caption := "&Change"
- .ZOrder := 6
- .Move(4950, 1500, 1050, 450)
- .TabStop := False
- End With 'ListBoxMasterForm.btnChange
- With .btnReset
- .Caption := "&Reset"
- .ZOrder := 7
- .Move(4950, 2700, 1050, 450)
- .TabStop := False
- End With 'ListBoxMasterForm.btnReset
- With .lblTotal
- .Caption := "0"
- .BackColor := 16777215
- .ZOrder := 8
- .Move(3900, 3600, 600, 360)
- .BorderStyle := "Fixed Single"
- .Alignment := "Center"
- End With 'ListBoxMasterForm.lblTotal
- With .lblFriendMessage
- .ForeColor := 13107200
- .ZOrder := 9
- .Move(300, 4050, 5700, 360)
- End With 'ListBoxMasterForm.lblFriendMessage
- With .btnInsert
- .Caption := "&Insert"
- .ZOrder := 10
- .Move(4950, 2100, 1050, 450)
- .TabStop := False
- End With 'ListBoxMasterForm.btnInsert
- With .Label3
- .Caption := "List of Friends:"
- .ZOrder := 11
- .Move(300, 1560, 1500, 240)
- End With 'ListBoxMasterForm.Label3
- With .chkSorted
- .Caption := "Sort list"
- .ZOrder := 12
- .Move(600, 3600, 1305, 315)
- .TabStop := False
- .Value := "Checked"
- End With 'ListBoxMasterForm.chkSorted
- With .txtLastName
- .ZOrder := 13
- .Move(2550, 1050, 2100, 360)
- End With 'ListBoxMasterForm.txtLastName
- With .btnAppend
- .Caption := "Append"
- .ZOrder := 14
- .Move(4950, 300, 1050, 450)
- End With 'ListBoxMasterForm.btnAppend
- With .Label4
- .Caption := "First Name"
- .ZOrder := 15
- .Move(300, 750, 1650, 240)
- End With 'ListBoxMasterForm.Label4
- With .Label5
- .Caption := "Last Name"
- .ZOrder := 16
- .Move(2550, 750, 1500, 240)
- End With 'ListBoxMasterForm.Label5
- With .helpfile
- .FileName := "C:\ENVELOP\bootcamp\basic\listbox\LISTBOX.hlp"
- End With 'ListBoxMasterForm.helpfile
- End With 'ListBoxMasterForm
- End Code
-