Visual Basic Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
 
User Name:
Password:
Remember me
Go Back   ASP Free ForumsProgrammingVisual Basic Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread ASP Free Forums Sponsor:
  #1  
Old February 4th, 2007, 04:30 PM
cjreynolds cjreynolds is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Mar 2005
Posts: 361 cjreynolds User rank is Corporal (100 - 500 Reputation Level)cjreynolds User rank is Corporal (100 - 500 Reputation Level)cjreynolds User rank is Corporal (100 - 500 Reputation Level)cjreynolds User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 3 Days 11 h 47 m 7 sec
Reputation Power: 5
Trouble printing complex shapes

I've written a program in VB6 that similates a spyrograph toy - you choose the radius of the outer gear, radius of the inner gear, and the offset (the hole where you put the pen), and a pattern is drawn in a picture box. You can choose drawing color, background color, etc., and it allows you to overlay patterns - like when you draw a pattern with one gear, then change gears and draw another on top of it. Works great.

Now I'm trying to add a print function. I'm using PSet() to print to the printer:

VB Code:
Original - VB Code
  1. Sub PrintRoullette()
  2. Dim pi, r, R1, R2, i
  3.  
  4.     For i = 0 To UBound(prtR1) - 1
  5.    
  6.         R1 = prtR1(i)   ' these 3 arrays and prtPen() are populated each
  7.         R2 = prtR2(i)   ' time the DrawRoullette() sub is called - they're
  8.         r = prtR(i)     ' the gear radius' and offset slider values
  9.        
  10.         pi = 4 * Atn(1)
  11.        
  12.         't represents time, X & Y are the coordinates of each point drawn
  13.         Dim Loop1, Loop2
  14.         Dim t, X, Y As Double
  15.         Dim Rotations As Integer
  16.        
  17.         If Int(R1 / R2) = R1 / R2 Then
  18.             Rotations = 1
  19.         Else
  20.             Rotations = Abs(R2 / 10)
  21.             If Int(R2 / 10) <> R2 / 10 Then Rotations = 10 * Rotations
  22.         End If
  23.         Rotations = Rotations + 1
  24.        
  25.         For Loop1 = 1 To Rotations
  26.            
  27.             For Loop2 = 0 To 2 * pi Step pi / (4 * 360)
  28.                 t = Loop1 * 2 * pi + Loop2
  29.                 X = (R1 + R2) * Cos(t) - (R2 + r) * Cos(((R1 + R2) / R2) * t)
  30.                 Y = (R1 + R2) * Sin(t) - (R2 + r) * Sin(((R1 + R2) / R2) * t)
  31.                 Printer.PSet (Printer.ScaleWidth / 2 + X, Printer.ScaleHeight _
  32.                   / 2 + Y), prtPen(i)
  33.             Next
  34.             DoEvents
  35.         Next
  36.     Next
  37.  
  38. End Sub


This is pretty much the same as the DrawRoullette() sub that draws the patterns on the screen. The DrawRoullette() sub draws a pattern in a picture box while loading the prtR1, prtR2, prtR, and prtPen arrays with the current drawing settings (gear radius, etc.). each time the sub is called, it reDims the arrays and adds another element to them.

The print button code is:

VB Code:
Original - VB Code
  1. Private Sub cmdPrint_Click()
  2.  
  3.     SetLargePrinterScale Picture1
  4.     PrintRoullette
  5.     Printer.EndDoc
  6.    
  7. End Sub


It first sets the printer's scale properties with the SetLargePrinterScale() sub:

VB Code:
Original - VB Code
  1. Sub SetLargePrinterScale(obj As Object)
  2. Dim Owid As Single      ' object's scale width
  3. Dim Ohgt As Single      ' object's scale height
  4. Dim Pwid As Single      ' printer's scale width
  5. Dim Phgt As Single      ' printer's scale height
  6. Dim Xmid As Single      ' middle of page (hor.)
  7. Dim Ymid As Single      ' middle of page (vert.)
  8. Dim S As Single
  9.  
  10.     Owid = obj.ScaleX(obj.ScaleWidth, obj.ScaleMode, vbPixels)
  11.     Ohgt = obj.ScaleY(obj.ScaleHeight, obj.ScaleMode, vbPixels)
  12.    
  13.     Pwid = Printer.ScaleX(Printer.ScaleWidth, Printer.ScaleMode, vbPixels)
  14.     Phgt = Printer.ScaleY(Printer.ScaleHeight, Printer.ScaleMode, vbPixels)
  15.    
  16.     If Ohgt / Owid > Phgt / Pwid Then
  17.         S = Phgt / Ohgt
  18.     Else
  19.         S = Pwid / Owid
  20.     End If
  21.    
  22.     Pwid = obj.ScaleX(Pwid, vbPixels, obj.ScaleMode) / S
  23.     Phgt = obj.ScaleY(Phgt, vbPixels, obj.ScaleMode) / S
  24.    
  25.     Xmid = obj.ScaleLeft + obj.ScaleWidth / 2
  26.     Ymid = obj.ScaleTop + obj.ScaleHeight / 2
  27.    
  28.     Printer.Scale (Xmid - Pwid / 2, Ymid - Phgt / 2)-(Xmid + Pwid / 2, Ymid + Phgt / 2)
  29.  
  30. End Sub


It then calls the PrintRoullette sub, which draws the pattern to the printer using prtR1(0), prtR2(0), etc., then repeats for each additional array element, overlaying the patterns.

cmdPrint_Click() then calls Printer.EndDoc to send the job to the printer.

This worked great when I was using it from within the VB environment. When I compiled the project, closed VB, and ran the stand-alone exe, I could print one pattern at a time, but if I tried to overlay patterns, that is, drawing more than one pattern to the printer before issuing the Printer.EndDoc command, I get a runtime error '482'.

I've researched the problem, and it seems to be a bug in VB6 - installing service pack 5 was recommended, and I installed SP5 and SP6 - no help.

I reloaded my printer drivers (a clue I got from one of the forums), and after that, I couldn't even print overlaid patterns from within VB - This is going downhill. I've since downloaded the latest drivers, but that didn't help.

I've found that I can overlay patterns if they are extremely simple, so this may be a matter of giving the printer more than it can handle, or perhaps this is a timeout issue?

Has anyone had similar experiences? Can this be done? If not, how do I simply print an image from a picture box? I'd rather do it the way I'm doing it (the resolution is awesome) but I've gotta do what works...

joe

Reply With Quote
Reply

Viewing: ASP Free ForumsProgrammingVisual Basic Programming > Trouble printing complex shapes


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump



 Free IT White Papers!
 
How to Present Effectively Online
This white paper offers practical and actionable advice on the key steps that any presenter should consider as they plan and execute a Webinar or online meeting.

 
Open Source Security Myths
Open Source Software (OSS) is computer software whose source code is available to the general public with relaxed or non-existent intellectual property restrictions (or arrangement such as the public domain), and is usually developed with the input of many contributors.

 
Power and Cooling Capacity Management for Data Centers
This paper describes the principles for achieving power and cooling capacity management.

 
Scalable, Fault-Tolerant NAS for Oracle - The Next Generation
For several years NAS has been evolving as a storage alternative for Oracle databases, and for good reason: NAS is quite often the simplest, most cost-effective storage approach for Oracle. Learn about the benefits that HP's approach to scalable NAS brings to Oracle environments in this comprehensive white paper.

 
Understanding Web Application Security Challenges
This white paper discusses many common threats and preventive measures for Web application security, and explains what you can do to help protect your organization.

 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2009 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway
Stay green...Green IT