SlideShare una empresa de Scribd logo
1 de 12
Descargar para leer sin conexión
VISUAL BASIC 6 – 3 CUBE COMPUTER INSTITUTE (3CCI)


                                             Chapter 7


List Box Control
A list box control displays a list of items from which the user can select one or more.




List boxes present a list of choices to the user. By default, the choices are displayed vertically in
a single column.
If the number of items exceeds what can be displayed in the list box, scroll bars automatically
appear on the control. The user can then scroll up and down, or left to right through the list.


Combo Box Control

A combo box control combines the features of a text box and a list box. This control allows the
user to select an item either by typing text into the combo box, or by selecting it from the list.

Combo boxes present a list of choices to the user. If the number of items exceeds what can be
displayed in the combo box, scroll bars will automatically appear on the control. The user can
then scroll up and down or left to right through the list.

Combo Box Styles
There are three combo box styles. Each style can be set at design time and uses values, or
equivalent Visual Basic constants, to set the style of the combo box.
Style                           Value                           Constant

Drop-down combo box             0                               vbComboDropDown

Simple combo box                1                               vbComboSimple

Drop-down list box              2                               vbComboDropDownList




    1. Drop-down Combo Box
    With the default setting (Style = 0 – Dropdown Combo), a combo box is a drop-down
    combo box. The user can either enter text directly (as in a text box) or click the detached
    arrow at the right of the combo box to open a list of choices. Selecting one of the choices
    inserts it into the text portion at the top of the combo box.




                                                                                                        1
VISUAL BASIC 6 – 3 CUBE COMPUTER INSTITUTE (3CCI)




2. Simple Combo Box
Setting the Style property of a combo box to 1 – Simple Combo specifies a simple combo
box in which the list is displayed at all times. To display all entries in the list, you must draw
the list box large enough to display the entries. A vertical scroll bar is automatically inserted
when there are more entries than can be displayed. The user can still enter text directly or
select from the list. As with a drop-down combo box, a simple combo box also allows users
to enter choices not on the list.




3. Drop-down List Box
A drop-down list box (Style = 2 – Dropdown List) is like a regular list box — it displays a
list of items from which a user must choose. Unlike list boxes, however, the list is not
displayed until you click the arrow to the right of the box. The key difference between this
and a drop-down combo box is that the user can't type into the box, he can only select
an item from the list.




                                                                                                 2
VISUAL BASIC 6 – 3 CUBE COMPUTER INSTITUTE (3CCI)



Adding Items to list Box / Combo Box at Design-Time:
   1. Place the list box/ Combo box in form and choose the list box/ Combo box.
   2. Go to list property of List Box Control/ Combo box Control.
   3. Add 1st item to the list box/ Combo box.
   4. To add 2nd item press Ctrl + Enter.
   5. Repeat 4th step for adding more items to the list.
   6. After Last item is added, don’t press Ctrl + Enter, otherwise at the end of list box/ Combo
      box an empty string will be added.




Adding Items to list Box / Combo Box at Run-Time:
If you want to add item in the list box/ Combo Box during runtime, you have to use the Addtem
method.
General form – Object.AddItem Value [, Index]
Value is the value to add to the list. If the value is a string literal, enclose it in quotation marks.
Index specifies the position in the list where the value must be stored, the first element in the
list box has the Index = 0.

Example: lstName.AddItem “A”
       cboName.AddItem “B”


Clearing The List Box/ Combo Box Items:
To clear items of the list box or a combo box at runtime, use the Clear Method to empty the
combo box and list box.
General form – Object.Clear
Example: lstName.Clear
          cboName.Clear


ListIndex Property

Returns or sets the index of the currently selected item in the control. Not available at design
time.


                                                                                                      3
VISUAL BASIC 6 – 3 CUBE COMPUTER INSTITUTE (3CCI)


When a project is running, the user select an item from the list box/combo box, the index of
that selected item is stored in the ListIndex property.
ListIndex of the first item in the list is 0.
 If no list item is selected then the ListIndex property is set to -1.

Example:
Private Sub cmdOk_Click ()
   MsgBox cboName.ListIndex
End Sub




ListCount Property
The ListCount property of a list box/combo box is used to store the number of items in the list.
ListCount is always one more that the highest ListIndex, since ListIndex starts from 0.

Example:
Private Sub Form_Load()
        Combo1.AddItem "A"
        Combo1.AddItem "B"
        Combo1.AddItem "C"
        Combo1.AddItem "D"
End Sub

Private Sub cmdOk_Click ()
      MsgBox cboName.ListCount
End Sub




List Property
The List Property is used to display a item from the list. The list property of list box/combo box
holds the text of all list elements.
Specify the element by using its Index.
General form –Object.List(Index) [ = Value]

Example:

                                                                                                   4
VISUAL BASIC 6 – 3 CUBE COMPUTER INSTITUTE (3CCI)


Private Sub Command1_Click()
        MsgBox Combo1.List(Combo1.ListIndex)            ‘gets the current selected item
End Sub




RemoveItem Property
The RemoveItem Property is used to remove a single element from the list.
General form – Object.RemoveItem Index.

The index is required as it specifies which item is to be removed.

Example:
Private Sub Command1_Click()
        Combo1.RemoveItem Combo1.ListIndex              ‘removes the current selected item
End Sub




Do/Loops
The process of repeating a series of instructions is called Looping. The group of repeated
instructions is called a loop.

An iteration is a single execution of the statements in the loop.

A Do/Loop terminates on the condition that you specify. Execution of a Do/Loop continues
while a condition is True or until a condition is true.

The first form of the Do/loop tests for completion at the top of the loop. This type of loop is
called as pretest. The statements inside the loop may never be executed if the terminating
condition is true the first time it is tested.
Syntax
        Do [{While | Until} condition]
        [statements]
        [Exit Do]
        [statements]
        Loop


                                                                                                  5
VISUAL BASIC 6 – 3 CUBE COMPUTER INSTITUTE (3CCI)



The second form of Do/Loop tests for completion at the bottom of the loop. This type of loop is
called as posttest. Which means the statements of the loop will always be executed at least once.
Syntax
        Do
        [statements]
        [Exit Do]
        [statements]
        Loop [{While | Until} condition]

The Do Loop statement syntax has these parts:
Part                      Description

condition                 Optional. Numeric expression or string expression that is True or False.
                          If condition is Null, condition is treated as False.

statements                One or more statements that are repeated while, or until, condition is
                          True.



For...Next Statement
Repeats a group of statements a specified number of times.
Syntax

        For counter = start To end [Step step]
        [statements]
        [Exit For]
        [statements]
        Next [counter]

