14
Let’s get started using Visual Basic!

Let’s get started using Visual Basic!

  • Upload
    asa

  • View
    32

  • Download
    0

Embed Size (px)

DESCRIPTION

Let’s get started using Visual Basic!. Private Sub cmdGo_Click...   Dim strMessage As String Dim sngSum As Single If IsNumeric(txtNumber1.Text) = False Then MsgBox "The first box must contain a number." Exit Sub End If - PowerPoint PPT Presentation

Citation preview

Page 1: Let’s get started using  Visual Basic!

Let’s get started using Visual Basic!

Page 2: Let’s get started using  Visual Basic!

Private Sub cmdGo_Click...  Dim strMessage As String Dim sngSum As Single  If IsNumeric(txtNumber1.Text) = False Then MsgBox "The first box must contain a number." Exit Sub End If If IsNumeric(txtNumber2.Text) = False Then MsgBox "The second box must contain a number." Exit Sub End If sngSum = CSng(txtNumber1.Text) + CSng(txtNumber2.Text) strMessage = "The sum of " strMessage = strMessage & txtNumber1.Text & " and " strMessage = strMessage & txtNumber2.Text & " is " strMessage = strMessage & CStr(nSum) MsgBox (strMessage) End Sub

Page 3: Let’s get started using  Visual Basic!

Vocabulary Words

• Compile?– Is when VB pre-translates the entire program

into Native code that the operating system and microprocessor can understand.

– The result is an executable program or EXE file.

– The program runs faster because the translation is already finished.

Page 4: Let’s get started using  Visual Basic!

What are the controls used for?

Page 5: Let’s get started using  Visual Basic!

Open Visual Basic and Create the following program:

txtNumber1

txtNumber2

cmdgo

Page 6: Let’s get started using  Visual Basic!

The Command Button!Event:

Means that when a particular event occurs (when the command button is clicked) the code is executed. We call this event the Click event of the command button.

Page 7: Let’s get started using  Visual Basic!

Open Visual Basic and place two command buttons on the form as shown below:

Page 8: Let’s get started using  Visual Basic!

• Double-click on the form to open the code window.

• From the drop-down list in the upper left of the code window, choose cmdbutton1.

• From the drop-down list in the right corner of the code window, choose the MouseMove event.

• Once the MouseMove event is chosen, it will appear in the code window, followed by an End Sub statement.

• Type the following code:MsgBox(“The cursor is on Button 1”)

• Run your program.• What happens?

Page 9: Let’s get started using  Visual Basic!

The Text Box?

Besides entering text into the a text box, what is the other primary purpose of a text box?

• A text box can also be used by the application to display data for the user to read.

Page 10: Let’s get started using  Visual Basic!

MsgBox?

What is the difference between these two lines of code?

MsgBox(“The cursor is on Button 1”)

MsgBox(TextBox1.Text)

?

Page 11: Let’s get started using  Visual Basic!

What will the following do?

TextBox1.Text = “Hello, World!”

TextBox1.Text = TextBox2.Text

TextBox2.Text = TextBox1.Text

?

Page 12: Let’s get started using  Visual Basic!

The Text Box! Create the following form:

Page 13: Let’s get started using  Visual Basic!

• Create a form that contains two text boxes labeled "First Name" and "Last Name", and a command button labeled "Combine".  

• The text boxes should allow the user to type in anything they want.  

• When the command button is clicked, a message box should appear showing the contents of the text box labeled Last Name followed by a comma and a space and then the contents of the text box labeled First Name.

• When finished, call me and I’ll check your program!

Page 14: Let’s get started using  Visual Basic!

Homework!

• Read section Getting Started. (Its section 1 in your book and section 7 on the computer.)

• Tomorrow we will begin with the listbox and combobox controls!