SlideShare a Scribd company logo
1 of 4
1
Controls:
OptionButtons (RadioButtons):
Multiple choices, but user can select only
one choice
Check Box:
Multiple choices, user can select many
choices
Combo Box:
One option can be selected
List Box:
One option can be selected
Frames:
Provide a way of grouping related controls
on a form. And, in the case of option
buttons, frames affect how such buttons
operate.
To group controls in a frame, you first draw
the frame. Then, the associated controls
must be drawn in the frame. This allows you
to move the frame and controls together.
Image Boxes:
An image box allows you to place graphics
information on a form.
Image box graphics can be resized by using the Stretch property.
Image Box Properties:
Picture Establishes the graphics file to display in the image box.
Stretch If False, the image box resizes itself to fit the graphic. If True, the graphic resizes to fit
the control area.
Drive List Box:
The drive list box control allows a user to select a valid disk drive at run-time. It displays the
available drives in a drop-down combo box. No code is needed to load a drive list box; Visual
Basic does this for us. We use the box to get the current drive identification.
Drive List Box Properties:
Drive Contains the name of the currently selected drive.
Drive List Box Events:
Change Triggered whenever the user or program changes the drive selection.
Directory List Box:
The directory list box displays an ordered, hierarchical list of the user's disk directories and
subdirectories. The directory structure is displayed in a list box.
Like, the drive list box, little coding is needed to use the directory list box – Visual Basic does
most of the work for us.
2
Directory List Box Properties:
Path Contains the current directory path.
Directory List Box Events:
Change Triggered when the directory selection is changed.
File List Box
The file list box locates and lists files in the directory specified by its Path property at run-time.
You may select the types of files you want to display in the file list box.
File List Box Properties:
FileName Contains the currently selected file name.
Path Contains the current path directory.
Pattern Contains a string that determines which files will be displayed. For example, using *.jpg
only displays files with the .jpg extension.
Synchronizing the Drive, Directory, and File List Boxes:
The drive, directory, and file list boxes are almost always used together to obtain a file name. As
such, it is important that their operation be synchronized to insure the displayed information is
always consistent.
When the drive selection is changed (drive box Change event), you should update the directory
path. For example, if the drive box is named drvExample and the directory box is dirExample,
use the code:
Dir1.Path = Drive1.Drive
When the directory selection is changed (directory box Change event), you should update the
displayed file names. With a file box named filExample, this code is:
File1.Path = Dir1.Path
Once all of the selections have been made and you want the file name, you need to form a text
string that correctly and completely specifies the file identifier. This string concatenates the
drive, directory, and file name information.
Example code for concatenating the available information into a proper file name and then
loading it into an image box is:
Dim YourFile as String
YourFile = File1.Path + "" + File1.FileName
Image1.Picture = LoadPicture(YourFile)
Note we only use properties of the file list box. The drive and directory box properties are only
used to create changes in the file list box via code.
IF Syntax:
If condition then
Statements
Else
Statements
3
End If
Loops:
For…Next Syntax:
For variable=start to end
Statements
Next
By default increment is of 1. For more increment, we write step increment, e.g. step2 for
increment of 2.
While…Wend Syntax:
While condition
Statements
inc/dec
Wend
Example:
num=Text1.Text
start= Text2.Text
end=Text3.Text
inc= Text4.Text
while start<=end
print num +”*”+start+”=”+num*start
start=val(start+inc)
wend
Do…Loop:
Do While…Loop syntax:
Do While(condition)
Statements
Inc/dec
Loop
Example:
Private Sub Command1_Click()
Dim x As Integer
x = 1
Do While x <= 10
Print x
x = x + 1
Loop
End Sub
4
Do Until…Loop syntax:
Unlike the Do While...Loop and While...Wend repetition structures, the Do Until... Loop
structure tests a condition for falsity.
Statements in the body of a Do Until...Loop are executed repeatedly as long as the condition is
False.
Do Until(condition)
Statements
Inc/dec
Loop
Example:
Private Sub Command1_Click()
Dim x As Integer
x = 1
Do Until x > 10
Print x
x = x + 1
Loop
End Sub
Message Box:
The message box is used to displays a message
Input Box:
The input box is used to take input
Some Control Events:
Click Event triggered when item in list is clicked.
Text Box Events:
Change Triggered every time the Text property changes.
LostFocus Triggered when the user leaves the text box. This is a good place to examine the
contents of a text box after editing.
Some Control Methods:
Combo Box Methods:
AddItem Allows you to insert item in list.
Clear Removes all items from list box.

