AddArray of unsigned integers in VB6

TeeChart for ActiveX, COM and ASP
Post Reply
Sinna
Newbie
Newbie
Posts: 9
Joined: Mon May 21, 2001 4:00 am
Location: Belgium

AddArray of unsigned integers in VB6

Post by Sinna » Tue Jan 27, 2004 11:24 am

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

Christopher
Site Admin
Site Admin
Posts: 1349
Joined: Thu Jan 01, 1970 12:00 am
Location: Riudellots de la Selva, Catalonia
Contact:

Post by Christopher » Fri Jan 30, 2004 11:20 am

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 ?
Thank you!

Christopher Ireland (Steema crew)
Please be aware of the newsgroup archives:
http://www.teechart.net/support/search.php
http://groups.google.com
http://codenewsfast.com/

Sinna
Newbie
Newbie
Posts: 9
Joined: Mon May 21, 2001 4:00 am
Location: Belgium

Post by Sinna » Mon Feb 02, 2004 8:27 am

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

Christopher
Site Admin
Site Admin
Posts: 1349
Joined: Thu Jan 01, 1970 12:00 am
Location: Riudellots de la Selva, Catalonia
Contact:

Post by Christopher » Mon Feb 02, 2004 9:39 am

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.
Thank you!

Christopher Ireland (Steema crew)
Please be aware of the newsgroup archives:
http://www.teechart.net/support/search.php
http://groups.google.com
http://codenewsfast.com/

Sinna
Newbie
Newbie
Posts: 9
Joined: Mon May 21, 2001 4:00 am
Location: Belgium

Post by Sinna » Mon Feb 02, 2004 2:16 pm

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

Christopher
Site Admin
Site Admin
Posts: 1349
Joined: Thu Jan 01, 1970 12:00 am
Location: Riudellots de la Selva, Catalonia
Contact:

Post by Christopher » Tue Feb 03, 2004 4:39 pm

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.
Thank you!

Christopher Ireland (Steema crew)
Please be aware of the newsgroup archives:
http://www.teechart.net/support/search.php
http://groups.google.com
http://codenewsfast.com/

Sinna
Newbie
Newbie
Posts: 9
Joined: Mon May 21, 2001 4:00 am
Location: Belgium

FYI: Convert Unsigned Integer Array to Long Array

Post by Sinna » Thu Feb 05, 2004 8:28 am

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.

Post Reply