O'Reilly logo

Beginning Microsoft® Visual Basic® 2008 by Bryan Newsome, Thearon Willis

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Appendix A. Exercise Solutions

  1. Create a Windows Application with a Textbox and Button control that will display whatever is typed in the text box when the user clicks on the button.

    1. To display the text from a text box on a form when the user clicks the button, you add code as highlighted here to the button's Click event handler:

      Private Sub btnDisplay_Click(ByVal sender As System.Object, _
          ByVal e As System.EventArgs) Handles btnDisplay.Click
      
          'Display the contents of the text box
          MessageBox.Show(txtInput.Text, "Exercise 1")
      End Sub
  1. Create a Windows application with two button controls. In the Click event for the first button, declare two Integer variables and set their values to any number that you like. Perform any math operation on these variables and display the results in a message box.

    In the Click event for the second button, declare two String variables and set their values to anything that you like. Perform a string concatenation on these variables and display the results in a message box.

    1. The first part of this exercise requires you to declare two Integer variables and set their values and then to perform a math operation of these variables and display the results in a message box. The variables can be declared and set as:

      'Declare variables and set their values
      Dim intX As Integer = 5
      Dim intY As Integer = 10

      To perform a math operation and display the results can be performed as:

      'Multiply the numbers and display the results MessageBox.Show("The sum of " & intX.ToString ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required