Solved

Slow Plot

Posted on 1998-11-17
6
248 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

 
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

Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

Question has a verified solution.

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

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

734 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