More Related Content

Similar to Form Controls and Loops in Visual Basic

There are 4 part for the project and the question may be long to rea.docx
There are 4 part for the project and the question may be long to rea.docxThere are 4 part for the project and the question may be long to rea.docx
There are 4 part for the project and the question may be long to rea.docxsusannr
 
There are 4 parts for the project. The question may be long to read .docx
There are 4 parts for the project. The question may be long to read .docxThere are 4 parts for the project. The question may be long to read .docx
There are 4 parts for the project. The question may be long to read .docxsusannr
 
There are 4 parts for the project. The question may be long to r.docx
There are 4 parts for the project. The question may be long to r.docxThere are 4 parts for the project. The question may be long to r.docx
There are 4 parts for the project. The question may be long to r.docxsusannr
 
Introduction to r studio on aws 2020 05_06
Introduction to r studio on aws 2020 05_06Introduction to r studio on aws 2020 05_06
Introduction to r studio on aws 2020 05_06Barry DeCicco
 
Windows FTK Forensics.pdf
Windows FTK Forensics.pdfWindows FTK Forensics.pdf
Windows FTK Forensics.pdfssusere6dc9d
 
CMPE2300 – Lab01 - Defrag-o-maticIn this lab you will crea.docx
CMPE2300 – Lab01 - Defrag-o-maticIn this lab you will crea.docxCMPE2300 – Lab01 - Defrag-o-maticIn this lab you will crea.docx
CMPE2300 – Lab01 - Defrag-o-maticIn this lab you will crea.docxmary772
 
Princeton's Maximum Entropy Tutorial
Princeton's Maximum Entropy TutorialPrinceton's Maximum Entropy Tutorial
Princeton's Maximum Entropy TutorialDashiell Cruz
 
Power Point Lesson 10 Part1
Power Point  Lesson 10  Part1Power Point  Lesson 10  Part1
Power Point Lesson 10 Part1Nasir Jumani
 
DFH PDF-converted.pptx
DFH PDF-converted.pptxDFH PDF-converted.pptx
DFH PDF-converted.pptxAmitKaur17
 
Data_Processing_Program
Data_Processing_ProgramData_Processing_Program
Data_Processing_ProgramNeil Dahlqvist
 
3.1 file input and output
3.1   file input and output3.1   file input and output
3.1 file input and outputallenbailey
 
Understanding and Configuring the FO Plug-in for Generating PDF Files: Part I...
Understanding and Configuring the FO Plug-in for Generating PDF Files: Part I...Understanding and Configuring the FO Plug-in for Generating PDF Files: Part I...
Understanding and Configuring the FO Plug-in for Generating PDF Files: Part I...Suite Solutions
 
Altering Drop-Down Menus for Admissions IT Service Request Form
Altering Drop-Down Menus for Admissions IT Service Request FormAltering Drop-Down Menus for Admissions IT Service Request Form
Altering Drop-Down Menus for Admissions IT Service Request FormEdwin Jackson
 
File System Implementation.pptx
File System Implementation.pptxFile System Implementation.pptx
File System Implementation.pptxRajapriya82
 
Putting dialog boxes to work
Putting dialog boxes to workPutting dialog boxes to work
Putting dialog boxes to workchunky.sarath
 
Sql server lesson3
Sql server lesson3Sql server lesson3
Sql server lesson3Ala Qunaibi
 

Similar to Form Controls and Loops in Visual Basic (20)

There are 4 part for the project and the question may be long to rea.docx
There are 4 part for the project and the question may be long to rea.docxThere are 4 part for the project and the question may be long to rea.docx
There are 4 part for the project and the question may be long to rea.docx
 
There are 4 parts for the project. The question may be long to read .docx
There are 4 parts for the project. The question may be long to read .docxThere are 4 parts for the project. The question may be long to read .docx
There are 4 parts for the project. The question may be long to read .docx
 
