what I'm doing Wrong 
Author Message
 what I'm doing Wrong

Quote:
> Try this
> di = Polyline(Picture1.hDC, pts(0), ubound(pts(0))

> You start with pts=1
> At the end Pts=ubound(pts(0))+1

The upper bound of a 0-bound array is one less than the number of items in
the array:

'***
Dim Pts(0) As PointAPI
'***

This gives you an array of 1 item but the UBound is 0.  Also, you're trying
to find the upper bound of a single element in the array (I presume a typo,
but just in case) which is raise an error, you want to send the array
itself:

'***
di = Polyline(Picture1.hDC, pts(0), ubound(pts()) + 1)
'***

AFAIK though the original count should be correct but it's worth trying.
Be aware though that the PolyLine() API call requires the coordinates to be
in Pixels so if you're sending the coordinates as Twips then you'll need to
convert them using one of the following methods:

'***
pts(n).X = ScaleX(pts(n).X, vbTwips, vbPixels)
pts(n).Y = ScaleY(pts(n).Y, vbTwips, vbPixels)
'***

Or

'***
pts(n).X = pts(n).X \ Screen.TwipsPerPixelX
pts(n).Y = pts(n).Y \ Screen.TwipsPerPixelY
'***

Hope this helps,

    Mike

 -- EDais --

 - Microsoft Visual Basic MVP -
WWW: http://www.*-*-*.com/




Wed, 20 Jul 2005 03:21:28 GMT  
 what I'm doing Wrong

Quote:

>Hi,
>Try this
>di = Polyline(Picture1.hDC, pts(0), ubound(pts(0))

>You start with pts=1
>At the end Pts=ubound(pts(0))+1

>Chrsitophe

Sorry, but that has absolutely nothing to do with it. I start with points=0.
UBound is fixed at 500 points. The actual wave will usually have far fewer
transtiions. (75-150) The procedure plots perfectly with the VB Line method
using the same point array.

---
http://www.laser.com/dhouston/



Wed, 20 Jul 2005 03:54:59 GMT  
 what I'm doing Wrong
No it is not.

The entire Sub is quite a bit longer than the snippet that I posted. I felt
all the massaging of the .wav data would only confuse the issue.

At the top of the Sub I...

  Dim pts(0 To 500)    As POINTAPI

I create pts(0) & pts(1) before entering the For/Next loop. The For/Next
loop finds transitions from 255 to 128 & vice versa and creates a point for
each, incrementing nPts with each inflection. Most codes end with some
period of silence so there is no inflection point. After exiting the
For/Next loop, I increment nPts and create this last point.

Again, the routine plots perfectly using the VB Line method and the same
point array. I am not plotting from 0 to UBound but only from 0 to nPts.

Quote:

>Excuses
>di = Polyline(Picture1.hDC, pts(0), ubound(pts))
>At the end Pts=ubound(pts)+1



>> Hi,
>> Try this
>> di = Polyline(Picture1.hDC, pts(0), ubound(pts(0))

>> You start with pts=1
>> At the end Pts=ubound(pts(0))+1

>> Chrsitophe

---
http://www.laser.com/dhouston/


Wed, 20 Jul 2005 04:15:51 GMT  
 what I'm doing Wrong

Quote:
> Sorry, but that has absolutely nothing to do with it. I start with
points=0.
> UBound is fixed at 500 points. The actual wave will usually have far fewer
> transtiions. (75-150) The procedure plots perfectly with the VB Line
method
> using the same point array.

Are you using adjusting any of the Scale* properties of the canvas you're
drawing on?  Also, make sure your API declares are correct, you could for
instance be storing the coordinates as integers or something - Unfortunately
"I get garbage in the picture box." isn't particularly descriptive, there
must be some logical relationship between what you send it and what's drawn.
Here's the API calls:

'***
Private Declare Function Polyline Lib "gdi32" (ByVal hDC As Long, _
    ByRef lpPoint As PointAPI, ByVal nCount As Long) As Long

Private Type PointAPI
    X As Long
    Y As Long
End Type
'***

Here's an example application, see if that works:

'***
Private Sub Form_Paint()
    Dim PtArr(99) As PointAPI
    Dim GenPts As Long

    Const Pi = 3.14159

    Form1.Cls
    Form1.ScaleMode = vbPixels

    For GenPts = 0 To 99
        PtArr(GenPts).X = (GenPts / 99) * Form1.ScaleWidth
        PtArr(GenPts).Y = (Sin((GenPts / 50) * Pi) + 1) * (Form1.ScaleHeight
\ 2)
    Next GenPts

    Call Polyline(Form1.hDC, PtArr(0), 100)
End Sub
'***

Hope this helps,

    Mike

 -- EDais --

 - Microsoft Visual Basic MVP -
WWW: Http://EDais.earlsoft.co.uk/




Wed, 20 Jul 2005 04:09:22 GMT  
 what I'm doing Wrong

Quote:
>The upper bound of a 0-bound array is one less than the number of items in
>the array:

>'***
>Dim Pts(0) As PointAPI
>'***

>This gives you an array of 1 item but the UBound is 0.  Also, you're trying
>to find the upper bound of a single element in the array (I presume a typo,
>but just in case) which is raise an error, you want to send the array
>itself:

>'***
>di = Polyline(Picture1.hDC, pts(0), ubound(pts()) + 1)
>'***

>AFAIK though the original count should be correct but it's worth trying.
>Be aware though that the PolyLine() API call requires the coordinates to be
>in Pixels so if you're sending the coordinates as Twips then you'll need to
>convert them using one of the following methods:

>'***
>pts(n).X = ScaleX(pts(n).X, vbTwips, vbPixels)
>pts(n).Y = ScaleY(pts(n).Y, vbTwips, vbPixels)
>'***

>Or

>'***
>pts(n).X = pts(n).X \ Screen.TwipsPerPixelX
>pts(n).Y = pts(n).Y \ Screen.TwipsPerPixelY
>'***

>Hope this helps,

I am sending the points to Polyline as pixels. At the very top of the code
snippet, before any points are calculated, is...

     Picture1.ScaleMode = 3

And all of the calculations are made after that as percentages of the
ScaleWidth and ScaleHeight with the result converted to Integers. A
debug.print dump of all the array points shows them to be in pixels and to
all lie within the Picture box. They plot perfectly using the same array and
the VB Line method.

---
http://www.laser.com/dhouston/



Wed, 20 Jul 2005 04:23:28 GMT  
 what I'm doing Wrong
My Declares for Polyline and for Type PointAPI are identical to yours.

I've uploaded a .jpg showing the output to my web page. See...

     http://www.laser.com/dhouston/garbage.jpg

The black plot is from the VB Line method while the red plot is what
Polyline plots with the same array.

If you look at the code section I posted in my original message you can see
exactly what I'm doing. I think everything is scaled correctly. As I noted,
the debug.print output of all the points is as expected. I'm sure there's
something I'm doing or something I'm not doing that's causing this but I
cannot see what it is. I patterned this after examples in Appleman's API
book and Rod Stephens VB Graphics book. I'm using VB4-32.

I'll try your example but it would help me more if it drew on a Picture box.
Mine is 6195 x 480 twips or 413 x 32 pixels.


Quote:
>Are you using adjusting any of the Scale* properties of the canvas you're
>drawing on?  Also, make sure your API declares are correct, you could for
>instance be storing the coordinates as integers or something - Unfortunately
>"I get garbage in the picture box." isn't particularly descriptive, there
>must be some logical relationship between what you send it and what's drawn.
>Here's the API calls:

>'***
>Private Declare Function Polyline Lib "gdi32" (ByVal hDC As Long, _
>    ByRef lpPoint As PointAPI, ByVal nCount As Long) As Long

>Private Type PointAPI
>    X As Long
>    Y As Long
>End Type
>'***

>Here's an example application, see if that works:

>'***
>Private Sub Form_Paint()
>    Dim PtArr(99) As PointAPI
>    Dim GenPts As Long

>    Const Pi = 3.14159

>    Form1.Cls
>    Form1.ScaleMode = vbPixels

>    For GenPts = 0 To 99
>        PtArr(GenPts).X = (GenPts / 99) * Form1.ScaleWidth
>        PtArr(GenPts).Y = (Sin((GenPts / 50) * Pi) + 1) * (Form1.ScaleHeight
>\ 2)
>    Next GenPts

>    Call Polyline(Form1.hDC, PtArr(0), 100)
>End Sub
>'***

>Hope this helps,

>    Mike

> -- EDais --

> - Microsoft Visual Basic MVP -
>WWW: Http://EDais.earlsoft.co.uk/



---
http://www.laser.com/dhouston/


Wed, 20 Jul 2005 05:56:39 GMT  
 what I'm doing Wrong

Quote:
>Private Type PointAPI
>    X As Long
>    Y As Long
>End Type

Dang!

I must have pasted the Type PointAPI declaration from a 16-bit program. I
was storing them as integers which did not bother the VB Line method but
screwed up the Polyline function. I had looked at everything several times
and did not catch that.

Thank you for your help and patience. It works fine now and I can get on
with the rest of my coding.
---
http://www.laser.com/dhouston/



Wed, 20 Jul 2005 06:11:32 GMT  
 what I'm doing Wrong

Quote:
> I must have pasted the Type PointAPI declaration from a 16-bit program. I
> was storing them as integers which did not bother the VB Line method but
> screwed up the Polyline function. I had looked at everything several times
> and did not catch that.

Yep, when the Line() method is passed integer coordinates it will perform a
CSng() behind the scenes (Since it expects Singles) then feed the method
with those.  When you're working with the API and passing an array of
objects, it doesn't know what the VB type looks like, it simply looks at the
memory.  The 16-bit version will store the value like this:

0xYYYYXXXX

The 32-bit version looks like this:

0xYYYYYYYYXXXXXXXX

As such, when you pass your array of 16-bit Points to a routine looking for
32-bit Points it gets confused:

Point[0].x = YYYYXXXX
Point[0].y = YYYYXXXX

The coordinates are fused together into a single 32-bit integer (Most likely
huge since if the Y coordinate stores anything then it's going to be
multiplied by 0x10000! - This is why the graph was always being drawn off
the picture box)
When you pass the 32-bit version to the routine then it reads then as
expected:

Point[0].x = XXXXXXXX
Point[0].y = YYYYYYYY

Quote:
> Thank you for your help and patience. It works fine now and I can get on
> with the rest of my coding.

You're welcome,

    Mike

 -- EDais --

 - Microsoft Visual Basic MVP -
WWW: Http://EDais.earlsoft.co.uk/




Wed, 20 Jul 2005 06:25:15 GMT  
 
 [ 8 post ] 

 Relevant Pages 

1. what i'm doing wrong?

2. What i'm doing wrong?

3. Can't figure out what I'm doing wrong. Check to see if last character is a /

4. Does anyone know what I'm doing wrong?

5. Help... What I'm doing wrong?

6. Does anyone know what I'm doing wrong?

7. can anyone tell me what i'm doing wrong???

8. Can someone tell me what I'm doing wrong?

9. Obviously I'm doing something wrong!

10. ADO thinks DBMS is done, but DBMS ain't done

11. Recordset: What am I doing wrong?

12. What am I doing wrong??

 

 
Powered by phpBB® Forum Software