Method 1 – pass the whole array ByVal so that the procedure handles the entire array
Option Explicit
Private Sub CmdStart_Click()
'Set up variables
Dim multiple As Integer
Dim answers(12) As Integer 'Array of 12 numbers
'Get Multiplier from user
Call GetValue(multiple)
'Calculate Answers
Call CalcAnswer(answers(), multiple)
'Display table
Call DisplayTable(answers(), multiple)
End Sub
Private Sub GetValue(ByRef intvalue As Integer)
intvalue = InputBox("Please enter the value")
End Sub
Private Sub DisplayTable(ByRef answers() As Integer, ByVal multiple)
Dim counter As Integer
Dim Answer As Integer
For counter = 1 To 12
lstOutput.AddItem multiple & " X " & counter & " = " & answers(counter)
Next
End Sub
Private Sub CalcAnswer(ByRef answers() As Integer, ByVal multiple)
Dim counter As Integer
For counter = 1 To 12
answers(counter) = multiple * counter
Next
End Sub
Method 2 – Pass a single item of the array so that the procedure only handles integers
Option Explicit
Private Sub CmdStart_Click()
'Set up variables
Dim Multiple As Integer
Dim counter As Integer
Dim Answers(12) As Integer 'Array of 12 numbers
'Get Multiplier from user
Call GetValue(Multiple)
For counter = 1 To 12
'Calculate Answers
Call CalcAnswer(Answers(counter), Multiple, counter)
'Display table
Call DisplayTable(Answers(counter), Multiple, counter)
Next
End Sub
Private Sub GetValue(ByRef intvalue As Integer)
intvalue = InputBox("Please enter the value")
End Sub
Private Sub DisplayTable(ByVal Answer, ByVal Multiple, ByVal counter)
lstOutput.AddItem Multiple & " X " & counter & " = " & Answer
End Sub
Private Sub CalcAnswer(ByRef Answer As Integer, ByVal Multiple, ByVal counter)
Answer = Multiple * counter
End Sub
Both methods have their uses and differing programs call for differing strategies.