There are 4 parts for the project. The question may be long to r.docx
There are 4 parts for the project. The question may be long to r.docxThere are 4 parts for the project. The question may be long to r.docx
There are 4 parts for the project. The question may be long to r.docx
 
Introduction to r studio on aws 2020 05_06
Introduction to r studio on aws 2020 05_06Introduction to r studio on aws 2020 05_06
Introduction to r studio on aws 2020 05_06
 
Unit5
Unit5Unit5
Unit5
 
CPP homework help
CPP homework helpCPP homework help
CPP homework help
 
Windows FTK Forensics.pdf
Windows FTK Forensics.pdfWindows FTK Forensics.pdf
Windows FTK Forensics.pdf
 
CMPE2300 – Lab01 - Defrag-o-maticIn this lab you will crea.docx
CMPE2300 – Lab01 - Defrag-o-maticIn this lab you will crea.docxCMPE2300 – Lab01 - Defrag-o-maticIn this lab you will crea.docx
CMPE2300 – Lab01 - Defrag-o-maticIn this lab you will crea.docx
 
Princeton's Maximum Entropy Tutorial
Princeton's Maximum Entropy TutorialPrinceton's Maximum Entropy Tutorial
Princeton's Maximum Entropy Tutorial
 
WPF Application
WPF ApplicationWPF Application
WPF Application
 
Power Point Lesson 10 Part1
Power Point  Lesson 10  Part1Power Point  Lesson 10  Part1
Power Point Lesson 10 Part1
 
DFH PDF-converted.pptx
DFH PDF-converted.pptxDFH PDF-converted.pptx
DFH PDF-converted.pptx
 
Data file handling
Data file handlingData file handling
Data file handling
 
Data_Processing_Program
Data_Processing_ProgramData_Processing_Program
Data_Processing_Program
 
3.1 file input and output
3.1   file input and output3.1   file input and output
3.1 file input and output
 
Understanding and Configuring the FO Plug-in for Generating PDF Files: Part I...
Understanding and Configuring the FO Plug-in for Generating PDF Files: Part I...Understanding and Configuring the FO Plug-in for Generating PDF Files: Part I...
Understanding and Configuring the FO Plug-in for Generating PDF Files: Part I...
 
Altering Drop-Down Menus for Admissions IT Service Request Form
Altering Drop-Down Menus for Admissions IT Service Request FormAltering Drop-Down Menus for Admissions IT Service Request Form
Altering Drop-Down Menus for Admissions IT Service Request Form
 
File System Implementation.pptx
File System Implementation.pptxFile System Implementation.pptx
File System Implementation.pptx
 
Putting dialog boxes to work
Putting dialog boxes to workPutting dialog boxes to work
Putting dialog boxes to work
 
Sql server lesson3
Sql server lesson3Sql server lesson3
Sql server lesson3
 

More from alldesign

Computer graphics circle
Computer graphics   circleComputer graphics   circle
Computer graphics circlealldesign
 
Getstart graphic
Getstart graphicGetstart graphic
Getstart graphicalldesign
 
Image types,raster and vector graphics
Image types,raster and vector graphicsImage types,raster and vector graphics
Image types,raster and vector graphicsalldesign
 
Image types,raster and vector graphics
Image types,raster and vector graphicsImage types,raster and vector graphics
Image types,raster and vector graphicsalldesign
 
Graphics display devices
Graphics display devicesGraphics display devices
Graphics display devicesalldesign
 
Circles graphic
Circles graphicCircles graphic
Circles graphicalldesign
 
Cg applications
Cg applicationsCg applications
Cg applicationsalldesign
 
Types of cards
Types of cardsTypes of cards
Types of cardsalldesign
 
External types of hardware
External types of hardwareExternal types of hardware
External types of hardwarealldesign
 
Devices of computer
Devices of computerDevices of computer
Devices of computeralldesign
 
Internal computer hardware
Internal computer hardwareInternal computer hardware
Internal computer hardwarealldesign
 
Computer hardware
Computer hardwareComputer hardware
Computer hardwarealldesign
 
