No announcement yet.

UDT, Strings and Pointers. . .

  • Filter
  • Time
  • Show
Clear All
new posts

  • UDT, Strings and Pointers. . .

    Is it OK to change this:

    Type myudt
    lweapon(1 to 10) As Long
    sweapon(1 to 20) As Long
    End Type
    Global tt As myudt
    Dim i As Long
    For i = 1 to 20
    tt.sweapon(i) = tt.sweapon(i) + 1
    Next i

    To This:

    Type myudt
    lweaponS As String * 40
    sweaponS As String * 80
    End Type
    Global tt As myudt

    And then access the data like this:

    Dim vPTR As Long PTR
    Dim i As Long
    vPTR = VARPTR(tt.sweaponS)
    For i = 1 To 20
    @vPTR[i - 1] = @vPTR[i - 1] + 1
    Next i

    Did I break any written or unwritten power basic programming rules?

    My program that I am doing this in runs great, I am unable to detect
    any errors. I have just never used pointers like that before, it looks
    a little wierd, is it OK?

    Tim Wisseman
    [email protected]

    [This message has been edited by Tim Wisseman (edited January 08, 2000).]

  • #2
    Tim --
    "it looks a little wierd"

    I have a binary file, which includes different arrays of different types. Dimension is variable and I can't declare Type or to do like in VB Get array.
    So I read information into fixed-length(!) String and use pointers similar you:
    DefInt A-Z
    Dim IntegerPtr As Double Ptr
    Dim SinglePtr As Single Ptr
    Dim DoublePtr As Double Ptr
    %LenTmpBuffer = 512
    Dim TmpBuffer As String * %LenTmpBuffer
    PosMaxTmpBuffer& = VarPtr(TmpBuffer) + %LenTmpBuffer
    IntegerPtr = PosMaxTmpBuffer&
    Dim mdir(0 To n)

    For i = 0 To n
    If IntegerPtr >= PosMaxTmpBuffer& Then Get #1, , TmpBuffer: IntegerPtr = VarPtr(TmpBuffer)
    mdir(i) = @IntegerPtr: IntegerPtr = IntegerPtr + 2

    Also looks more than strange, but works.