' Mr. Minich
' Period 1
' Ch3Demo4
' 9/14/2000
' Purpose - This program demonstrates the use of the Str & Val functions.

Option Explicit

Private Sub Form_Activate()

' variable declaration statements ************************************************ Dim strHouseNumber As String ' house number Dim strStreet As String ' street address Dim strCity As String ' city Dim strState As String ' state abbreviation Dim strZip As String ' ZIP code Dim strNextDoorNeighbor As String ' neighbor's address Dim intTemp As Integer ' temporary value ' assignment statements ********************************************************** strHouseNumber = "630" strStreet = "Evans Ave." strCity = "Wyomissing" strState = "PA" strZip = 19610 ' This statement would cause an error: ' strNextDoorNeighbor = strHouseNumber + 1 ' since you cannot add a String to an Integer ' Instead you have to use the Val function to first turn "630" into 630. intTemp = Val(strHouseNumber) + 1 strNextDoorNeighbor = Str(intTemp) ' the two statements above could be combined into: ' strNextDoorNeighbor = Str(Val(strHouseNumber) + 1) ' eliminating the need for the intTemp variable ' displaying the output ********************************************************** frmMain.Print "Your neighbor lives at: " frmMain.Print strNextDoorNeighbor &" " & strStreet ' including blank spaces frmMain.Print strCity; ", " & strState & " " & strZip ' where appropriate End Sub ' 1. The statement strZip = 19610 does not cause a compile or run-time error ' but the programmer should have been more careful. Rewrite the statement. ' 2. Do you think the variable intTemp should be used or not? Explain why or why not in an ' essay on the back of this paper. ' 3. Actually VB permits a programmer to avoid using the Val and Str functions in some ' situations. Explain why it is dangerous to rely on this aspect of VB in an essay.