The For…Next statement syntax has these parts:
Part                   Description
Counter                Required. Numeric variable used as a loop counter.
start                  Required. Initial value of counter.
end                    Required. Final value of counter.
step                   Optional. Amount counter is changed each time through the loop. If not
                       specified, step defaults to one.
statements             Optional. One or more statements between For and Next that are
                       executed the specified number of times.

Remarks
The step argument can be either positive or negative.

After all statements in the loop have executed, step is added to counter. At this point, either the
statements in the loop execute again (based on the same test that caused the loop to execute
initially), or the loop is exited and execution continues with the statement following the Next
statement.




                                                                                                      6
VISUAL BASIC 6 – 3 CUBE COMPUTER INSTITUTE (3CCI)


String Function

    1. Left Function

Returns a Variant (String) containing a specified number of characters from the left side of a string.
Syntax
Left(string, length)
The Left function syntax has these named arguments:
Part          Description
string        Required. String expression from which the leftmost characters are returned. If string
              contains Null, Null is returned.
length        Required; Variant (Long). Numeric expression indicating how many characters to
              return. If 0, a zero-length string ("") is returned. If greater than or equal to the number
              of characters in string, the entire string is returned.


Left Function Example

This example uses the Left function to return a specified number of characters from the left
side of a string.

Dim AnyString, MyStr
AnyString = "Hello World"   ' Define string.
MyStr = Left(AnyString, 1)   ' Returns "H".
MyStr = Left(AnyString, 7)   ' Returns "Hello W".
MyStr = Left(AnyString, 20)   ' Returns "Hello World".



    2. Right Function

Returns a Variant (String) containing a specified number of characters from the right side of a
string.

Syntax

Right(string, length)

The Right function syntax has these named arguments:

Part         Description

string       Required. String expression from which the rightmost characters are returned. If
             string contains Null, Null is returned.

length       Required; Variant (Long). Numeric expression indicating how many characters to
             return. If 0, a zero-length string ("") is returned. If greater than or equal to the
             number of characters in string, the entire string is returned.




                                                                                                            7
VISUAL BASIC 6 – 3 CUBE COMPUTER INSTITUTE (3CCI)


Right Function Example

This example uses the Right function to return a specified number of characters from the right
side of a string.

Dim AnyString, MyStr
AnyString = "Hello World" ' Define string.
MyStr = Right(AnyString, 1) ' Returns "d".
MyStr = Right(AnyString, 6) ' Returns " World".
MyStr = Right(AnyString, 20) ' Returns "Hello World".




   3. Mid Function

   Returns a Variant (String) containing a specified number of characters from a string.

Syntax

Mid(string, start[, length])

The Mid function syntax has these named arguments:

Part       Description

string     Required. String expression from which characters are returned. If string contains
           Null, Null is returned.

start      Required; Long. Character position in string at which the part to be taken begins. If
           start is greater than the number of characters in string, Mid returns a zero-length
           string ("").

length     Optional; Variant (Long). Number of characters to return. If omitted or if there are
           fewer than length characters in the text (including the character at start), all
           characters from the start position to the end of the string are returned.



Mid Function Example

The first example uses the Mid function to return a specified number of characters from a
string.

Dim MyString, FirstWord, LastWord, MidWords
MyString = "Mid Function Demo" ' Create text string.
FirstWord = Mid(MyString, 1, 3) ' Returns "Mid".
LastWord = Mid(MyString, 14, 4) ' Returns "Demo".
MidWords = Mid(MyString, 5) ' Returns "Function Demo".



                                                                                                   8
VISUAL BASIC 6 – 3 CUBE COMPUTER INSTITUTE (3CCI)


    4. Len Function

Returns a Long containing the number of characters in a string or the number of bytes required
to store a variable.

Syntax

Len(string | varname)

The Len function syntax has these parts:

Part            Description

string          Any valid string expression. If string contains Null, Null is returned.

Varname         Any valid variable name. If varname contains Null, Null is returned. If varname is
                a Variant, Len treats it the same as a String and always returns the number of
                characters it contains.


Len Function Example

The first example uses Len to return the number of characters in a string or the number of bytes
required to store a variable.

Dim MyString, MyLen
MyString = "Hello World" ' Initialize variable.
MyLen = Len(MyString) ' Returns 11.


    5. InStr Function

Returns a Variant (Long) specifying the position of the first occurrence of one string within another.

Syntax: InStr([start, ]string1, string2)

The InStr function syntax has these arguments:

Part             Description

start            Optional. Numeric expression that sets the starting position for each search. If
                 omitted, search begins at the first character position. If start contains Null, an
                 error occurs. The start argument is required if compare is specified.

string1          Required. String expression being searched.

string2          Required. String expression sought.




                                                                                                         9
VISUAL BASIC 6 – 3 CUBE COMPUTER INSTITUTE (3CCI)


InStr Function Example
This example uses the InStr function to return the position of the first occurrence of one string
within another.
Dim SearchString, SearchChar, MyPos
SearchString ="XXpXXpXXPXXP" ' String to search in.
SearchChar = "P" ' Search for "P".

' A textual comparison starting at position 4. Returns 6.
MyPos = Instr(4, SearchString, SearchChar, 1)

' A binary comparison starting at position 1. Returns 9.
MyPos = Instr(1, SearchString, SearchChar, 0)

' Comparison is binary by default (last argument is omitted).
MyPos = Instr(SearchString, SearchChar) ' Returns 9.

MyPos = Instr(1, SearchString, "W") ' Returns 0.



    6. LTrim, RTrim, and Trim Functions

 Returns a Variant (String) containing a copy of a specified string without leading spaces
(LTrim), trailing spaces (RTrim), or both leading and trailing spaces (Trim).

Syntax
LTrim(string)
RTrim(string)
Trim(string)
The required string argument is any valid string expression. If string contains Null, Null is
returned.

LTrim, RTrim, and Trim Functions Example
This example uses the LTrim function to strip leading spaces and the RTrim function to strip
trailing spaces from a string variable. It uses the Trim function to strip both types of spaces.

Dim MyString, TrimString
MyString = " <-Trim-> " ' Initialize string.
TrimString = LTrim(MyString) ' TrimString = "<-Trim-> ".
TrimString = RTrim(MyString) ' TrimString = " <-Trim->".
TrimString = LTrim(RTrim(MyString)) ' TrimString = "<-Trim->".
' Using the Trim function alone achieves the same result.
TrimString = Trim(MyString) ' TrimString = "<-Trim->".




                                                                                                    10
VISUAL BASIC 6 – 3 CUBE COMPUTER INSTITUTE (3CCI)


