Page 1 of 1

AddArray of unsigned integers in VB6

Posted: Tue Jan 27, 2004 11:24 am
by 6919150
How can I force TeeChart to draw a graph with unsigned integer values in Visual Basic 6?

If I write

Code: Select all

Call Profile.Series(0).AddArray(mValuesCount, mLastProfileValues)
with mLastProfileValues an array of unsigned integers, the graph is drawn as it were signed integers.

Converting the unsigned integers to longs is not really an option (quite slow).


TIA

Posted: Fri Jan 30, 2004 11:20 am
by Chris
Hi --
How can I force TeeChart to draw a graph with unsigned integer values in Visual Basic 6?
Have you read the article on:

http://support.microsoft.com/default.as ... bContent=1 ?

Posted: Mon Feb 02, 2004 8:27 am
by 6919150
Yes, I read the article and use the conversion methods as mentioned (but optimized by using APIs)

So, the array of integers I pass to the TeeChart control, is in fact an array of unsigned integers.

I know I could convert all the unsigned integers to longs and pass the array of longs to the TeeChart Control, but I want to avoid that (takes quite some time to get them converted).

That's why I posted the question to know if it is possible to let TeeChart Control interprete the array of integers as unsigned integers.


Sinna

Posted: Mon Feb 02, 2004 9:39 am
by Chris
Hi Sinna,
That's why I posted the question to know if it is possible to let TeeChart Control interprete the array of integers as unsigned integers.
Have you tried passing unsigned integer arrays to TeeChart's AddArray()
method? What happens when you do? If it is not possible to do so then I'm
afraid I can't offer you a solution to this problem.

Posted: Mon Feb 02, 2004 2:16 pm
by 6919150
If I pass the array to the TeeChart Control, the control plots them signed.
So, if I have a value of say 33000, it is plotted -233, 32800 becomes -33.


Sinna

Posted: Tue Feb 03, 2004 4:39 pm
by Chris
Hi --
If I pass the array to the TeeChart Control, the control plots them signed.
So, if I have a value of say 33000, it is plotted -233, 32800 becomes -33.
Mmm, in this case, I'm afraid, you will have to make the conversion before passing the values to the TeeChart Control.

FYI: Convert Unsigned Integer Array to Long Array

Posted: Thu Feb 05, 2004 8:28 am
by 6919150
Since TeeChart Control interpretes arrays of unsigned integer values as integer values, you have to convert the array to long.

To achieve this, you can use the following code (which is significantly faster than the conversion methods in the KB of the MSDN Library):

Code: Select all

Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (pDst As Any, pSrc As Any, ByVal ByteLen As Long)

Private Function UIntArray2Long(uintArray() As Integer) As Long()
    Dim lngArray() As Long, lBnd As Long, uBnd As Long, lElem As Long
    
    On Error Resume Next
        lBnd = LBound(uintArray)
        uBnd = UBound(uintArray)
    On Error GoTo 0
    
    If lBnd = 0 And uBnd = 0 Then Exit Function
    
    ReDim lngArray(lBnd To uBnd) As Long
    
    For lElem = lBnd To uBnd
        CopyMemory lngArray(lElem), uintArray(lElem), 2
    Next lElem
    
    UIntArray2Long = lngArray
End Function
Note that if you assign an unsigned integer value to a long, VB correctly converts it, so the value remains signed. That's why the MSDN Article mentioned in a previous post has to do additional operations to have an unsigned value.