PDA

View Full Version : Solved: Array Help!



GMan
05-20-2009, 04:36 AM
I have a procedure that collects information into an Array and then calls a procedure to attach a file using the information. I originally had the Load of data and the call to attach the file in two seperate procedures with the array defined globally. I have moved it into 1 procedure and seems to have fixed an issue with accessing the data. But know the call to attach the data is not working. Can someone tell me what I am doing wrong?


Public arFiles()
Sub Manage_Array(stProcess As String, stFileName As String, stDescription As String)
If stProcess = "Load" Then
iInst = iInst + 1
ReDim Preserve arFiles(1 To iInst)
arFiles(iInst) = Array(iRow, iCol, stFileName, stDescription)
SITForm2.lbMessage = "File " & stDescription & " has been QUEUED."
SITForm2.tbFileName = Null
SITForm2.tbDescription = Null
End If
If stProcess = "Attach" Then
iCnt = 1
Do Until iCnt > iInst
Call Attach_File(Int(arFiles(iCnt)(0)), Int(arFiles(iCnt)(1)), _
Str(arFiles(iCnt)(2)), Str(arFiles(iCnt)(3)), iInst)
iCnt = iCnt + 1
Loop
iInst = 0
ReDim arFiles(iInst)
End If
End Sub


I am receiving a "TYPE MISMATCH" on the CALL ATTACH_FILE. However, I can move the array fields to other fields and make the call using the new fields. Although this works it seems sloppy to me. The define of ATTACCH_FILE is below.

Sub Attach_File(iInvoiceRow As Integer, iCol As Integer, _
stFileName As String, stDescription As String, iTotal As Integer)

Bob Phillips
05-20-2009, 04:45 AM
Is it just because you do not declare iInst, and so it defaults to a variant but the procedure wants an integer.

GMan
05-20-2009, 07:02 AM
I was about ready to kick myself. But, I do have the iInst defined with the array. There is much more to this macro than what I have posted but was trying to get the important information. Obviously I missed a vital line.


Public iCnt As Integer
Public iInst As Integer
Public arFiles()


What I expect should work is below (but clearly is not being that I am posting the question). The orginal post above I was trying to ensure that the fields were Integers and Strings. The issue is with the arFiles references. If I change these to normal Integers and Strings or constants the code works.


Call Attach_File(arFiles(iCnt)(0), arFiles(iCnt)(1), _
arFiles(iCnt)(2), arFiles(iCnt)(3), iInst)

GMan
05-20-2009, 08:30 AM
I actually got it working. It seems that the array fields are defined as Variant/Integers and Variant/Strings. These fields are being passed to a procedure that is looking for Integers and Strings. So, with a little tweak to the Call statement it is working.


Call Attach_File((arFiles(iCnt)(0)), (arFiles(iCnt)(1)), _
(arFiles(iCnt)(2)), (arFiles(iCnt)(3)), iInst)


The way I understand this, the variables inside the parathesis are being passed to Attach_File. By adding an extra parathesis around each variable it forces an evaluation of it as an expression and makes the data conform to the expected argument type.

If anyone wants to shine some more light on this please feel free.