Types of slots
Types of slotsTypes of slots
Types of slotsalldesign
 
Application of computer graphic
Application of computer graphicApplication of computer graphic
Application of computer graphicalldesign
 
What is computer graphics
What is computer graphicsWhat is computer graphics
What is computer graphicsalldesign
 
Types of rom
Types of romTypes of rom
Types of romalldesign
 
Types of ram
Types of ramTypes of ram
Types of ramalldesign
 

More from alldesign (20)

Vb lecture
Vb lectureVb lecture
Vb lecture
 
Color model
Color modelColor model
Color model
 
Computer graphics circle
Computer graphics   circleComputer graphics   circle
Computer graphics circle
 
Getstart graphic
Getstart graphicGetstart graphic
Getstart graphic
 
Image types,raster and vector graphics
Image types,raster and vector graphicsImage types,raster and vector graphics
Image types,raster and vector graphics
 
Graphics c
Graphics cGraphics c
Graphics c
 
Image types,raster and vector graphics
Image types,raster and vector graphicsImage types,raster and vector graphics
Image types,raster and vector graphics
 
Graphics display devices
Graphics display devicesGraphics display devices
Graphics display devices
 
Circles graphic
Circles graphicCircles graphic
Circles graphic
 
Cg applications
Cg applicationsCg applications
Cg applications
 
Types of cards
Types of cardsTypes of cards
Types of cards
 
External types of hardware
External types of hardwareExternal types of hardware
External types of hardware
 
Devices of computer
Devices of computerDevices of computer
Devices of computer
 
Internal computer hardware
Internal computer hardwareInternal computer hardware
Internal computer hardware
 
Computer hardware
Computer hardwareComputer hardware
Computer hardware
 
Types of slots
Types of slotsTypes of slots
Types of slots
 
Application of computer graphic
Application of computer graphicApplication of computer graphic
Application of computer graphic
 
What is computer graphics
What is computer graphicsWhat is computer graphics
What is computer graphics
 
Types of rom
Types of romTypes of rom
Types of rom
 
Types of ram
Types of ramTypes of ram
Types of ram
 

Recently uploaded

MARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized GroupMARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized GroupJonathanParaisoCruz
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxpboyjonauth
 
Final demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxFinal demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxAvyJaneVismanos
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxOH TEIK BIN
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsanshu789521
 
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdfLike-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdfMr Bounab Samir
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...Marc Dusseiller Dusjagr
 
Pharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfPharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfMahmoud M. Sallam
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Celine George
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxiammrhaywood
 
Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Jisc
 
Capitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptxCapitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptxCapitolTechU
 
Full Stack Web Development Course for Beginners
Full Stack Web Development Course  for BeginnersFull Stack Web Development Course  for Beginners
Full Stack Web Development Course for BeginnersSabitha Banu
 
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfEnzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfSumit Tiwari
 
Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Celine George
 
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfFraming an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfUjwalaBharambe
 
DATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersDATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersSabitha Banu
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 

Recently uploaded (20)

MARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized GroupMARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized Group
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptx
 
Final demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxFinal demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptx
 
9953330565 Low Rate Call Girls In Rohini Delhi NCR
9953330565 Low Rate Call Girls In Rohini  Delhi NCR9953330565 Low Rate Call Girls In Rohini  Delhi NCR
9953330565 Low Rate Call Girls In Rohini Delhi NCR
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptx
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha elections
 
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdfLike-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
 
Pharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfPharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdf
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17
 
OS-operating systems- ch04 (Threads) ...
OS-operating systems- ch04 (Threads) ...OS-operating systems- ch04 (Threads) ...
OS-operating systems- ch04 (Threads) ...
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
 
Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...
 
Capitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptxCapitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptx
 
Full Stack Web Development Course for Beginners
Full Stack Web Development Course  for BeginnersFull Stack Web Development Course  for Beginners
Full Stack Web Development Course for Beginners
 
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfEnzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
 
Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17
 
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfFraming an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
 
DATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersDATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginners
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
 

