home *** CD-ROM | disk | FTP | other *** search
/ The Best of Select: Windows 95 Special 2 / WIN95_2.bin / utils / envelop / envelop.6 / Tools / Bootcamp / basic / listbox / listbox.eto < prev    next >
Encoding:
Text File  |  1996-07-08  |  8.0 KB  |  283 lines

  1. Type ListBoxMasterForm From SampleMasterForm
  2.   Dim Label1 As New Label
  3.   Dim lstNames As New ListBox
  4.   Dim txtFirstName As New TextBox
  5.   Dim Label2 As New Label
  6.   Dim btnDelete As New Button
  7.   Dim btnChange As New Button
  8.   Dim btnReset As New Button
  9.   Dim lblTotal As New Label
  10.   Dim lblFriendMessage As New Label
  11.   Dim btnInsert As New Button
  12.   Dim Label3 As New Label
  13.   Dim chkSorted As New CheckBox
  14.   Dim txtLastName As New TextBox
  15.   Dim btnAppend As New Button
  16.   Dim Label4 As New Label
  17.   Dim Label5 As New Label
  18.  
  19.   ' METHODS for object: ListBoxMasterForm
  20.   Sub btnAppend_Click()
  21.     If txtFirstName.Text = "" Or txtLastName.Text = "" Then 
  22.       InfoBox.Message("", "Name information is incomplete.")
  23.     Else 
  24.       ' GetName function makes sure we only get the first token in each box
  25.       lstNames.AddItem(GetName(txtFirstName.Text) & " " & GetName(txtLastName.Text))
  26.       txtFirstName.Text = ""
  27.       txtLastName.Text = ""
  28.       txtFirstName.SetFocus
  29.       UpdateTotals
  30.     End If
  31.   End Sub
  32.  
  33.   Sub btnChange_Click()
  34.     Dim first_name As String
  35.     Dim last_name As String
  36.     Dim list_entry As String
  37.   
  38.     list_entry = lstNames.Text
  39.   
  40.     ' parse the list entry to get the first and last names
  41.     ' format for GetToken <string> <token> <separator>
  42.     first_name = GetToken(list_entry, 1, " ")
  43.     last_name = GetToken(list_entry, 2, " ")
  44.   
  45.     ' copy the first and last names into the edit boxes
  46.     txtFirstName.Text = first_name
  47.     txtLastName.Text = last_name
  48.   
  49.     ' Remove the current list entry
  50.     btnDelete_Click
  51.   
  52.     ' Select the first name
  53.     txtFirstName.SetFocus
  54.     txtFirstName.SelStart = 0
  55.     txtFirstName.SelLength = Len(txtFirstName.Text)
  56.   End Sub
  57.  
  58.   Sub btnDelete_Click()
  59.     lstNames.RemoveItem(lstNames.ListIndex)
  60.     UpdateTotals
  61.   End Sub
  62.  
  63.   Sub btnInsert_Click()
  64.     Dim name_entry As String
  65.   
  66.     If txtFirstName.Text = "" Or txtLastName.Text = "" Then 
  67.       InfoBox.Message("", "Name information is incomplete.")
  68.     ElseIf lstNames.ListIndex = -1 Then 
  69.       InfoBox.Message("", "No name entry selected in list.")
  70.     Else 
  71.       name_entry = GetName(txtFirstName.Text) & " " & GetName(txtLastName.Text)
  72.       lstNames.InsertItem(name_entry, lstNames.ListIndex)
  73.       txtFirstName.Text = ""
  74.       txtLastName.Text = ""
  75.       UpdateTotals
  76.     End If
  77.   End Sub
  78.  
  79.   Sub btnReset_Click()
  80.     lstNames.Clear
  81.     txtFirstName.Text = ""
  82.     txtLastName.Text = ""
  83.     UpdateTotals
  84.   End Sub
  85.  
  86.   Sub chkSorted_Click()
  87.     If chkSorted.Value = 0 Then 
  88.       lstNames.Sorted = False
  89.     Else 
  90.       lstNames.Sorted = True
  91.     End If
  92.   
  93.     lstNames.Refresh
  94.   End Sub
  95.  
  96.   Function GetName (name_entry As String) As String
  97.     Dim entry As String
  98.     Dim found_blank As Integer
  99.   
  100.     ' Get what ever the user keys into the first/last name textbox
  101.     ' and return only the first word in each box
  102.     ' If the name_entry is empty, don't bother exit fast
  103.     If Len(name_entry) = 0 Then 
  104.       GetName = ""
  105.       Exit Function
  106.     End If
  107.   
  108.     ' Since a blank space is our default separator, we add one so we know we have one
  109.     ' And strip off any leading or trailing spaces
  110.     entry = Trim(name_entry) & " "
  111.   
  112.     ' Find the first blank space
  113.     found_blank = Instr(0, entry, " ")
  114.   
  115.     ' Return the first word
  116.     GetName = Left(entry, found_blank - 1)
  117.   
  118.   End Function
  119.  
  120.   Function GetToken(string_entry As String, token_count As Integer,  separator As String) As String
  121.     ' This function accepts a string and a token count value and returns the token string
  122.     ' A string separator is also passed
  123.     Dim counter As Integer
  124.     Dim found As Integer
  125.     Dim foundpos As Integer
  126.     Dim startpos As Integer
  127.   
  128.     found = 0
  129.     counter = 0
  130.     startpos = 1
  131.   
  132.     ' Add a separator to the end of the passed string
  133.     string_entry = string_entry & separator
  134.   
  135.     Do Until found = 1
  136.       counter = counter + 1
  137.       foundpos = Instr(startpos, string_entry, separator)
  138.       If counter = token_count Then 
  139.         GetToken = Mid(string_entry, startpos, foundpos - startpos)
  140.         found = 1
  141.       Else 
  142.         startpos = foundpos + 1
  143.       End If
  144.     Loop
  145.   
  146.   End Function
  147.  
  148.   Sub ResetApplication_Click ()
  149.   
  150.     ' Initialize the Listbox demo form
  151.     txtFirstName.Text = ""
  152.     txtLastName.Text = ""
  153.     txtFirstName.SetFocus
  154.   
  155.     lstNames.Clear
  156.     lblTotal.Caption = ""
  157.     lblFriendMessage.Caption = ""
  158.   
  159.     ' Set the sorted property
  160.     chkSorted.Value = 1
  161.     lstNames.Sorted = True
  162.   
  163.   End Sub
  164.  
  165.   Sub UpdateTotals()
  166.     ' When ever the listbox changes, update the friends
  167.     ' message and total label
  168.     lblTotal.Caption = lstNames.ListCount
  169.     If lstNames.ListCount > 6 Then 
  170.       lblFriendMessage.Caption = "You sure have a lot of friends!"
  171.     Else 
  172.       lblFriendMessage.Caption = ""
  173.     End If
  174.     txtFirstName.SetFocus
  175.   End Sub
  176.  
  177. End Type
  178.  
  179. Begin Code
  180. ' Reconstruction commands for object: ListBoxMasterForm
  181. '
  182.   With ListBoxMasterForm
  183.     .Caption := "ListBox Demonstration"
  184.     .Move(4035, 1200, 6330, 5280)
  185.     .DefaultButton := ListBoxMasterForm.btnAppend
  186.     .SampleDir := "C:\ENVELOP\bootcamp\basic\listbox\"
  187.     .SampleName := "LISTBOX"
  188.     With .Label1
  189.       .Caption := "Key in names of some of your friends."
  190.       .ForeColor := 13107200
  191.       .ZOrder := 1
  192.       .Move(300, 300, 4050, 300)
  193.     End With  'ListBoxMasterForm.Label1
  194.     With .lstNames
  195.       .Caption := "lstNames"
  196.       .ZOrder := 2
  197.       .Move(120, 1875, 4740, 1470)
  198.       .TabStop := False
  199.     End With  'ListBoxMasterForm.lstNames
  200.     With .txtFirstName
  201.       .ZOrder := 3
  202.       .Move(300, 1050, 2100, 360)
  203.     End With  'ListBoxMasterForm.txtFirstName
  204.     With .Label2
  205.       .Caption := "Total Friends:"
  206.       .ZOrder := 4
  207.       .Move(2250, 3660, 1500, 300)
  208.       .Alignment := "Right"
  209.     End With  'ListBoxMasterForm.Label2
  210.     With .btnDelete
  211.       .Caption := "&Delete"
  212.       .ZOrder := 5
  213.       .Move(4950, 900, 1050, 450)
  214.       .TabStop := False
  215.     End With  'ListBoxMasterForm.btnDelete
  216.     With .btnChange
  217.       .Caption := "&Change"
  218.       .ZOrder := 6
  219.       .Move(4950, 1500, 1050, 450)
  220.       .TabStop := False
  221.     End With  'ListBoxMasterForm.btnChange
  222.     With .btnReset
  223.       .Caption := "&Reset"
  224.       .ZOrder := 7
  225.       .Move(4950, 2700, 1050, 450)
  226.       .TabStop := False
  227.     End With  'ListBoxMasterForm.btnReset
  228.     With .lblTotal
  229.       .Caption := "0"
  230.       .BackColor := 16777215
  231.       .ZOrder := 8
  232.       .Move(3900, 3600, 600, 360)
  233.       .BorderStyle := "Fixed Single"
  234.       .Alignment := "Center"
  235.     End With  'ListBoxMasterForm.lblTotal
  236.     With .lblFriendMessage
  237.       .ForeColor := 13107200
  238.       .ZOrder := 9
  239.       .Move(300, 4050, 5700, 360)
  240.     End With  'ListBoxMasterForm.lblFriendMessage
  241.     With .btnInsert
  242.       .Caption := "&Insert"
  243.       .ZOrder := 10
  244.       .Move(4950, 2100, 1050, 450)
  245.       .TabStop := False
  246.     End With  'ListBoxMasterForm.btnInsert
  247.     With .Label3
  248.       .Caption := "List of Friends:"
  249.       .ZOrder := 11
  250.       .Move(300, 1560, 1500, 240)
  251.     End With  'ListBoxMasterForm.Label3
  252.     With .chkSorted
  253.       .Caption := "Sort list"
  254.       .ZOrder := 12
  255.       .Move(600, 3600, 1305, 315)
  256.       .TabStop := False
  257.       .Value := "Checked"
  258.     End With  'ListBoxMasterForm.chkSorted
  259.     With .txtLastName
  260.       .ZOrder := 13
  261.       .Move(2550, 1050, 2100, 360)
  262.     End With  'ListBoxMasterForm.txtLastName
  263.     With .btnAppend
  264.       .Caption := "Append"
  265.       .ZOrder := 14
  266.       .Move(4950, 300, 1050, 450)
  267.     End With  'ListBoxMasterForm.btnAppend
  268.     With .Label4
  269.       .Caption := "First Name"
  270.       .ZOrder := 15
  271.       .Move(300, 750, 1650, 240)
  272.     End With  'ListBoxMasterForm.Label4
  273.     With .Label5
  274.       .Caption := "Last Name"
  275.       .ZOrder := 16
  276.       .Move(2550, 750, 1500, 240)
  277.     End With  'ListBoxMasterForm.Label5
  278.     With .helpfile
  279.       .FileName := "C:\ENVELOP\bootcamp\basic\listbox\LISTBOX.hlp"
  280.     End With  'ListBoxMasterForm.helpfile
  281.   End With  'ListBoxMasterForm
  282. End Code
  283.