Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Overflow error on calculating a zoomed picturebox

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
Hi,

I am trying to calculate the size of a zoomed picture (4 times). However the picturebox tries to size properly but I get an overflow error on my horizontal and vertical scrollbars max methods.

Can someone point out my error, I have tried multiple ways of fixing this bug with no such luck. As well, can someone tell me of a faster way to zoom a picture box as my paintpicture event is slow at 4x magnification. My 2 pictureboxes have a scalemode of pixels.

My sample code is below, thanks in advance!

VScroll1.Max = 0 'init max value of vertical s.bar

'set the scroll bar min and max values
'VScroll1.Max = -Pic(0).Height * 0.75

Debug.Print Pic(0).Height
Debug.Print Pic(1).Height

VScroll1.Max = Pic(1).Height - Pic(0).Height

Debug.Print VScroll1.Max

VScroll1.Min = 0
VScroll1.LargeChange = 50
VScroll1.SmallChange = 25



HScroll1.Enabled = True
HScroll1.Max = 0

'set the scroll bar min and max values
'HScroll1.Max = -Pic(0).Width * 0.75

HScroll1.Max = -(Pic(0).Width - Pic(1).Width)
HScroll1.Min = 0
HScroll1.LargeChange = 100 - HScroll1.Max / 2
HScroll1.SmallChange = 25

frmPreview.Refresh



thanks
newbie_999
 
My initial conclusion is that the overflow is being generated by your first line of code (.max = 0).

Maybe what is hppening is that VB trys to ensure that the current scroll position is between min and max, and to accomplish this it divides the current position by the .max value. Any value divided by zero is infinity which will generate an overflow.

Try changing your logic and see what occurs. "Life is full of learning, and then there is wisdom"
 
Hi,

I tried what you suggested by remming out the max = 0 lines but got the same error. I picked up another vb book and found that the scroll bar values are integers, so the min and max values are either +- 32 thousand plus.

So I put a debug.print statement form each and found that the max values are over this =- 32 thousand, thus the error message.

Now I am stuck questioning how I can calucate the max value in order to view the zoom picture. Does any have any ideas, I'm really stuck!

Thanks in Advance

newbie_999
 
you could try something like this:

HScroll1.Max = -(Pic(0).Width - Pic(1).Width) \ 10 'or 2 or any oyher #
then in HScroll1_change:

Pic(0).left = HScroll1.value * 10 * -1

PS I personally like to work with twips when manipulating a GUI. Tim

Remember the KISS principle:
Keep It Simple, Stupid!
 
hi,

Thanks tim! I tried what you suggested and it works great!

However, I have another question regarding pixels or twips. Why is one better to use than another? I tried to use twips but my preview picture pic(0) became all blocky and blurred. I could not figure out the conversion properly so I put my pics defaulting to pixels.

Thanks for all your help!

newbie_999
 
How do you load pic(0)? (show code)
Twips is a measurement of actual screen area (at any resolution) in inches where 1440 Twips = 1 inch. Tim

Remember the KISS principle:
Keep It Simple, Stupid!
 
Hi,


Thanks Tim, I am slowing learning!

I am loading my pics from my picture array, so you can scroll through the pictures as follows:

These prodcedure work, the only problem I have is dealing with the scalemodes and calculations. If I leave pic(1) in twips and pic(0) as userdefined zero scalemode properties I have no issues. I just need to learn how to do the scaling more effeciently, twips to pixels, twips to inches, etc...

' this code goes on 2 separate lines in my project

Pic(0).Picture = LoadPicture(Pictures intArrayPointer))
Pic(1).Picture = LoadPicture(Pictures(intArrayPointer))

The picture loads in okay, however, my scale code produces different results:

Select Case cboScale.ListIndex
Case 0, 1, 2
MousePointer = vbHourglass
'Pic(0).Picture = LoadPicture()
Pic(0).Cls

Pic(0).Width = Pic(1).Width / i
Pic(0).Height = Pic(1).Height / i


' Copy the hidden picture into PreviewPict.
Pic(0).PaintPicture Pic(1), 0, 0, (Pic(1).ScaleWidth / i) / 1440, (Pic(1).ScaleHeight / i) / 1440


tbPreview.Buttons(4).Enabled = True

Case Else

tbPreview.Buttons(4).Enabled = False
tbPreview.Buttons(5).Enabled = False


MousePointer = vbHourglass

Pic(0).Cls

' Copy the hidden picture into PreviewPict.
Pic(0).PaintPicture Pic(1), 0, 0, (Pic(1).ScaleWidth / 1440) * i, (Pic(1).ScaleHeight / 1440) * i

Pic(0).Width = Pic(1).Width * i
Pic(0).Height = Pic(1).Height * i


End Select

Pic(0).Refresh

Call Form_Resize

MousePointer = vbDefault



Thanks in advance

newbie_999
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top