SAMPLE APPLICATION




Private Sub cmdAddCoffee_Click()
  'Add a new coffee flavor to the coffee list
  If cboCoffee.Text <> "" Then
     With cboCoffee
       .AddItem .Text
       .Text = ""
     End With
  Else
     MsgBox "Entere a coffee name to add", vbExclamation, "Missing Data"
  End If
  cboCoffee.SetFocus
End Sub

Private Sub mnuEditAdd_Click(Index As Integer)
  'Add a new coffee to list
  cmdAddCoffee_Click
End Sub

Private Sub mnuEditClear_Click(Index As Integer)
  'Clear the coffee list
  Dim intResponse As Integer
  intResponse = MsgBox("Clear the coffee flavor list?", _
     vbYesNo + vbQuestion, "Clear coffee list")
  If intResponse = vbYes Then
      cboCoffee.Clear
  End If
End Sub


Private Sub mnuEditCount_Click(Index As Integer)
  'Display a count of the coffee list
  MsgBox "The number of coffee types is " & cboCoffee.ListCount
End Sub

                                                                              11
VISUAL BASIC 6 – 3 CUBE COMPUTER INSTITUTE (3CCI)



Private Sub mnuEditRemove_Click(Index As Integer)
  'Remove the selected coffee from list
  If cboCoffee.ListIndex <> -1 Then
     cboCoffee.RemoveItem cboCoffee.ListIndex
  Else
     MsgBox "First select the coffee to remove", vbInformation, _
     "No selection made"
  End If
End Sub

Private Sub mnuFileExit_Click(Index As Integer)
  'Terminate the Project
  End
End Sub

Private Sub mnuFilePrintAll_Click(Index As Integer)
  'Print the contents of the coffee flavors combo box on the printer
  Dim intIndex As Integer
  Dim intFinalValue As Integer

  Printer.Print              'Blank Line
  Printer.Print Tab(20); "Coffee Flavors"
  Printer.Print              'Blank Line
  intFinalValue = cboCoffee.ListCount - 1
  'List index starts at 0
  For intIndex = 0 To intFinalValue
     Printer.Print Tab(20); cboCoffee.List(intIndex)
  Next intIndex
  Printer.EndDoc
End Sub


Private Sub mnuFilePrintSelect_Click(Index As Integer)
  'Send the current selection of coffee flavor
  'and syrup flavor to the printer

  If cboCoffee.ListIndex <> -1 And lstSyrup.ListIndex <> -1 Then
     Printer.Print 'Blank Line
     Printer.Print Tab(15); "Coffee Selection"
     Printer.Print 'Blank Line
     Printer.Print Tab(10); "Coffee Flavor: "; cboCoffee.Text
     Printer.Print 'Blank Line
     Printer.Print Tab(10); "Syrup Flavor: "; lstSyrup.Text
  Else
     MsgBox "Make a selection for coffee and syrup.", vbExclamation, _
         "Missing Data"
  End If
End Sub




                                                                               12

Más contenido relacionado

La actualidad más candente

[C++][a] tutorial 2
[C++][a] tutorial 2[C++][a] tutorial 2
[C++][a] tutorial 2yasir_cesc
 
Dialog box in vb6
Dialog box in vb6Dialog box in vb6
Dialog box in vb6Saroj Patel
 
7. check box control
7. check box control7. check box control
7. check box controlchauhankapil
 
C UNIT-2 PREPARED Y M V BRAHMANANDA REDDY
C UNIT-2 PREPARED Y M V BRAHMANANDA REDDYC UNIT-2 PREPARED Y M V BRAHMANANDA REDDY
C UNIT-2 PREPARED Y M V BRAHMANANDA REDDYRajeshkumar Reddy
 
USER DEFINED FUNCTIONS IN C MRS.SOWMYA JYOTHI.pdf
USER DEFINED FUNCTIONS IN C MRS.SOWMYA JYOTHI.pdfUSER DEFINED FUNCTIONS IN C MRS.SOWMYA JYOTHI.pdf
USER DEFINED FUNCTIONS IN C MRS.SOWMYA JYOTHI.pdfSowmyaJyothi3
 
Bt0067 c programming and data structures 1
Bt0067 c programming and data structures 1Bt0067 c programming and data structures 1
Bt0067 c programming and data structures 1Techglyphs
 
Overview of C Mrs Sowmya Jyothi
Overview of C Mrs Sowmya JyothiOverview of C Mrs Sowmya Jyothi
Overview of C Mrs Sowmya JyothiSowmya Jyothi
 
Escape Sequences and Variables
Escape Sequences and VariablesEscape Sequences and Variables
Escape Sequences and Variablesyarkhosh
 
Control structure C++
Control structure C++Control structure C++
Control structure C++Anil Kumar
 
Windows form application - C# Training
Windows form application - C# Training Windows form application - C# Training
Windows form application - C# Training Moutasm Tamimi
 

La actualidad más candente (19)

[C++][a] tutorial 2
[C++][a] tutorial 2[C++][a] tutorial 2
[C++][a] tutorial 2
 
Maxbox starter
Maxbox starterMaxbox starter
Maxbox starter
 
C fundamental
C fundamentalC fundamental
C fundamental
 
Dialog box in vb6
Dialog box in vb6Dialog box in vb6
Dialog box in vb6
 
Module iii part i
Module iii part iModule iii part i
Module iii part i
 
7. check box control
7. check box control7. check box control
7. check box control
 
C UNIT-2 PREPARED Y M V BRAHMANANDA REDDY
C UNIT-2 PREPARED Y M V BRAHMANANDA REDDYC UNIT-2 PREPARED Y M V BRAHMANANDA REDDY
C UNIT-2 PREPARED Y M V BRAHMANANDA REDDY
 
USER DEFINED FUNCTIONS IN C MRS.SOWMYA JYOTHI.pdf
USER DEFINED FUNCTIONS IN C MRS.SOWMYA JYOTHI.pdfUSER DEFINED FUNCTIONS IN C MRS.SOWMYA JYOTHI.pdf
USER DEFINED FUNCTIONS IN C MRS.SOWMYA JYOTHI.pdf
 
Bt0067 c programming and data structures 1
Bt0067 c programming and data structures 1Bt0067 c programming and data structures 1
Bt0067 c programming and data structures 1
 
Overview of C Mrs Sowmya Jyothi
Overview of C Mrs Sowmya JyothiOverview of C Mrs Sowmya Jyothi
Overview of C Mrs Sowmya Jyothi
 
Cp module 2
Cp module 2Cp module 2
Cp module 2
 
