Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Speed: Need more!

Posted on 1998-11-17
3
Medium Priority
?
150 Views
Last Modified: 2010-05-03
I have a quite large loop in my program and want to increase the speed at which it runs... Is there any way to do this? The code is below. Although you might want to copy it into wordpad... It may be hard to read otherwise. All varables are delcared as best and small as they could be. Thanks!


For xnow = 0 To XMAPSHOWN * (tile_width + 2) Step tile_width
tilex = tilex + 1
tiley = ycord
For ynow = 0 To ymapshown * (tile_Height + 2) Step tile_Height
tilenow = map(tilex, tiley).land1

If tilenow < 1000 Then GoTo no_draw
If tilenow >= 1000 And tilenow <= 1225 Then page = 1
If tilenow >= 2000 And tilenow <= 2225 Then page = 2
If tilenow >= 3000 And tilenow <= 3225 Then page = 3
If tilenow >= 4000 And tilenow <= 4225 Then page = 4
If tilenow >= 5000 And tilenow <= 5225 Then page = 5
If tilenow >= 6000 And tilenow <= 6225 Then page = 6
If tilenow >= 7000 And tilenow <= 7225 Then page = 7
If tilenow >= 8000 And tilenow <= 8225 Then page = 8
If tilenow >= 9000 And tilenow <= 9225 Then page = 9

tile = (tilenow - (page * 1000)) - 1
i = BitBlt(mapeditor.Picture1.hdc, xnow, ynow, tile_width, tile_Height, Graphics.Graphics_pages(page + 9).hdc, ((tile Mod temtiles_ud) * (tile_width + 2)) + 1, ((tile \ temtiles_rl) * (tile_Height + 2)) + 1, SRCAND)
i = BitBlt(mapeditor.Picture1.hdc, xnow, ynow, tile_width, tile_Height, Graphics.Graphics_pages(page).hdc, ((tile Mod temtiles_ud) * (tile_width + 2)) + 1, ((tile \ temtiles_rl) * (tile_Height + 2)) + 1, SRCINVERT)
no_draw:

tiley = tiley + 1
Next ynow
Next xnow
Exit Sub
0
Comment
Question by:testing38
[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
3 Comments
 
LVL 5

Accepted Solution

by:
scrapdog earned 200 total points
ID: 1445338
c1 = (tile_height + 2) / temtiles_rl
c2 = (tile_width + 2)

For xnow = 0 To XMAPSHOWN * (tile_width + 2) Step tile_width
tilex = tilex + 1
tiley = ycord
For ynow = 0 To ymapshown * (tile_Height + 2) Step tile_Height
tilenow = map(tilex, tiley).land1

If tilenow < 1000 Then GoTo no_draw

page = int(tilenow/1000)
tile = (tilenow mod 1000) - 1
c3 = ((tile Mod temtiles_ud) * c2) + 1_
c4 = tile * c1 + 1

i = BitBlt(mapeditor.Picture1.hdc, xnow, ynow, tile_width, tile_Height, _
  Graphics.Graphics_pages(page + 9).hdc, c3, c4, SRCAND)

i = BitBlt(mapeditor.Picture1.hdc, xnow, ynow, tile_width, tile_Height,_
  Graphics.Graphics_pages(page).hdc, c3, c4, SRCINVERT)
no_draw:

tiley = tiley + 1
Next ynow
Next xnow
Exit Sub


You were performing the same calculations more than once within the loop.  This eats up a lot of time.  So I added a couple of variables to store them after they are calculated once (c1,c2,c3,c4).

I could not test this, because I do not have Visual Basic.  You might have to check the syntax because there might be something I didn't catch (like mismatched parentheses, etc.)

Also, I don't understand why you didn't set the page for values outside the 0 to 225 range.  I took this check out, because your program didn't seem to need it anyway.
0
 

Author Comment

by:testing38
ID: 1445339
Thanks this worked great with a little editing!
0
 

Expert Comment

by:path
ID: 1445340
Just another thought you may find useful - on your iterative "next", comment out (but leave it for readability) the counter name ie Next 'ynow (comment) and Next 'xnow(comment) - this will improve the speed considerable, expecially since there are two nested loops running. Simple but effective.
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

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…
I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
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…
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…
Suggested Courses

610 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