|
www.hitmill.com
|
|
|
The following tutorial (code sample) was written using the Visual Basic 6.0 IDE
(Integrated Development Environment).
|
![]()
The ampersand in the caption serves to make a letter of the command button caption underlined on the button. The button is then accessible by using a keyboard combination of ALT + the underlined letter. Alt + X would unload the form and exit this single-document interface (SDI) program. Directions (continued) When continuing to build the above user interface, name the list box lstBox. (Very original name, yeh?) The name begins with the letter "l", not the numeral one. lst is the Hungarian notation prefix for a list box. When you first build the list box you may see the name of the list box inside the box. Just ignore it. It will not appear in the run mode. Name the form frmMain.The CAPTION property of the form is Display and List. Now you are ready to copy to paste the code, below: |
|
|
Option Explicit
' *********************************************** ' This program includes Boolean variable, ' Message box, List box (AddItem, RemoveItem, ' Clear every other item, Clear List Box), ' Form (Print, clear form background) ' Unload Form (Unload Me), not End. ' Copyright The HiTMilL /October 14, 1999/vb6 ' *********************************************** Private blnDisplayed As Boolean 'Default value is false; ' This is the display-check variable, as boolean Dim Entry, I, Msg 'Declare variables Private Sub cmdClear_Click() If blnDisplayed Then ' if there is a display on the form background frmMain.Cls ' clear form background blnDisplayed = False 'resets the display-check variable to false End If End Sub Private Sub cmdClearHalf_Click() Msg = "Choose OK to remove every other entry." MsgBox Msg ' Display message. For I = 1 To 50 ' There will be 50 items removed, index renews itself lstBox.RemoveItem I ' removes every other Next I ' item. End Sub Private Sub cmdClearRemainder_Click() Msg = "Choose OK to remove all items from the list box." MsgBox Msg ' Display message. lstBox.Clear ' Clear list box. End Sub Private Sub cmdDisplay_Click() If Not blnDisplayed Then '(if blnDisplayed is still false, then..) frmMain.Print "Eat at Joe's" frmMain.Print "Eat at Paul's" frmMain.Print "Eat at Mike's" frmMain.Print "Eat at Mollie's" frmMain.Print "Eat at Steven's" frmMain.Print "Eat at DinkyDoo's" frmMain.Print "Eat at Stephanie's" blnDisplayed = True 'sets the display-check variable to true End If End Sub Private Sub cmdExit_Click() Unload Me End Sub Private Sub cmdShowList_Click() Msg = "Choose OK to add 100 items to your list box." MsgBox Msg ' Display message. For I = 1 To 100 ' Count from 1 to 100. Entry = "Entry " & I ' Create entry. lstBox.AddItem Entry ' Add the entry. Next I End Sub |