Presentation is loading. Please wait.

Presentation is loading. Please wait.

Adding Code to the Option Button. Open VB 1.Double click the Calculate button and select General from the Object list box. 2.Add the following code to.

Similar presentations


Presentation on theme: "Adding Code to the Option Button. Open VB 1.Double click the Calculate button and select General from the Object list box. 2.Add the following code to."— Presentation transcript:

1 Adding Code to the Option Button

2 Open VB 1.Double click the Calculate button and select General from the Object list box. 2.Add the following code to create two form-level variables: Option Explicit Dim sngPlanetWeight As Single Dim strPlanetName As String

3 3.Select optMars from the Object list box and add the following code: sngPlanetWeight = 0.38 strPlanetName = “Mars” 4.Select obtJupiter from the Object list box and add the following: sngPlanetWeight = 2.64 strPlanetName = “Jupiter”

4 5.Select optSaturn from the Object list box and enter: sngPlanetWeight = 1.15 strPlanetName = “Saturn” 6.Select optPluto from the Object list box and enter: sngPlanetWeight = 0.04 strPlanetName = “Pluto”

5 The final step is to calculate the result and create the output. 7.Double-click the Calculate button and add the following code: Dim intWeight As Integer Dim strWeight As String ‘Calculate Weight intWeight = Fix(sngPlanetWeight * Val(txtWeight.text)) strWeight = Format(intWeight, “####”)

6 8. The following code will display the results in the caption of the lblOutput label. ‘Display Output lblOutput.Caption = “Your weight on “ & strPlanetName _ & “would be “ & strWeight & “pounds.”

7 9.Run the program. 10.Enter 150 into the text box. 11.Click the Jupiter option button and click the Calculate button. 12. Click each of the other option buttons and the Calculate button to test them. 13.The answer should change each time. 14.End the program and save your changes.

8 Homework: Answer True or False for the following: 1.___ Only one option button in a group can be selected. 2.___ The first option button you place on a form automatically creates a frame in which you can place other option buttons. 3.___ The controls you place inside a frame are treated as one unit. 4.___ Drawing option buttons in a frame will automatically associate them with that frame. 5.___ The first option button you add to a form will be selected by default when you run the program.


Download ppt "Adding Code to the Option Button. Open VB 1.Double click the Calculate button and select General from the Object list box. 2.Add the following code to."

Similar presentations


Ads by Google