0

Firstly apologies for this extremely vague post. We have a macro that is very old, was built by someone who has since left the organisation and it is unfortunately beyond my capabilities. It takes in various csv files and creates notepad outputs.

We are upgrading to 365 and it fails. It is breaking on the VarPtr(pPrim) below due to a Type Mismatch:

    Dim pPrim As tPrim
    Public Sub initLoad()
          DataCopy String(Len(pPrim) / 2, " "), VarPtr(pPrim)
    End Sub

tPrim relates to this:

    Private Type tPrim
      WS_PRIM_I_SEC(31) As Byte
      Filler1(19) As Byte
      WS_PRIM_I_CUSIP(17) As Byte
      Filler2(19) As Byte
      WS_PRIM_I_SYM(31) As Byte
      Filler3(19) As Byte
      WS_PRIM_I_NAV(37) As Byte  ' 12N6
      Filler4(19) As Byte
      WS_PRIM_I_SRC(15) As Byte
      Filler5(19) As Byte
      WS_PRIM_I_STA(15) As Byte
      FILLER6(1) As Byte
      WS_PRIM_I_UFLAG(9) As Byte
      FILLER7(7) As Byte
      WS_PRIM_I_COB_DT(19) As Byte
      FILLER8(19) As Byte
      WS_PRIM_I_DIV(35) As Byte
      FILLER9(19) As Byte
      WS_PRIM_I_DIV_DT(19) As Byte
      FILLER10(19) As Byte
      WS_PRIM_I_DIV_DIST(7) As Byte
      FILLER11(19) As Byte
      WS_PRIM_I_CDIV(35) As Byte
      FILLER12(999) As Byte
    End Type

I honestly don't know if there is enough information here to enable anyone to help, but there is a huge amount of code in the workbook so it's difficult to post it all.

Addition

The code relating to DataCopy is:

Private Sub DataCopy(value$, toMem&)

      Dim myBuff() As Byte
    
      If value = "" Then Exit Sub
      
      myBuff = value
      CopyMemory ByVal toMem, myBuff(0), UBound(myBuff) + 1
    End Sub
JohnM
  • 2,422
  • 2
  • 8
  • 20
xceej
  • 159
  • 1
  • 1
  • 7
  • 1
    Have you possibly changed from 32 to 64 bit Office? Can you include in your question the signature of the `DataCopy` method. – JohnM Aug 25 '23 at 15:39
  • from googling VarPtr I believe it is a 32 vs 64 bit question, and yes we have upgraded to that. When I hover over DataCopy it says: myBuff(0)=32 – xceej Aug 25 '23 at 15:42
  • 1
    Is the 2nd parameter of DataCopy a Long? If so, change to LongPtr ... though you may then find the need to change other code to also work with the LongPtr – JohnM Aug 25 '23 at 15:43
  • I've added the DataCopy code to the original post – xceej Aug 25 '23 at 15:44
  • 1
    Highly suggest you [ditch the type hints](https://stackoverflow.com/a/41044332) `$` and `&`. That's an archaic practice. – BigBen Aug 25 '23 at 15:46
  • Archaic would make sense, as this macro has been around for years. But that worked, thanks for the hint! Now on to the next place it breaks.... Thanks for the help – xceej Aug 25 '23 at 15:51

0 Answers0