Variables and data types IN SWIFT
 Variables and data types IN SWIFT Variables and data types IN SWIFT
Variables and data types IN SWIFT
 
Escape Sequences and Variables
Escape Sequences and VariablesEscape Sequences and Variables
Escape Sequences and Variables
 
Control structure C++
Control structure C++Control structure C++
Control structure C++
 
Unit 5: Variables
Unit 5: VariablesUnit 5: Variables
Unit 5: Variables
 
Assignment2
Assignment2Assignment2
Assignment2
 
C Programming Unit-1
C Programming Unit-1C Programming Unit-1
C Programming Unit-1
 
cp Module4(1)
cp Module4(1)cp Module4(1)
cp Module4(1)
 
Windows form application - C# Training
Windows form application - C# Training Windows form application - C# Training
Windows form application - C# Training
 

Similar a Vb6 ch.7-3 cci

Basic controls in asp
Basic controls in aspBasic controls in asp
Basic controls in aspSireesh K
 
java-Unit4 chap2- awt controls and layout managers of applet
java-Unit4 chap2- awt controls and layout managers of appletjava-Unit4 chap2- awt controls and layout managers of applet
java-Unit4 chap2- awt controls and layout managers of appletraksharao
 
Loop structures chpt_6
Loop structures chpt_6Loop structures chpt_6
Loop structures chpt_6cmontanez
 
Practicalfileofvb workshop
Practicalfileofvb workshopPracticalfileofvb workshop
Practicalfileofvb workshopdhi her
 
Vizwik Coding Manual
Vizwik Coding ManualVizwik Coding Manual
Vizwik Coding ManualVizwik
 
Excel Formulas Functions 2007
Excel Formulas Functions 2007Excel Formulas Functions 2007
Excel Formulas Functions 2007simply_coool
 
Apply Bold, Italic and Underline to Selected Text in a RichtextBox using Visu...
Apply Bold, Italic and Underline to Selected Text in a RichtextBox using Visu...Apply Bold, Italic and Underline to Selected Text in a RichtextBox using Visu...
Apply Bold, Italic and Underline to Selected Text in a RichtextBox using Visu...Daniel DotNet
 
9 - Advanced Functions in MS Excel.pptx
9 - Advanced Functions in MS Excel.pptx9 - Advanced Functions in MS Excel.pptx
9 - Advanced Functions in MS Excel.pptxSheryldeVilla2
 
Advanced Spreadsheet Skills-1.pptx
Advanced Spreadsheet Skills-1.pptxAdvanced Spreadsheet Skills-1.pptx
Advanced Spreadsheet Skills-1.pptxCliffordBorromeo
 
การใช้ ListBox และ ComboBox Control
การใช้ ListBox และ ComboBox Controlการใช้ ListBox และ ComboBox Control
การใช้ ListBox และ ComboBox ControlWarawut
 

Similar a Vb6 ch.7-3 cci (20)

Chapter 07
Chapter 07Chapter 07
Chapter 07
 
Maliram poonia project
Maliram poonia projectMaliram poonia project
Maliram poonia project
 
Basic controls in asp
Basic controls in aspBasic controls in asp
Basic controls in asp
 
java-Unit4 chap2- awt controls and layout managers of applet
java-Unit4 chap2- awt controls and layout managers of appletjava-Unit4 chap2- awt controls and layout managers of applet
java-Unit4 chap2- awt controls and layout managers of applet
 
Loop structures chpt_6
Loop structures chpt_6Loop structures chpt_6
Loop structures chpt_6
 
Chapter9 more on database and sql
Chapter9 more on database and sqlChapter9 more on database and sql
Chapter9 more on database and sql
 
Practicalfileofvb workshop
Practicalfileofvb workshopPracticalfileofvb workshop
Practicalfileofvb workshop
 
Vizwik Coding Manual
Vizwik Coding ManualVizwik Coding Manual
Vizwik Coding Manual
 
Excel Formulas Functions 2007
Excel Formulas Functions 2007Excel Formulas Functions 2007
Excel Formulas Functions 2007
 
Apply Bold, Italic and Underline to Selected Text in a RichtextBox using Visu...
Apply Bold, Italic and Underline to Selected Text in a RichtextBox using Visu...Apply Bold, Italic and Underline to Selected Text in a RichtextBox using Visu...
Apply Bold, Italic and Underline to Selected Text in a RichtextBox using Visu...
 
Visual basic bt0082
Visual basic  bt0082Visual basic  bt0082
Visual basic bt0082
 
Richtextbox
RichtextboxRichtextbox
Richtextbox
 
Vb (1)
Vb (1)Vb (1)
Vb (1)
 
Day2
Day2Day2
Day2
 
9 - Advanced Functions in MS Excel.pptx
9 - Advanced Functions in MS Excel.pptx9 - Advanced Functions in MS Excel.pptx
9 - Advanced Functions in MS Excel.pptx
 
Interview Preparation
Interview PreparationInterview Preparation
Interview Preparation
 
easyPy-Basic.pdf
easyPy-Basic.pdfeasyPy-Basic.pdf
easyPy-Basic.pdf
 
Vb script final pari
Vb script final pariVb script final pari
Vb script final pari
 
Advanced Spreadsheet Skills-1.pptx
Advanced Spreadsheet Skills-1.pptxAdvanced Spreadsheet Skills-1.pptx
Advanced Spreadsheet Skills-1.pptx
 
การใช้ ListBox และ ComboBox Control
การใช้ ListBox และ ComboBox Controlการใช้ ListBox และ ComboBox Control
การใช้ ListBox และ ComboBox Control
 

Último

Call Girls in Faridabad 9000000000 Faridabad Escorts Service
Call Girls in Faridabad 9000000000 Faridabad Escorts ServiceCall Girls in Faridabad 9000000000 Faridabad Escorts Service
Call Girls in Faridabad 9000000000 Faridabad Escorts ServiceTina Ji
 
NO1 Certified Black magic/kala jadu,manpasand shadi in lahore,karachi rawalpi...
NO1 Certified Black magic/kala jadu,manpasand shadi in lahore,karachi rawalpi...NO1 Certified Black magic/kala jadu,manpasand shadi in lahore,karachi rawalpi...
NO1 Certified Black magic/kala jadu,manpasand shadi in lahore,karachi rawalpi...Amil baba
 
Call Girls Near The Corus Hotel New Delhi 9873777170
Call Girls Near The Corus Hotel New Delhi 9873777170Call Girls Near The Corus Hotel New Delhi 9873777170
Call Girls Near The Corus Hotel New Delhi 9873777170Sonam Pathan
 
