Download presentation
Presentation is loading. Please wait.
Published byNicholas Perkins Modified over 9 years ago
1
Slide 1 Controls v Control naming convention –Label: lblName –Command Button: cmdName –Text Box: txtName
2
Slide 2 Variables v Variable: Temporary storage location for information v Variable declaration: each variable can be declared with the dim statement –Dim x as integer v Single declaration statement must not contain more than one variable without specifying its type. v Set VB to Require variable declarations in order to avoid misspelling a variable –(Tools, Options, Editor – Require Variable Declaration) –This way VB gives an error if a variable is not declared
3
Slide 3 Variables v Naming convention (using prefix) –s : String –n : Integer –l : Long Integer –f : Single –d : Double –c : Currency –b : Boolean –v : Variant
4
Slide 4 Small Application v To get data from a user you should use a Text Box v To display information for a user you should use a Label v The processing of the data should take place when the user clicks on a Command Button Text Box Label Command Button
5
Slide 5 Changing Properties To change a control’s property you assign the new property to it: label4.caption = fNumberOfKilos To access a control on another form you should use the form name to prefix the property name: Form2.Label5.Caption = fCostPerKilo Control Name Property Form Name Control Name Property
6
Slide 6 Controls: Text Box v The Text / Edit box is a control that handles user input / editing of text. v The characters that are written in the text box are held in the Text property.
7
Slide 7 Controls: Text Box v We can assign the contents of the text box to a variable quite simply - for instance Sub Command1_click() Dim sMyName As String sMyName = Text1.Text End Will cause whatever to written by the user in the text box to be stored in the variable sMyName when the user clicks on Command button 1
8
Slide 8 Val function v The contents of a text box is always character based - even if we type in numbers they will always be seen as simply a collection of characters and so cannot be used in any form of maths - that is we can’t add them, multiply or so on. v To turn them into numbers we must use the Val function. iMyNumber = Val(Text1.text) Here the text is stored in the text property The Val function converts the symbols into numbers Finally the value is stored in the variable
9
Slide 9 Controls: Label v A label is intended for displaying information only v We can display information in it by assigning a value to the Caption property Command1_Click() Label1.Caption = “Intro to VB” End
10
Slide 10 Running a Program v Click the Start button on the VB toolbar OR v Choose Run – Start OR v Press F5
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.