Variable declaration is required with Option Explicit and a module level variable (answer) is declared. : Variable Declaration « Language Basics « VBA / Excel / Access / Word






Variable declaration is required with Option Explicit and a module level variable (answer) is declared.

 
Option Explicit
Dim answer As Integer
Sub Main()
   Dim num1 As Integer
   Dim num2 As Integer
   num1 = Val(InputBox("Please enter the first addend", "First Addend"))
   num2 = Val(InputBox("Please enter the second addend", "Second Addend"))
   Call AddUserInput(num1, num2)
   SendResult
End Sub
Private Sub AddUserInput(num1 As Integer, num2 As Integer)
    answer = num1 + num2
End Sub
Private Sub SendResult()
    MsgBox ("The answer is " & Str(answer))
End Sub

 








Related examples in the same category

1.Declaring Variables
2.To declare a variable in VBA use the Dim (short for Dimension) statement.
3.Forcing Declaration of Variables: Option Explicit
4.If you're going to declare multiple variables on one line, make sure each variable is specifically declared
5.Variables can also be declared in the declarations section at the top of a module