Call Girls Near Taurus Sarovar Portico Hotel New Delhi 9873777170
Call Girls Near Taurus Sarovar Portico Hotel New Delhi 9873777170Call Girls Near Taurus Sarovar Portico Hotel New Delhi 9873777170
Call Girls Near Taurus Sarovar Portico Hotel New Delhi 9873777170Sonam Pathan
 
Real NO1 Amil baba in Faisalabad Kala jadu in faisalabad Aamil baba Faisalaba...
Real NO1 Amil baba in Faisalabad Kala jadu in faisalabad Aamil baba Faisalaba...Real NO1 Amil baba in Faisalabad Kala jadu in faisalabad Aamil baba Faisalaba...
Real NO1 Amil baba in Faisalabad Kala jadu in faisalabad Aamil baba Faisalaba...Amil Baba Company
 
Zoom In Game for ice breaking in a training
Zoom In Game for ice breaking in a trainingZoom In Game for ice breaking in a training
Zoom In Game for ice breaking in a trainingRafik ABDI
 
QUIZ BOLLYWOOD ( weekly quiz ) - SJU quizzers
QUIZ BOLLYWOOD ( weekly quiz ) - SJU quizzersQUIZ BOLLYWOOD ( weekly quiz ) - SJU quizzers
QUIZ BOLLYWOOD ( weekly quiz ) - SJU quizzersSJU Quizzers
 
Gripping Adult Web Series You Can't Afford to Miss
Gripping Adult Web Series You Can't Afford to MissGripping Adult Web Series You Can't Afford to Miss
Gripping Adult Web Series You Can't Afford to Missget joys
 
VIP Call Girls In Goa 7028418221 Call Girls In Baga Beach Escorts Service
VIP Call Girls In Goa 7028418221 Call Girls In Baga Beach Escorts ServiceVIP Call Girls In Goa 7028418221 Call Girls In Baga Beach Escorts Service
VIP Call Girls In Goa 7028418221 Call Girls In Baga Beach Escorts ServiceApsara Of India
 
Call Girls Prahlad Nagar 9920738301 Ridhima Hire Me Full Night
Call Girls Prahlad Nagar 9920738301 Ridhima Hire Me Full NightCall Girls Prahlad Nagar 9920738301 Ridhima Hire Me Full Night
Call Girls Prahlad Nagar 9920738301 Ridhima Hire Me Full Nightssuser7cb4ff
 
Low Rate Call Girls In Budh Vihar, Call Us :-9711106444
Low Rate Call Girls In Budh Vihar, Call Us :-9711106444Low Rate Call Girls In Budh Vihar, Call Us :-9711106444
Low Rate Call Girls In Budh Vihar, Call Us :-9711106444CallGirlsInSouthDelh1
 
Amil baba in Pakistan amil baba Karachi amil baba in pakistan amil baba in la...
Amil baba in Pakistan amil baba Karachi amil baba in pakistan amil baba in la...Amil baba in Pakistan amil baba Karachi amil baba in pakistan amil baba in la...
Amil baba in Pakistan amil baba Karachi amil baba in pakistan amil baba in la...Amil Baba Company
 
North Avenue Call Girls Services, Hire Now for Full Fun
North Avenue Call Girls Services, Hire Now for Full FunNorth Avenue Call Girls Services, Hire Now for Full Fun
North Avenue Call Girls Services, Hire Now for Full FunKomal Khan
 
NO1 WorldWide Amil baba in pakistan Amil Baba in Karachi Black Magic Islamaba...
NO1 WorldWide Amil baba in pakistan Amil Baba in Karachi Black Magic Islamaba...NO1 WorldWide Amil baba in pakistan Amil Baba in Karachi Black Magic Islamaba...
NO1 WorldWide Amil baba in pakistan Amil Baba in Karachi Black Magic Islamaba...Amil baba
 
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377087607
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377087607FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377087607
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377087607dollysharma2066
 
Call Girls SG Highway 7397865700 Ridhima Hire Me Full Night
Call Girls SG Highway 7397865700 Ridhima Hire Me Full NightCall Girls SG Highway 7397865700 Ridhima Hire Me Full Night
Call Girls SG Highway 7397865700 Ridhima Hire Me Full Nightssuser7cb4ff
 
Call Girls Sanand 7397865700 Ridhima Hire Me Full Night
Call Girls Sanand 7397865700 Ridhima Hire Me Full NightCall Girls Sanand 7397865700 Ridhima Hire Me Full Night
Call Girls Sanand 7397865700 Ridhima Hire Me Full Nightssuser7cb4ff
 
NO1 Certified Black magic specialist,Expert in Pakistan Amil Baba kala ilam E...
NO1 Certified Black magic specialist,Expert in Pakistan Amil Baba kala ilam E...NO1 Certified Black magic specialist,Expert in Pakistan Amil Baba kala ilam E...
NO1 Certified Black magic specialist,Expert in Pakistan Amil Baba kala ilam E...Amil Baba Dawood bangali
 
8377087607 Full Enjoy @24/7 Call Girls in Patel Nagar Delhi NCR
8377087607 Full Enjoy @24/7 Call Girls in Patel Nagar Delhi NCR8377087607 Full Enjoy @24/7 Call Girls in Patel Nagar Delhi NCR
8377087607 Full Enjoy @24/7 Call Girls in Patel Nagar Delhi NCRdollysharma2066
 

Último (20)

Call Girls in Faridabad 9000000000 Faridabad Escorts Service
Call Girls in Faridabad 9000000000 Faridabad Escorts ServiceCall Girls in Faridabad 9000000000 Faridabad Escorts Service
Call Girls in Faridabad 9000000000 Faridabad Escorts Service
 
NO1 Certified Black magic/kala jadu,manpasand shadi in lahore,karachi rawalpi...
NO1 Certified Black magic/kala jadu,manpasand shadi in lahore,karachi rawalpi...NO1 Certified Black magic/kala jadu,manpasand shadi in lahore,karachi rawalpi...
NO1 Certified Black magic/kala jadu,manpasand shadi in lahore,karachi rawalpi...
 
Call Girls Near The Corus Hotel New Delhi 9873777170
Call Girls Near The Corus Hotel New Delhi 9873777170Call Girls Near The Corus Hotel New Delhi 9873777170
Call Girls Near The Corus Hotel New Delhi 9873777170
 
Call Girls Near Taurus Sarovar Portico Hotel New Delhi 9873777170
Call Girls Near Taurus Sarovar Portico Hotel New Delhi 9873777170Call Girls Near Taurus Sarovar Portico Hotel New Delhi 9873777170
Call Girls Near Taurus Sarovar Portico Hotel New Delhi 9873777170
 