Form Controls and Loops in Visual Basic

  • 1. 1 Controls: OptionButtons (RadioButtons): Multiple choices, but user can select only one choice Check Box: Multiple choices, user can select many choices Combo Box: One option can be selected List Box: One option can be selected Frames: Provide a way of grouping related controls on a form. And, in the case of option buttons, frames affect how such buttons operate. To group controls in a frame, you first draw the frame. Then, the associated controls must be drawn in the frame. This allows you to move the frame and controls together. Image Boxes: An image box allows you to place graphics information on a form. Image box graphics can be resized by using the Stretch property. Image Box Properties: Picture Establishes the graphics file to display in the image box. Stretch If False, the image box resizes itself to fit the graphic. If True, the graphic resizes to fit the control area. Drive List Box: The drive list box control allows a user to select a valid disk drive at run-time. It displays the available drives in a drop-down combo box. No code is needed to load a drive list box; Visual Basic does this for us. We use the box to get the current drive identification. Drive List Box Properties: Drive Contains the name of the currently selected drive. Drive List Box Events: Change Triggered whenever the user or program changes the drive selection. Directory List Box: The directory list box displays an ordered, hierarchical list of the user's disk directories and subdirectories. The directory structure is displayed in a list box. Like, the drive list box, little coding is needed to use the directory list box – Visual Basic does most of the work for us.
  • 2. 2 Directory List Box Properties: Path Contains the current directory path. Directory List Box Events: Change Triggered when the directory selection is changed. File List Box The file list box locates and lists files in the directory specified by its Path property at run-time. You may select the types of files you want to display in the file list box. File List Box Properties: FileName Contains the currently selected file name. Path Contains the current path directory. Pattern Contains a string that determines which files will be displayed. For example, using *.jpg only displays files with the .jpg extension. Synchronizing the Drive, Directory, and File List Boxes: The drive, directory, and file list boxes are almost always used together to obtain a file name. As such, it is important that their operation be synchronized to insure the displayed information is always consistent. When the drive selection is changed (drive box Change event), you should update the directory path. For example, if the drive box is named drvExample and the directory box is dirExample, use the code: Dir1.Path = Drive1.Drive When the directory selection is changed (directory box Change event), you should update the displayed file names. With a file box named filExample, this code is: File1.Path = Dir1.Path Once all of the selections have been made and you want the file name, you need to form a text string that correctly and completely specifies the file identifier. This string concatenates the drive, directory, and file name information. Example code for concatenating the available information into a proper file name and then loading it into an image box is: Dim YourFile as String YourFile = File1.Path + "" + File1.FileName Image1.Picture = LoadPicture(YourFile) Note we only use properties of the file list box. The drive and directory box properties are only used to create changes in the file list box via code. IF Syntax: If condition then Statements Else Statements
  • 3. 3 End If Loops: For…Next Syntax: For variable=start to end Statements Next By default increment is of 1. For more increment, we write step increment, e.g. step2 for increment of 2. While…Wend Syntax: While condition Statements inc/dec Wend Example: num=Text1.Text start= Text2.Text end=Text3.Text inc= Text4.Text while start<=end print num +”*”+start+”=”+num*start start=val(start+inc) wend Do…Loop: Do While…Loop syntax: Do While(condition) Statements Inc/dec Loop Example: Private Sub Command1_Click() Dim x As Integer x = 1 Do While x <= 10 Print x x = x + 1 Loop End Sub
  • 4. 4 Do Until…Loop syntax: Unlike the Do While...Loop and While...Wend repetition structures, the Do Until... Loop structure tests a condition for falsity. Statements in the body of a Do Until...Loop are executed repeatedly as long as the condition is False. Do Until(condition) Statements Inc/dec Loop Example: Private Sub Command1_Click() Dim x As Integer x = 1 Do Until x > 10 Print x x = x + 1 Loop End Sub Message Box: The message box is used to displays a message Input Box: The input box is used to take input Some Control Events: Click Event triggered when item in list is clicked. Text Box Events: Change Triggered every time the Text property changes. LostFocus Triggered when the user leaves the text box. This is a good place to examine the contents of a text box after editing. Some Control Methods: Combo Box Methods: AddItem Allows you to insert item in list. Clear Removes all items from list box.