SlideShare une entreprise Scribd logo
1  sur  12
Télécharger pour lire hors ligne
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

Contenu connexe

Tendances

[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
 

Tendances (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
 

Similaire à 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
 

Similaire à 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
 

Dernier

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
 
Vip Udaipur Call Girls 9602870969 Dabok Airport Udaipur Escorts Service
Vip Udaipur Call Girls 9602870969 Dabok Airport Udaipur Escorts ServiceVip Udaipur Call Girls 9602870969 Dabok Airport Udaipur Escorts Service
Vip Udaipur Call Girls 9602870969 Dabok Airport Udaipur Escorts ServiceApsara Of India
 
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
 
Kolkata Call Girl Howrah 👉 8250192130 ❣️💯 Available With Room 24×7
Kolkata Call Girl Howrah 👉 8250192130 ❣️💯 Available With Room 24×7Kolkata Call Girl Howrah 👉 8250192130 ❣️💯 Available With Room 24×7
Kolkata Call Girl Howrah 👉 8250192130 ❣️💯 Available With Room 24×7Riya Pathan
 
Hi Class Call Girls In Goa 7028418221 Call Girls In Anjuna Beach Escort Services
Hi Class Call Girls In Goa 7028418221 Call Girls In Anjuna Beach Escort ServicesHi Class Call Girls In Goa 7028418221 Call Girls In Anjuna Beach Escort Services
Hi Class Call Girls In Goa 7028418221 Call Girls In Anjuna Beach Escort ServicesApsara Of India
 
LE IMPOSSIBRU QUIZ (Based on Splapp-me-do)
LE IMPOSSIBRU QUIZ (Based on Splapp-me-do)LE IMPOSSIBRU QUIZ (Based on Splapp-me-do)
LE IMPOSSIBRU QUIZ (Based on Splapp-me-do)bertfelixtorre
 
Amil Baba in Pakistan Kala jadu Expert Amil baba Black magic Specialist in Is...
Amil Baba in Pakistan Kala jadu Expert Amil baba Black magic Specialist in Is...Amil Baba in Pakistan Kala jadu Expert Amil baba Black magic Specialist in Is...
Amil Baba in Pakistan Kala jadu Expert Amil baba Black magic Specialist in Is...Amil Baba Company
 
Private Call Girls Bansdroni - 8250192130 | 24x7 Service Available Near Me
Private Call Girls Bansdroni - 8250192130 | 24x7 Service Available Near MePrivate Call Girls Bansdroni - 8250192130 | 24x7 Service Available Near Me
Private Call Girls Bansdroni - 8250192130 | 24x7 Service Available Near MeRiya Pathan
 
Air-Hostess Call Girls Shobhabazar | 8250192130 At Low Cost Cash Payment Booking
Air-Hostess Call Girls Shobhabazar | 8250192130 At Low Cost Cash Payment BookingAir-Hostess Call Girls Shobhabazar | 8250192130 At Low Cost Cash Payment Booking
Air-Hostess Call Girls Shobhabazar | 8250192130 At Low Cost Cash Payment BookingRiya Pathan
 
定制(UofT毕业证书)加拿大多伦多大学毕业证成绩单原版一比一
定制(UofT毕业证书)加拿大多伦多大学毕业证成绩单原版一比一定制(UofT毕业证书)加拿大多伦多大学毕业证成绩单原版一比一
定制(UofT毕业证书)加拿大多伦多大学毕业证成绩单原版一比一lvtagr7
 
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
 
1681275559_haunting-adeline and hunting.pdf
1681275559_haunting-adeline and hunting.pdf1681275559_haunting-adeline and hunting.pdf
1681275559_haunting-adeline and hunting.pdfTanjirokamado769606
 
Call Girl Price Andheri WhatsApp:+91-9833363713
Call Girl Price Andheri WhatsApp:+91-9833363713Call Girl Price Andheri WhatsApp:+91-9833363713
Call Girl Price Andheri WhatsApp:+91-9833363713Sonam Pathan
 
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
 
Kolkata Call Girl Bagbazar 👉 8250192130 ❣️💯 Available With Room 24×7
Kolkata Call Girl Bagbazar 👉 8250192130 ❣️💯 Available With Room 24×7Kolkata Call Girl Bagbazar 👉 8250192130 ❣️💯 Available With Room 24×7
Kolkata Call Girl Bagbazar 👉 8250192130 ❣️💯 Available With Room 24×7Riya Pathan
 
The Fine Line Between Honest and Evil Comics by Salty Vixen
The Fine Line Between Honest and Evil Comics by Salty VixenThe Fine Line Between Honest and Evil Comics by Salty Vixen
The Fine Line Between Honest and Evil Comics by Salty VixenSalty Vixen Stories & More
 
Call Girls In Karnal O8860008073 Sector 6 7 8 9 Karnal Escorts
Call Girls In Karnal O8860008073 Sector 6 7 8 9 Karnal EscortsCall Girls In Karnal O8860008073 Sector 6 7 8 9 Karnal Escorts
Call Girls In Karnal O8860008073 Sector 6 7 8 9 Karnal EscortsApsara Of India
 
5* Hotel Call Girls In Goa 7028418221 Call Girls In Calangute Beach Escort Se...
5* Hotel Call Girls In Goa 7028418221 Call Girls In Calangute Beach Escort Se...5* Hotel Call Girls In Goa 7028418221 Call Girls In Calangute Beach Escort Se...
5* Hotel Call Girls In Goa 7028418221 Call Girls In Calangute Beach Escort Se...Apsara Of India
 
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
 

Dernier (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
 
Vip Udaipur Call Girls 9602870969 Dabok Airport Udaipur Escorts Service
Vip Udaipur Call Girls 9602870969 Dabok Airport Udaipur Escorts ServiceVip Udaipur Call Girls 9602870969 Dabok Airport Udaipur Escorts Service
Vip Udaipur Call Girls 9602870969 Dabok Airport Udaipur Escorts Service
 
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
 
Kolkata Call Girl Howrah 👉 8250192130 ❣️💯 Available With Room 24×7
Kolkata Call Girl Howrah 👉 8250192130 ❣️💯 Available With Room 24×7Kolkata Call Girl Howrah 👉 8250192130 ❣️💯 Available With Room 24×7
Kolkata Call Girl Howrah 👉 8250192130 ❣️💯 Available With Room 24×7
 
Hi Class Call Girls In Goa 7028418221 Call Girls In Anjuna Beach Escort Services
Hi Class Call Girls In Goa 7028418221 Call Girls In Anjuna Beach Escort ServicesHi Class Call Girls In Goa 7028418221 Call Girls In Anjuna Beach Escort Services
Hi Class Call Girls In Goa 7028418221 Call Girls In Anjuna Beach Escort Services
 
LE IMPOSSIBRU QUIZ (Based on Splapp-me-do)
LE IMPOSSIBRU QUIZ (Based on Splapp-me-do)LE IMPOSSIBRU QUIZ (Based on Splapp-me-do)
LE IMPOSSIBRU QUIZ (Based on Splapp-me-do)
 
Amil Baba in Pakistan Kala jadu Expert Amil baba Black magic Specialist in Is...
Amil Baba in Pakistan Kala jadu Expert Amil baba Black magic Specialist in Is...Amil Baba in Pakistan Kala jadu Expert Amil baba Black magic Specialist in Is...
Amil Baba in Pakistan Kala jadu Expert Amil baba Black magic Specialist in Is...
 
Private Call Girls Bansdroni - 8250192130 | 24x7 Service Available Near Me
Private Call Girls Bansdroni - 8250192130 | 24x7 Service Available Near MePrivate Call Girls Bansdroni - 8250192130 | 24x7 Service Available Near Me
Private Call Girls Bansdroni - 8250192130 | 24x7 Service Available Near Me
 
Air-Hostess Call Girls Shobhabazar | 8250192130 At Low Cost Cash Payment Booking
Air-Hostess Call Girls Shobhabazar | 8250192130 At Low Cost Cash Payment BookingAir-Hostess Call Girls Shobhabazar | 8250192130 At Low Cost Cash Payment Booking
Air-Hostess Call Girls Shobhabazar | 8250192130 At Low Cost Cash Payment Booking
 
定制(UofT毕业证书)加拿大多伦多大学毕业证成绩单原版一比一
定制(UofT毕业证书)加拿大多伦多大学毕业证成绩单原版一比一定制(UofT毕业证书)加拿大多伦多大学毕业证成绩单原版一比一
定制(UofT毕业证书)加拿大多伦多大学毕业证成绩单原版一比一
 
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
 
Call Girls Koti 7001305949 all area service COD available Any Time
Call Girls Koti 7001305949 all area service COD available Any TimeCall Girls Koti 7001305949 all area service COD available Any Time
Call Girls Koti 7001305949 all area service COD available Any Time
 
1681275559_haunting-adeline and hunting.pdf
1681275559_haunting-adeline and hunting.pdf1681275559_haunting-adeline and hunting.pdf
1681275559_haunting-adeline and hunting.pdf
 
Call Girl Price Andheri WhatsApp:+91-9833363713
Call Girl Price Andheri WhatsApp:+91-9833363713Call Girl Price Andheri WhatsApp:+91-9833363713
Call Girl Price Andheri WhatsApp:+91-9833363713
 
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
 
Kolkata Call Girl Bagbazar 👉 8250192130 ❣️💯 Available With Room 24×7
Kolkata Call Girl Bagbazar 👉 8250192130 ❣️💯 Available With Room 24×7Kolkata Call Girl Bagbazar 👉 8250192130 ❣️💯 Available With Room 24×7
Kolkata Call Girl Bagbazar 👉 8250192130 ❣️💯 Available With Room 24×7
 
The Fine Line Between Honest and Evil Comics by Salty Vixen
The Fine Line Between Honest and Evil Comics by Salty VixenThe Fine Line Between Honest and Evil Comics by Salty Vixen
The Fine Line Between Honest and Evil Comics by Salty Vixen
 
Call Girls In Karnal O8860008073 Sector 6 7 8 9 Karnal Escorts
Call Girls In Karnal O8860008073 Sector 6 7 8 9 Karnal EscortsCall Girls In Karnal O8860008073 Sector 6 7 8 9 Karnal Escorts
Call Girls In Karnal O8860008073 Sector 6 7 8 9 Karnal Escorts
 
5* Hotel Call Girls In Goa 7028418221 Call Girls In Calangute Beach Escort Se...
5* Hotel Call Girls In Goa 7028418221 Call Girls In Calangute Beach Escort Se...5* Hotel Call Girls In Goa 7028418221 Call Girls In Calangute Beach Escort Se...
5* Hotel Call Girls In Goa 7028418221 Call Girls In Calangute Beach Escort Se...
 
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...
 

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