Real NO1 Amil baba in Faisalabad Kala jadu in faisalabad Aamil baba Faisalaba...
Real NO1 Amil baba in Faisalabad Kala jadu in faisalabad Aamil baba Faisalaba...Real NO1 Amil baba in Faisalabad Kala jadu in faisalabad Aamil baba Faisalaba...
Real NO1 Amil baba in Faisalabad Kala jadu in faisalabad Aamil baba Faisalaba...
 
Zoom In Game for ice breaking in a training
Zoom In Game for ice breaking in a trainingZoom In Game for ice breaking in a training
Zoom In Game for ice breaking in a training
 
QUIZ BOLLYWOOD ( weekly quiz ) - SJU quizzers
QUIZ BOLLYWOOD ( weekly quiz ) - SJU quizzersQUIZ BOLLYWOOD ( weekly quiz ) - SJU quizzers
QUIZ BOLLYWOOD ( weekly quiz ) - SJU quizzers
 
Environment Handling Presentation by Likhon Ahmed.pptx
Environment Handling Presentation by Likhon Ahmed.pptxEnvironment Handling Presentation by Likhon Ahmed.pptx
Environment Handling Presentation by Likhon Ahmed.pptx
 
Gripping Adult Web Series You Can't Afford to Miss
Gripping Adult Web Series You Can't Afford to MissGripping Adult Web Series You Can't Afford to Miss
Gripping Adult Web Series You Can't Afford to Miss
 
VIP Call Girls In Goa 7028418221 Call Girls In Baga Beach Escorts Service
VIP Call Girls In Goa 7028418221 Call Girls In Baga Beach Escorts ServiceVIP Call Girls In Goa 7028418221 Call Girls In Baga Beach Escorts Service
VIP Call Girls In Goa 7028418221 Call Girls In Baga Beach Escorts Service
 
Call Girls Prahlad Nagar 9920738301 Ridhima Hire Me Full Night
Call Girls Prahlad Nagar 9920738301 Ridhima Hire Me Full NightCall Girls Prahlad Nagar 9920738301 Ridhima Hire Me Full Night
Call Girls Prahlad Nagar 9920738301 Ridhima Hire Me Full Night
 
Low Rate Call Girls In Budh Vihar, Call Us :-9711106444
Low Rate Call Girls In Budh Vihar, Call Us :-9711106444Low Rate Call Girls In Budh Vihar, Call Us :-9711106444
Low Rate Call Girls In Budh Vihar, Call Us :-9711106444
 
Amil baba in Pakistan amil baba Karachi amil baba in pakistan amil baba in la...
Amil baba in Pakistan amil baba Karachi amil baba in pakistan amil baba in la...Amil baba in Pakistan amil baba Karachi amil baba in pakistan amil baba in la...
Amil baba in Pakistan amil baba Karachi amil baba in pakistan amil baba in la...
 
North Avenue Call Girls Services, Hire Now for Full Fun
North Avenue Call Girls Services, Hire Now for Full FunNorth Avenue Call Girls Services, Hire Now for Full Fun
North Avenue Call Girls Services, Hire Now for Full Fun
 
NO1 WorldWide Amil baba in pakistan Amil Baba in Karachi Black Magic Islamaba...
NO1 WorldWide Amil baba in pakistan Amil Baba in Karachi Black Magic Islamaba...NO1 WorldWide Amil baba in pakistan Amil Baba in Karachi Black Magic Islamaba...
NO1 WorldWide Amil baba in pakistan Amil Baba in Karachi Black Magic Islamaba...
 
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377087607
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377087607FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377087607
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377087607
 
Call Girls SG Highway 7397865700 Ridhima Hire Me Full Night
Call Girls SG Highway 7397865700 Ridhima Hire Me Full NightCall Girls SG Highway 7397865700 Ridhima Hire Me Full Night
Call Girls SG Highway 7397865700 Ridhima Hire Me Full Night
 
Call Girls Sanand 7397865700 Ridhima Hire Me Full Night
Call Girls Sanand 7397865700 Ridhima Hire Me Full NightCall Girls Sanand 7397865700 Ridhima Hire Me Full Night
Call Girls Sanand 7397865700 Ridhima Hire Me Full Night
 
NO1 Certified Black magic specialist,Expert in Pakistan Amil Baba kala ilam E...
NO1 Certified Black magic specialist,Expert in Pakistan Amil Baba kala ilam E...NO1 Certified Black magic specialist,Expert in Pakistan Amil Baba kala ilam E...
NO1 Certified Black magic specialist,Expert in Pakistan Amil Baba kala ilam E...
 
8377087607 Full Enjoy @24/7 Call Girls in Patel Nagar Delhi NCR
8377087607 Full Enjoy @24/7 Call Girls in Patel Nagar Delhi NCR8377087607 Full Enjoy @24/7 Call Girls in Patel Nagar Delhi NCR
8377087607 Full Enjoy @24/7 Call Girls in Patel Nagar Delhi NCR
 

