passing an array to a module

  • Thread starter Thread starter Erik Foreman
  • Start date Start date
E

Erik Foreman

this is what I have



'variables defined as arrays

Dim ceday(), ceti(), ceto(), ceproj(), cenotes() As String

Dim cerow As Int32

Private Sub cboEmpName_SelectedIndexChanged(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
cboEmpName.SelectedIndexChanged

Dim ename As String

cerow = 2

ename = cboEmpName.SelectedItem

EditInfo(ename, cerow, ceday(), ceti(), ceto(),ceproj () , cenotes())

'finish doing stuff

End Sub

'in another module

Public Sub EditInfo(ByVal empname As String, ByRef i As Int16, ByRef
ceday() As Array, ByRef ceti() As Array, ByRef ceto() As Array, ByRef
ceproj() As Array, ByRef cenotes() As Array)

'do stuff

i = XLObj.activesheet.Cells(1,1).currentregion.rows.count

ReDim ceday(i), ceti(i), ceto(i), ceproj(i), cenotes(i)

'do more stuff

End Sub



the arrays in Private Sub cboEmpName_SelectedIndexChanged have the ()
underlined in blue and the message is:
Number of indicies is less than the number of dimensions of the indexed
array.

Since these are all one dimension arrays I do not understand why this
error is showing up.
 
Your method EditInfo is expecting an array of Arrays while you are passing
in an array of strings. Change the definition of your method to:

Public Sub EditInfo(ByVal empname As String, ByRef i As Int16, _
ByRef ceday() As String, ByRef ceti() As String, _
ByRef ceto() As String, ByRef ceproj() As String, _
ByRef cenotes() As String)

Alternatively, you could also change it to:
Public Sub EditInfo(ByVal empname As String, ByRef i As Int16, _
ByRef ceday As Array, ByRef ceti As Array, _
ByRef ceto As Array, ByRef ceproj As Array, _
ByRef cenotes As Array)

Personally, I would go with the first one.

hope that helps..
Imran.
 
both options produce the same effect for me as what I had expressed
before. It says:
Number if indicies is less than the number of dimensions of the indexed
array.

Public Sub EditInfo(ByVal empname As String, ByRef i As Int16, ByRef
ceday() As String, ByRef ceti() As String, ByRef ceto() As String, ByRef
ceproj() As String, ByRef cenotes() As String, ByRef ceworked() As
String)


is what i have here now. the little blue line is under the () in the
line

EditInfo(ename, cerow, ceday(), ceti(), ceto(), ceproj(), cenotes(),
ceworked())

and when I hover the mouse over the () the message appears in the tool
tip box.
 
Erik,
Have you tried:

EditInfo(ename, cerow, ceday, ceti, ceto, ceproj, _
cenotes, ceworked)

Note there are no () when you pass an array as a parameter.

Hope this helps
Jay
 
You are exactly correct. Everyting works perfectly now. Thank you very
much.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top