Let’s get started using Visual Basic!. Private Sub cmdGo_Click... Dim strMessage As String Dim...
-
Upload
samson-beasley -
Category
Documents
-
view
213 -
download
0
Transcript of Let’s get started using Visual Basic!. Private Sub cmdGo_Click... Dim strMessage As String Dim...
![Page 1: Let’s get started using Visual Basic!. Private Sub cmdGo_Click... Dim strMessage As String Dim sngSum As Single If IsNumeric(txtNumber1.Text) = False.](https://reader035.fdocuments.in/reader035/viewer/2022071807/56649e935503460f94b98e90/html5/thumbnails/1.jpg)
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.](https://reader035.fdocuments.in/reader035/viewer/2022071807/56649e935503460f94b98e90/html5/thumbnails/2.jpg)
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!. Private Sub cmdGo_Click... Dim strMessage As String Dim sngSum As Single If IsNumeric(txtNumber1.Text) = False.](https://reader035.fdocuments.in/reader035/viewer/2022071807/56649e935503460f94b98e90/html5/thumbnails/3.jpg)
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!. Private Sub cmdGo_Click... Dim strMessage As String Dim sngSum As Single If IsNumeric(txtNumber1.Text) = False.](https://reader035.fdocuments.in/reader035/viewer/2022071807/56649e935503460f94b98e90/html5/thumbnails/4.jpg)
What are the controls used for?
![Page 5: Let’s get started using Visual Basic!. Private Sub cmdGo_Click... Dim strMessage As String Dim sngSum As Single If IsNumeric(txtNumber1.Text) = False.](https://reader035.fdocuments.in/reader035/viewer/2022071807/56649e935503460f94b98e90/html5/thumbnails/5.jpg)
Open Visual Basic and Create the following program:
txtNumber1
txtNumber2
cmdgo
![Page 6: Let’s get started using Visual Basic!. Private Sub cmdGo_Click... Dim strMessage As String Dim sngSum As Single If IsNumeric(txtNumber1.Text) = False.](https://reader035.fdocuments.in/reader035/viewer/2022071807/56649e935503460f94b98e90/html5/thumbnails/6.jpg)
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!. Private Sub cmdGo_Click... Dim strMessage As String Dim sngSum As Single If IsNumeric(txtNumber1.Text) = False.](https://reader035.fdocuments.in/reader035/viewer/2022071807/56649e935503460f94b98e90/html5/thumbnails/7.jpg)
Open Visual Basic and place two command buttons on the form as shown below:
![Page 8: Let’s get started using Visual Basic!. Private Sub cmdGo_Click... Dim strMessage As String Dim sngSum As Single If IsNumeric(txtNumber1.Text) = False.](https://reader035.fdocuments.in/reader035/viewer/2022071807/56649e935503460f94b98e90/html5/thumbnails/8.jpg)
• 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!. Private Sub cmdGo_Click... Dim strMessage As String Dim sngSum As Single If IsNumeric(txtNumber1.Text) = False.](https://reader035.fdocuments.in/reader035/viewer/2022071807/56649e935503460f94b98e90/html5/thumbnails/9.jpg)
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!. Private Sub cmdGo_Click... Dim strMessage As String Dim sngSum As Single If IsNumeric(txtNumber1.Text) = False.](https://reader035.fdocuments.in/reader035/viewer/2022071807/56649e935503460f94b98e90/html5/thumbnails/10.jpg)
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!. Private Sub cmdGo_Click... Dim strMessage As String Dim sngSum As Single If IsNumeric(txtNumber1.Text) = False.](https://reader035.fdocuments.in/reader035/viewer/2022071807/56649e935503460f94b98e90/html5/thumbnails/11.jpg)
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!. Private Sub cmdGo_Click... Dim strMessage As String Dim sngSum As Single If IsNumeric(txtNumber1.Text) = False.](https://reader035.fdocuments.in/reader035/viewer/2022071807/56649e935503460f94b98e90/html5/thumbnails/12.jpg)
The Text Box! Create the following form:
![Page 13: Let’s get started using Visual Basic!. Private Sub cmdGo_Click... Dim strMessage As String Dim sngSum As Single If IsNumeric(txtNumber1.Text) = False.](https://reader035.fdocuments.in/reader035/viewer/2022071807/56649e935503460f94b98e90/html5/thumbnails/13.jpg)
• 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!. Private Sub cmdGo_Click... Dim strMessage As String Dim sngSum As Single If IsNumeric(txtNumber1.Text) = False.](https://reader035.fdocuments.in/reader035/viewer/2022071807/56649e935503460f94b98e90/html5/thumbnails/14.jpg)
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!