Solved

Slow Plot

Posted on 1998-11-17
6
231 Views
Last Modified: 2010-05-18
I've created a control which basically just draws a trace according to data supplied to it.  It does this using the line(x1,y1)-(x2,y2) function.
Basic problem - it's slow.  I may have up to 32 of these updating continuously in my project, and with the possibility of 1000 data points - this can mean drawing tens of thousands of lines in each iteration - which I want to happen once every two seconds or so.

So, what can anybody suggest?  Is there a better way of drawing these lines which goes faster?  I was hoping I may be able to get each instance of my control to work in parallel using multithreading, but I can't figure it out.

Cheers-
Rob
0
Comment
Question by:robholden
6 Comments
 
LVL 2

Expert Comment

by:kswinney
ID: 1445220
You can use the API calls "MoveTo" and "LineTo" which will draw significantly faster than VB's line method... but you might also try "Polygon" which will draw several line segments at once.

HTH.
0
 

Author Comment

by:robholden
ID: 1445221
I found LineTo and MoveToEx in the WIN32API.  However I can't seem to get them to work.  The API seems to have loads of graphics type calls, its quite overwhelming.  Could you post a bit of sample code to give me a starting point please?

Cheers
0
 

Author Comment

by:robholden
ID: 1445222
Ok, anybody else got any ideas?
0
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 
LVL 1

Expert Comment

by:muffinthedog
ID: 1445223
Seems you might be able to use a memory DC and just BitBlt or StretchBlt it to where ever. Have some old code somewhere (not for a plot though) if you would like... May B write a leetle Dee el el function, pass an array and a hwnd, and have it update the window?
0
 
LVL 1

Accepted Solution

by:
javierma earned 100 total points
ID: 1445224
        I'd try using the API function Polyline. It's easy to do:
1) Declare the function in a module (just paste this)
Type POINTAPI
     x As Long
     y As Long
End Type
Declare Function Polyline& Lib "gdi32" (ByVal hdc As Long, lpPoint As POINTAPI, ByVal nCount As Long)

2) Create a POINTAPI vector to store your points: (10 for example)
Dim ptVector(1 to 10) as POINTAPI

3) Call the function telling it how many points from that vector are you going to paint.
If you're going to paint in a form then hdc = MyForm.hdc; if on a PictureBox hdc = MyPicture.hdc; or if on a printer hdc = Printer.hdc
Dim Foo as Long
foo = Polyline(hdc , ptVector(1) , 10 )

You're all set. If foo = 0 it means that the function failed, otherwise it worked.

                  Javier Martinez

0
 

Author Comment

by:robholden
ID: 1445225
I like this solution - it is seriously fast.

Cheers-
Rob
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
VBS file using code from 2nd file (txt or vbs) 4 42
Excel Automation VBA 19 88
VBA - If Bookmark = "XXBOOKMARKXX" then 15 40
backup program with robocopy 6 42
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…

808 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question