Vb6 ch.7-3 cci

  • 1. VISUAL BASIC 6 – 3 CUBE COMPUTER INSTITUTE (3CCI) Chapter 7 List Box Control A list box control displays a list of items from which the user can select one or more. List boxes present a list of choices to the user. By default, the choices are displayed vertically in a single column. If the number of items exceeds what can be displayed in the list box, scroll bars automatically appear on the control. The user can then scroll up and down, or left to right through the list. Combo Box Control A combo box control combines the features of a text box and a list box. This control allows the user to select an item either by typing text into the combo box, or by selecting it from the list. Combo boxes present a list of choices to the user. If the number of items exceeds what can be displayed in the combo box, scroll bars will automatically appear on the control. The user can then scroll up and down or left to right through the list. Combo Box Styles There are three combo box styles. Each style can be set at design time and uses values, or equivalent Visual Basic constants, to set the style of the combo box. Style Value Constant Drop-down combo box 0 vbComboDropDown Simple combo box 1 vbComboSimple Drop-down list box 2 vbComboDropDownList 1. Drop-down Combo Box With the default setting (Style = 0 – Dropdown Combo), a combo box is a drop-down combo box. The user can either enter text directly (as in a text box) or click the detached arrow at the right of the combo box to open a list of choices. Selecting one of the choices inserts it into the text portion at the top of the combo box. 1
  • 2. VISUAL BASIC 6 – 3 CUBE COMPUTER INSTITUTE (3CCI) 2. Simple Combo Box Setting the Style property of a combo box to 1 – Simple Combo specifies a simple combo box in which the list is displayed at all times. To display all entries in the list, you must draw the list box large enough to display the entries. A vertical scroll bar is automatically inserted when there are more entries than can be displayed. The user can still enter text directly or select from the list. As with a drop-down combo box, a simple combo box also allows users to enter choices not on the list. 3. Drop-down List Box A drop-down list box (Style = 2 – Dropdown List) is like a regular list box — it displays a list of items from which a user must choose. Unlike list boxes, however, the list is not displayed until you click the arrow to the right of the box. The key difference between this and a drop-down combo box is that the user can't type into the box, he can only select an item from the list. 2
  • 3. VISUAL BASIC 6 – 3 CUBE COMPUTER INSTITUTE (3CCI) Adding Items to list Box / Combo Box at Design-Time: 1. Place the list box/ Combo box in form and choose the list box/ Combo box. 2. Go to list property of List Box Control/ Combo box Control. 3. Add 1st item to the list box/ Combo box. 4. To add 2nd item press Ctrl + Enter. 5. Repeat 4th step for adding more items to the list. 6. After Last item is added, don’t press Ctrl + Enter, otherwise at the end of list box/ Combo box an empty string will be added. Adding Items to list Box / Combo Box at Run-Time: If you want to add item in the list box/ Combo Box during runtime, you have to use the Addtem method. General form – Object.AddItem Value [, Index] Value is the value to add to the list. If the value is a string literal, enclose it in quotation marks. Index specifies the position in the list where the value must be stored, the first element in the list box has the Index = 0. Example: lstName.AddItem “A” cboName.AddItem “B” Clearing The List Box/ Combo Box Items: To clear items of the list box or a combo box at runtime, use the Clear Method to empty the combo box and list box. General form – Object.Clear Example: lstName.Clear cboName.Clear ListIndex Property Returns or sets the index of the currently selected item in the control. Not available at design time. 3
  • 4. VISUAL BASIC 6 – 3 CUBE COMPUTER INSTITUTE (3CCI) When a project is running, the user select an item from the list box/combo box, the index of that selected item is stored in the ListIndex property. ListIndex of the first item in the list is 0. If no list item is selected then the ListIndex property is set to -1. Example: Private Sub cmdOk_Click () MsgBox cboName.ListIndex End Sub ListCount Property The ListCount property of a list box/combo box is used to store the number of items in the list. ListCount is always one more that the highest ListIndex, since ListIndex starts from 0. Example: Private Sub Form_Load() Combo1.AddItem "A" Combo1.AddItem "B" Combo1.AddItem "C" Combo1.AddItem "D" End Sub Private Sub cmdOk_Click () MsgBox cboName.ListCount End Sub List Property The List Property is used to display a item from the list. The list property of list box/combo box holds the text of all list elements. Specify the element by using its Index. General form –Object.List(Index) [ = Value] Example: 4
  • 5. VISUAL BASIC 6 – 3 CUBE COMPUTER INSTITUTE (3CCI) Private Sub Command1_Click() MsgBox Combo1.List(Combo1.ListIndex) ‘gets the current selected item End Sub RemoveItem Property The RemoveItem Property is used to remove a single element from the list. General form – Object.RemoveItem Index. The index is required as it specifies which item is to be removed. Example: Private Sub Command1_Click() Combo1.RemoveItem Combo1.ListIndex ‘removes the current selected item End Sub Do/Loops The process of repeating a series of instructions is called Looping. The group of repeated instructions is called a loop. An iteration is a single execution of the statements in the loop. A Do/Loop terminates on the condition that you specify. Execution of a Do/Loop continues while a condition is True or until a condition is true. The first form of the Do/loop tests for completion at the top of the loop. This type of loop is called as pretest. The statements inside the loop may never be executed if the terminating condition is true the first time it is tested. Syntax Do [{While | Until} condition] [statements] [Exit Do] [statements] Loop 5
  • 6. VISUAL BASIC 6 – 3 CUBE COMPUTER INSTITUTE (3CCI) The second form of Do/Loop tests for completion at the bottom of the loop. This type of loop is called as posttest. Which means the statements of the loop will always be executed at least once. Syntax Do [statements] [Exit Do] [statements] Loop [{While | Until} condition] The Do Loop statement syntax has these parts: Part Description condition Optional. Numeric expression or string expression that is True or False. If condition is Null, condition is treated as False. statements One or more statements that are repeated while, or until, condition is True. For...Next Statement Repeats a group of statements a specified number of times. Syntax For counter = start To end [Step step] [statements] [Exit For] [statements] Next [counter] The For…Next statement syntax has these parts: Part Description Counter Required. Numeric variable used as a loop counter. start Required. Initial value of counter. end Required. Final value of counter. step Optional. Amount counter is changed each time through the loop. If not specified, step defaults to one. statements Optional. One or more statements between For and Next that are executed the specified number of times. Remarks The step argument can be either positive or negative. After all statements in the loop have executed, step is added to counter. At this point, either the statements in the loop execute again (based on the same test that caused the loop to execute initially), or the loop is exited and execution continues with the statement following the Next statement. 6
  • 7. VISUAL BASIC 6 – 3 CUBE COMPUTER INSTITUTE (3CCI) String Function 1. Left Function Returns a Variant (String) containing a specified number of characters from the left side of a string. Syntax Left(string, length) The Left function syntax has these named arguments: Part Description string Required. String expression from which the leftmost characters are returned. If string contains Null, Null is returned. length Required; Variant (Long). Numeric expression indicating how many characters to return. If 0, a zero-length string ("") is returned. If greater than or equal to the number of characters in string, the entire string is returned. Left Function Example This example uses the Left function to return a specified number of characters from the left side of a string. Dim AnyString, MyStr AnyString = "Hello World" ' Define string. MyStr = Left(AnyString, 1) ' Returns "H". MyStr = Left(AnyString, 7) ' Returns "Hello W". MyStr = Left(AnyString, 20) ' Returns "Hello World". 2. Right Function Returns a Variant (String) containing a specified number of characters from the right side of a string. Syntax Right(string, length) The Right function syntax has these named arguments: Part Description string Required. String expression from which the rightmost characters are returned. If string contains Null, Null is returned. length Required; Variant (Long). Numeric expression indicating how many characters to return. If 0, a zero-length string ("") is returned. If greater than or equal to the number of characters in string, the entire string is returned. 7
  • 8. VISUAL BASIC 6 – 3 CUBE COMPUTER INSTITUTE (3CCI) Right Function Example This example uses the Right function to return a specified number of characters from the right side of a string. Dim AnyString, MyStr AnyString = "Hello World" ' Define string. MyStr = Right(AnyString, 1) ' Returns "d". MyStr = Right(AnyString, 6) ' Returns " World". MyStr = Right(AnyString, 20) ' Returns "Hello World". 3. Mid Function Returns a Variant (String) containing a specified number of characters from a string. Syntax Mid(string, start[, length]) The Mid function syntax has these named arguments: Part Description string Required. String expression from which characters are returned. If string contains Null, Null is returned. start Required; Long. Character position in string at which the part to be taken begins. If start is greater than the number of characters in string, Mid returns a zero-length string (""). length Optional; Variant (Long). Number of characters to return. If omitted or if there are fewer than length characters in the text (including the character at start), all characters from the start position to the end of the string are returned. Mid Function Example The first example uses the Mid function to return a specified number of characters from a string. Dim MyString, FirstWord, LastWord, MidWords MyString = "Mid Function Demo" ' Create text string. FirstWord = Mid(MyString, 1, 3) ' Returns "Mid". LastWord = Mid(MyString, 14, 4) ' Returns "Demo". MidWords = Mid(MyString, 5) ' Returns "Function Demo". 8
  • 9. VISUAL BASIC 6 – 3 CUBE COMPUTER INSTITUTE (3CCI) 4. Len Function Returns a Long containing the number of characters in a string or the number of bytes required to store a variable. Syntax Len(string | varname) The Len function syntax has these parts: Part Description string Any valid string expression. If string contains Null, Null is returned. Varname Any valid variable name. If varname contains Null, Null is returned. If varname is a Variant, Len treats it the same as a String and always returns the number of characters it contains. Len Function Example The first example uses Len to return the number of characters in a string or the number of bytes required to store a variable. Dim MyString, MyLen MyString = "Hello World" ' Initialize variable. MyLen = Len(MyString) ' Returns 11. 5. InStr Function Returns a Variant (Long) specifying the position of the first occurrence of one string within another. Syntax: InStr([start, ]string1, string2) The InStr function syntax has these arguments: Part Description start Optional. Numeric expression that sets the starting position for each search. If omitted, search begins at the first character position. If start contains Null, an error occurs. The start argument is required if compare is specified. string1 Required. String expression being searched. string2 Required. String expression sought. 9
  • 10. VISUAL BASIC 6 – 3 CUBE COMPUTER INSTITUTE (3CCI) InStr Function Example This example uses the InStr function to return the position of the first occurrence of one string within another. Dim SearchString, SearchChar, MyPos SearchString ="XXpXXpXXPXXP" ' String to search in. SearchChar = "P" ' Search for "P". ' A textual comparison starting at position 4. Returns 6. MyPos = Instr(4, SearchString, SearchChar, 1) ' A binary comparison starting at position 1. Returns 9. MyPos = Instr(1, SearchString, SearchChar, 0) ' Comparison is binary by default (last argument is omitted). MyPos = Instr(SearchString, SearchChar) ' Returns 9. MyPos = Instr(1, SearchString, "W") ' Returns 0. 6. LTrim, RTrim, and Trim Functions Returns a Variant (String) containing a copy of a specified string without leading spaces (LTrim), trailing spaces (RTrim), or both leading and trailing spaces (Trim). Syntax LTrim(string) RTrim(string) Trim(string) The required string argument is any valid string expression. If string contains Null, Null is returned. LTrim, RTrim, and Trim Functions Example This example uses the LTrim function to strip leading spaces and the RTrim function to strip trailing spaces from a string variable. It uses the Trim function to strip both types of spaces. Dim MyString, TrimString MyString = " <-Trim-> " ' Initialize string. TrimString = LTrim(MyString) ' TrimString = "<-Trim-> ". TrimString = RTrim(MyString) ' TrimString = " <-Trim->". TrimString = LTrim(RTrim(MyString)) ' TrimString = "<-Trim->". ' Using the Trim function alone achieves the same result. TrimString = Trim(MyString) ' TrimString = "<-Trim->". 10
  • 11. VISUAL BASIC 6 – 3 CUBE COMPUTER INSTITUTE (3CCI) SAMPLE APPLICATION Private Sub cmdAddCoffee_Click() 'Add a new coffee flavor to the coffee list If cboCoffee.Text <> "" Then With cboCoffee .AddItem .Text .Text = "" End With Else MsgBox "Entere a coffee name to add", vbExclamation, "Missing Data" End If cboCoffee.SetFocus End Sub Private Sub mnuEditAdd_Click(Index As Integer) 'Add a new coffee to list cmdAddCoffee_Click End Sub Private Sub mnuEditClear_Click(Index As Integer) 'Clear the coffee list Dim intResponse As Integer intResponse = MsgBox("Clear the coffee flavor list?", _ vbYesNo + vbQuestion, "Clear coffee list") If intResponse = vbYes Then cboCoffee.Clear End If End Sub Private Sub mnuEditCount_Click(Index As Integer) 'Display a count of the coffee list MsgBox "The number of coffee types is " & cboCoffee.ListCount End Sub 11
  • 12. VISUAL BASIC 6 – 3 CUBE COMPUTER INSTITUTE (3CCI) Private Sub mnuEditRemove_Click(Index As Integer) 'Remove the selected coffee from list If cboCoffee.ListIndex <> -1 Then cboCoffee.RemoveItem cboCoffee.ListIndex Else MsgBox "First select the coffee to remove", vbInformation, _ "No selection made" End If End Sub Private Sub mnuFileExit_Click(Index As Integer) 'Terminate the Project End End Sub Private Sub mnuFilePrintAll_Click(Index As Integer) 'Print the contents of the coffee flavors combo box on the printer Dim intIndex As Integer Dim intFinalValue As Integer Printer.Print 'Blank Line Printer.Print Tab(20); "Coffee Flavors" Printer.Print 'Blank Line intFinalValue = cboCoffee.ListCount - 1 'List index starts at 0 For intIndex = 0 To intFinalValue Printer.Print Tab(20); cboCoffee.List(intIndex) Next intIndex Printer.EndDoc End Sub Private Sub mnuFilePrintSelect_Click(Index As Integer) 'Send the current selection of coffee flavor 'and syrup flavor to the printer If cboCoffee.ListIndex <> -1 And lstSyrup.ListIndex <> -1 Then Printer.Print 'Blank Line Printer.Print Tab(15); "Coffee Selection" Printer.Print 'Blank Line Printer.Print Tab(10); "Coffee Flavor: "; cboCoffee.Text Printer.Print 'Blank Line Printer.Print Tab(10); "Syrup Flavor: "; lstSyrup.Text Else MsgBox "Make a selection for coffee and syrup.", vbExclamation, _ "Missing Data" End If End Sub 12