Professional Documents
Culture Documents
Assignments in Controls: Assignment 1: Usage of TEXTBOX & COMMAND BUTTON
Assignments in Controls: Assignment 1: Usage of TEXTBOX & COMMAND BUTTON
? Assignments in Controls
Objective: Creation of a form using Text box and Command button controls, in which
the text “Starting of Visual Basic” should appear in the Textbox, on clicking
the command but ton OK
TextBox
Command Button
? Open new form in your project by clicking Project>>Add form, then selecting the
form option.
? Click on object text box in tool and drag it to blank form.
? Adjust the size of text box.
? Click on object command button and drag it to blank form.
? Adjust the size of command button.
? Set the properties of two objects as follows:
Text Box
? Open new form in your project by clicking Project>>Add form, then selecting the
form option.
? Create the following objects in the blank form:
Text <Empty>
Radio Button1 Name Option1 Private Sub Option1_Click( )
If Option1.Value = True Then
Caption UpperCase txtInput.Text = UCase(txtInput.Text)
End If
End Sub
Radio Button2 Name Option2 Private Sub Option2_Click( )
If Option2.Value = True Then
Caption LowerCase txtInput.Text = LCase(txtInput .Text)
End If
End Sub
Objective: Creation of a form to add list of items to Combo box and list box through
entry in the Text box
Combo Box
List Box
? Open new form in your project by clicking Project>>Add form, then selecting the
form option.
? Create the following objects in the blank form:
Object Property Value Code
Text Box Name txtBox
Text <Empty>
Command Name cmdAddItem Private Sub CmdAddItem_Click( )
Button1 Dim Data As String
Caption Add Item to Data = txtBox.Text
List lstBox.AddItem Data
cboBox.AddItem Data
End Sub
List Box Name lstBox
ComboBox Name cboBox
? Click on Run button or Run project from RUN menu then click Start.
? Type Apple in Text Box and click the button Add Item to List.
? Similarly, continue adding items to the List Box and Combo Box
Now Both item will be add to list box and as well as in the combo Boxes
Objective: To create a form to make a two way link with an object in another Windows
application.
? Open new form in your project by clicking Project>>Add form, then selecting the
form option.
? Create the following objects in the blank form:
? When you select OLE object from tools box and drag it to the form, the following
screen appears.
You can select a file also by clicking on “Create from a file” button.
Objective: To set the time limit for the execution of your program
? Open new form in your project by clicking Project>>Add form, then selecting the
form option.
? Create the following objects in the blank form:
? Assignments in Programming
Objective: Selection of a Drive from Drive List box, a folder from Directory Listbox,
Image file from the filelistbox of the folder and viewing of the selected image
in the image Control Space.
File ListBox
Fig. 1
Steps for designing the above form
? Open new form in your project by clicking Project>>Add form, and then
selecting the Form option.
? Bring the following objects in the blank form and set their respective properties:
Object Properties Value Code
Drive listbox Name Drive1 Private Sub Drive1_Change( )
Dir1.path = Drive1.Drive
End Sub
Directorylistbox Name Dir1 Private Sub Dir1_Click( )
File1.path = Dir1.Path
End Sub
Image Control Name Image1
Stretch True
Filelistbox Name File1 Private Sub File1_Click( )
SelectFile = File1.path & “\” & File1.filename
Image1.Picture= LoadPicture(SelectFile)
End Sub
Fig. 2
Description: In this form, when Spin button is clicked, three numbers appear in the
labels. In case any of the numbers is 7, the picture of Coins appears, otherwise it
does not.
Fig. 3
Description: In this form, you are supposed to type your age in the text box and
then press the Submit button. Based on the age typed, some message will appear
in the label below. Next you may click on the Type Again button and the cursor
flashes in the text box. Try putting different ages and see the results.
txtAge.Text = ""
lblMessage.Caption = ""
txtAge.SetFocus
Fig. 4
Objective: The functionality of this form, as discussed before, can also be achieved
with the help of another decision structure called Select Case.
txtAge.Text = ""
lblMessage.Caption = ""
txtAge.SetFocus
Fig. 5
Description: When the Loop button is clicked, the text "NIC" appears in different
font sizes, line by line.
For Count = 1 To 10
FontSize = 10 + Count
Print "NIC"; Count
Next Count
with
For Count = 10 To 20 Step 2
FontSize = 10 + Count
Print "NIC"; Count
Next Count
Fig. 5
Description: When the Loop button is clicked, the text "NIC" appears in different
font sizes, line by line.
For Count = 1 To 10
FontSize = 10 + Count
Print "NIC"; Count
Next Count
with
For Count = 10 To 20 Step 2
FontSize = 10 + Count
Print "NIC"; Count
Next Count
Fig. 6
Description : When the Do..While option is clicked under Loops menu , a dialog box
appears. Here upper limit of the numbers has to be entered and OK button is clicked.
As a result, list of the numbers starting from 1 to the upper limit will be printed on the
main form.
p=p+1
Print p
Loop
For trying for Do until..Loop and then replace the same code with the following code for
While..Wend loop
Dim x, p As Integer
x = InputBox("Enter the max limit")
While p < x
p=p+1
Print p
Wend
Fig. 7
Description : Create array of 10 text boxes and a button with caption RESET on the
form. When Arrays menu item is clicked table of 2 will be printed in the text boxex
created.
? Create the menu on the above form as shown in tree given below
In this example NorthWind database already available as sample with Microsoft products
is used.
Sub movefield()
rst.MoveNext
Text1.Text = rst!employeeid
Text2.Text = rst!firstname
Text3.Text = rst!birthdate
End Sub
Sub moveprev()
rst.MovePrevious
Text1.Text = rst!employeeid
Text2.Text = rst!firstname
Text3.Text = rst!birthdate
End Sub
CUSTOMER Form :
End Sub
Sub movefield()
rst.MoveNext
Text1.Text = rst!customerid
Text2.Text = rst!CompanyName
End Sub
Sub moveprev()
rst.MovePrevious
Text1.Text = rst!customerid
Text2.Text = rst!CompanyName
End Sub
Property Value
RowSource Adodc1(Name of ADO control)
ListField Title
cnn.Open