Restored from previous forum. Originally posted by freak.
Hi All,
If you get a Double LONG Value from an API procedure, and want to
display it as a string, here's a way to do it:
UPDATE: The code had a little bug, that i just corrected.
Code: Select all
Procedure.s StrDouble(lowLONG.l, hiLONG.l)
Protected buffer1.s, buffer2.s, buffer3.s, pos1.l, pos2.l, pos3.l, calc1.l, calc2.l
buffer3 = StrU(lowLONG, #PB_Long)
For pos1 = Len(StrU(hiLONG, #PB_Long)) To 1 Step -1
For pos2 = Len(StrU(-1, #PB_Long)) To 1 Step -1
calc1 = Val(Mid(StrU(hiLONG, #PB_Long), pos1, 1)) * Val(Mid(StrU(-1, #PB_Long), pos2, 1))
calc2 = (Len(StrU(hiLONG, #PB_Long)) - pos1) + (Len(StrU(-1, #PB_Long)) - pos2)
buffer1 = StrU(calc1) + Left("00000000000000000000",calc2)
buffer2 = buffer3
buffer3 = ""
calc1 = 0
If Len(buffer1) > Len(buffer2)
buffer2 = Right("00000000000000000000" + buffer2, Len(buffer1))
Else
buffer1 = Right("00000000000000000000" + buffer1, Len(buffer2))
EndIf
For pos3 = Len(buffer1) To 1 Step -1
calc1 + Val(Mid(buffer1, pos3,1)) + Val(Mid(buffer2, pos3,1))
buffer3 = Right(Str(calc1), 1)+buffer3
calc1/10
Next pos3
If calc1 > 0: buffer3 = Str(calc1) + buffer3: EndIf
Next pos2
Next pos1
While Left(buffer3,1)="0"
buffer3 = Right(buffer3, Len(buffer3) - 1)
Wend
ProcedureReturn buffer3
EndProcedure
; -----------------------------------
; Example getting the Size of Drive C
; -----------------------------------
drive.s = "C:\"
Structure _Quad
L1.l
L2.l
EndStructure
; result is off by 20 bytes... (at least on my machine)
GetDiskFreeSpaceEx_(@drive, FB._Quad, TB._Quad, TFB._Quad)
MessageRequester("Drive Size: ", StrDouble(TB\L1,TB\L2) + " Bytes",0)
;- using PB's build-in StrD... (shows the correct value)
GetDiskFreeSpaceEx_(@drive, @FBQ.q, @TBQ.q, @TFBQ.q)
MessageRequester("Drive Size: ", StrD(TBQ) + " Bytes",0)
End
Timo