I am having an issue with passing an array to a sub (receiving type mismatch: array or user-defined type expected). I have worked with array structures in other languages and I must be missing something here in vba since I can't get this to work. I have posted code snippets below for comment:
Private Sub x()
Dim ssn_vals(1 To 9) As String
Dim ssn_cells(1 To 9) As String
'define employee object
Dim emp As Employee
'create new employee foreach row
Set emp = New Employee
'ssn values
ssn_vals(1) = cell.Offset(0, 60)
ssn_vals(2) = cell.Offset(0, 61)
ssn_vals(3) = cell.Offset(0, 62)
ssn_vals(4) = cell.Offset(0, 63)
ssn_vals(5) = cell.Offset(0, 64)
ssn_vals(6) = cell.Offset(0, 65)
ssn_vals(7) = cell.Offset(0, 66)
ssn_vals(8) = cell.Offset(0, 67)
ssn_vals(9) = cell.Offset(0, 68)
'ssn cell addresses
ssn_cells(1) = cell.Offset(0, 60).Address
ssn_cells(2) = cell.Offset(0, 61).Address
ssn_cells(3) = cell.Offset(0, 62).Address
ssn_cells(4) = cell.Offset(0, 63).Address
ssn_cells(5) = cell.Offset(0, 64).Address
ssn_cells(6) = cell.Offset(0, 65).Address
ssn_cells(7) = cell.Offset(0, 66).Address
ssn_cells(8) = cell.Offset(0, 67).Address
ssn_cells(9) = cell.Offset(0, 68).Address
emp.setSSN = ssn_vals
emp.setSSN_cells = ssn_cells
'validate ssn
emp.validateSSN (ssn_vals)
end sub
i have a sub defined inside employee class
'validate SSN
Public Sub validateSSN(ssn() As Variant)
Dim i As Integer
'Dim orig_array(1 To 9) As Variant
Dim multipler_array(1 To 9) As Integer
Dim summation_array(1 To 9) As Integer
multipler_array(1) = 1
multipler_array(2) = 2
multipler_array(3) = 1
multipler_array(4) = 2
multipler_array(5) = 1
multipler_array(6) = 2
multipler_array(7) = 1
multipler_array(8) = 2
multipler_array(9) = 1
If Me.getSinOrT = "sin" Then
For i = LBound(ssn(i)) To UBound(ssn(i))
summation_array(i) = (Int(ssn(i)) * Int(multipler_array(i)))
Debug.Print summation_array(i)
Next i
Else
End If
End Sub
Any suggestions on how to fix this trivial thing would be greatly appreciated. Thanks in advance, Michael
You are using cell as a Range, but have not Dim 'ed it or Set it. There may be other problems
thank you for the useful comments - this had made me realize that I didn't have to pass ssn array again to employee object, since its data was saved inside Employee already. To correct issue I created a method within Employee that verified SIN based on an Employee's existing SIN. Thanks a bunch...
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.