Learning Visual Basic Contols Tutorial 2

  • Uploaded by: Bradley Fourie
  • 0
  • 0
  • May 2020
  • PDF

This document was uploaded by user and they confirmed that they have the permission to share it. If you are author or own the copyright of this book, please report to us by using this DMCA report form. Report DMCA


Overview

Download & View Learning Visual Basic Contols Tutorial 2 as PDF for free.

More details

  • Words: 1,423
  • Pages: 8
Introduction: Learning Visual Basic (VB) will be very useful for any computer user ages ranging from 12 to anything really! What the word ‘Basic’ stands for is, 'Beginner's All-purpose Symbolic Instruction Code'. The reason why the word ‘Visual’ is in front of it is because unlike most programming languages where you would normally have to type coding in to create a command button or a text box, Visual Basic is basically just a "click and drag" method.

First Steps: When you load Visual Basic a pop-up window should appear asking what project you would like to create. Selecting ‘Standard EXE’ is the best choice for the time being. When the project loads you should see a window saying, “Project1 - Form1 (Form)”. This is what we call a Form. To the left of the form is a window which we call the Tool-Box. To the right is the Properties window and above the Properties window is a Project window. The windows you see should be similar to these.

Now I will explain some of the controls you can use in your Projects to start and build-up your very own applications. Command Buttons:

Command Buttons is very user because it places the user in control of the program so they can tell it what to do. To insert a Command Button you’ll have to click on the icon and click and drag where you want it to be positioned and then just release the mouse when you are happy with its positioning. You can change the Command Buttons caption by selecting, “Caption” in the Properties and then changing it to suit your needs.

Labels:

Labels are used to display text which can’t be edited. For example it might inform the user about something. To insert a Label you’ll have to click on the icon and click and drag where you want it to be positioned and then just release the mouse when you are happy with its positioning. You can change the Labels caption by selecting, “Caption” in the Properties and then changing it to suit your needs.

Text Boxes:

Text boxes are used to display text and edit text during runtime. They can store large amounts of data which can be very useful. To insert a Text Box you’ll have to click on the icon and click and drag where you want it to be positioned and then just release the mouse when you are happy with its positioning. You can change the Text Boxes text by selecting, “Text” in the Properties and then changing it to suit your needs.

Picture Boxes:

Picture boxes can contain images and you can also draw pictures into one. To insert a Picture Box you’ll have to click on the icon and click and drag where you want it to be positioned and then just release the mouse when you are happy with its positioning. You can change the Pictures Boxes image by selecting, “Picture” in the Properties and then search for the image which you choose to use.

Recapping: In the last tutorial I talk about the installation process of Visual Basic and also told you about some Controls and explained what they can do. In this PART 02 tutorial I will be adding some still code to them controls I explained in the PART 01 tutorial. Enjoy… Command Buttons and Labels: Here I will be using both the Command Button and the Label to create this code. The code I will be creating is very simple and very easy to follow, all it is, is when the user clicks on the Command Button the Label will change it’s positioning. - Coding: Private Sub Command1_Click() Label1.Move (0)

Before:

Label1.Caption = “My positioning has changed!!!” End Sub - Explained: Basically the ‘Private Sub Command1_Click()’ means that when Command1 (the Command Button) is click on by the user then it goes to the next line down. This line is the ‘Label1.Move (0)’ and this is the command the computer will do if the user clicks the Command1 (Command Button) as explained above but this little command will tell the computer to move (see the .Move) the Label to the left hand side of the form (see the (0)). The third line of coding changes the Labels Caption to say, “My positioning has changed!!!”, but you can edit this anyway you like just make sure you start it will quotation marks and end it will quotation marks. The fourth line of coding just tells the computer that it is the end of that command for that Command Button. - Visuals: These are some visuals below showing you a before and after image of what should happen. After:

Command Buttons and Text Boxes: Here I will be using both the Command Button (again) and a Text Box to create this code. The code I will be creating is very simple and very easy to follow, all it is, is when the user clicks on the Command Button a MsgBox will appear telling the user the number of characters in the Text Box. - Coding: Private Sub Command1_Click() MsgBox (“Characters: “ & Str$(Len(Text1.Text)) & “.”) End Sub - Explained: Basically the ‘Private Sub Command1_Click()’ means that when Command1 (the Command Button) is click on by the user then it goes to the next line down. This line is the ‘MsgBox (“Characters: “ & Str$(Len(Text1.Text)) & “.”)’ and this is the command the computer will do if the user clicks the Command1 (Command Button) as explained above but this

- Visuals: Before:

command will tell the computer to display a MsgBox (MsgBox(“”)) displaying the message, “Characters: “ and then the number of characters in Text1 (Text Box), it does this by making the length (Len) of Text1 into a String (Str$) and then adds it to the MsgBox. The third line of coding just tells the computer that it is the end of that command for that Command Button. These are some visuals below showing you a before and after image of what should happen. After:

Command Buttons, Labels and Text Boxes: Here I will be using the Command Button, a Label and a Text Box to create this code. The code I will be creating is very simple and very easy to follow, all it is, is when the user has entered two numbers in Text1 and Text2 and then has clicked the Command1 it will show what the two numbers equal when added together and this answer will be displayed in Label1. - Coding: Private Sub Command1_Click() Label1.Caption = Str(Val(Text1.Text) + Val(Text2.Text)) End Sub - Explained: Basically the ‘Private Sub Command1_Click()’ means that when Command1 (the Command Button) is click on by the user then it goes to the next line down. This line is the ‘Label1.Caption = Str(Val(Text1.Text) + Val(Text2.Text))’ and this is the command the computer will do if the user clicks the

- Visuals: Before:

Command1 (Command Button) as explained above but this command will tell the computer to display what Text1 and Text2 equal when added together (+). It does this my making Text1 and Text2 into a string (strings are explained above) and then converts that string into a Value (Val) so that the computer understands that it is dealing with numbers. The third line of coding just tells the computer that it is the end of that command for that Command Button. These are some visuals below showing you a before and after image of what should happen. After:

Different Data Types: String: Integer: Long: Single: Double: Currency:

Date: Boolean: Byte: Object:

This is a sequence of up to around 2 billion characters. This is a whole number from -32,768 to 32,767. This is a whole number from -2,147,483,648 to 2,147,483,647. A floating point data type which holds positive or negative numbers up to around 3.4 E38. A floating-point data type like single but holding positive or numbers to around 1.8 E308. This data type is called a scaled integer because it deals with fixed-point numbers that have 15 digits to the left of the decimal point and 4 digits to the right. This is more accurate than floating-point numbers for currency values. st st Holds dates from January 1 , 100 to December 31 , 9999. Time information is also stored. This is the simplest data type. It has just two possible values, True and False. This data type holds positive numbers from 0 to 255. The object data type stores Visual Basic objects. These can also be automation objects from other applications.

Related Documents


More Documents from ""