Consulting

Results 1 to 4 of 4

Thread: Solved: Array Help!

  1. #1
    VBAX Regular
    Joined
    Nov 2005
    Posts
    39
    Location

    Solved: Array Help!

    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?

    [vba]
    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
    [/vba]

    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.

    [vba]Sub Attach_File(iInvoiceRow As Integer, iCol As Integer, _
    stFileName As String, stDescription As String, iTotal As Integer)[/vba]

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Is it just because you do not declare iInst, and so it defaults to a variant but the procedure wants an integer.
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  3. #3
    VBAX Regular
    Joined
    Nov 2005
    Posts
    39
    Location
    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.

    [vba]
    Public iCnt As Integer
    Public iInst As Integer
    Public arFiles()
    [/vba]

    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.

    [vba]
    Call Attach_File(arFiles(iCnt)(0), arFiles(iCnt)(1), _
    arFiles(iCnt)(2), arFiles(iCnt)(3), iInst)
    [/vba]

  4. #4
    VBAX Regular
    Joined
    Nov 2005
    Posts
    39
    Location
    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.

    [vba]
    Call Attach_File((arFiles(iCnt)(0)), (arFiles(iCnt)(1)), _
    (arFiles(iCnt)(2)), (arFiles(iCnt)(3)), iInst)
    [/vba]

    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •