Solved

An object question

Posted on 2002-03-17
6
158 Views
Last Modified: 2010-05-02
Using VB5.  What is wrong with the following code?  The offending code line is indicated with the error thrown:
=======
Module1.bas
Public objPrint As Object
=======
Private Function ScaleInches _
   (picPreview As PictureBox) As Double
Dim Ratio As Double
---
---computations
---
ScaleInches = Ratio
End Function
=======
Private Sub cmdPreview_Click()
Dim dRatio as Double
Set objPrint = frmPreview.Picture
' frmPreview is another form, containing a picture box,
' named Picture
'
' The following line throws the error:
' " 13 type mismatch"
dRatio = ScaleInches(objPrint)
End Sub
======

I tried changing the Function definition to:
Private Function ScaleInches _
   (picPreview As Object) As Double

Then, inside that function, the following code line:

picPreview.ScaleMode = vbInches

throws the error: "438 Object doesn't support this property or method".
=====
Please help -- Norm

0
Comment
Question by:posnorm
6 Comments
 
LVL 2

Expert Comment

by:nahumd
ID: 6876115
Try to define the objects picPreview and objPrint not as objects , but as their exact type.
0
 
LVL 44

Expert Comment

by:bruintje
ID: 6876118
Hi posnorm,
The first error on the type mismatch error 13 comes probably with using the object in the function, returning a double and putting it into a double could get to that message i guess....

The second error is the start of the trouble it seems that the scalemode property of the picturebox isn't supported

i couldn't find anything except on grids or the printer object about this error with scalemode and they had to be patched with service packs

maybe this is the solution for your problem too, but i'm not sure

http://msdn.microsoft.com/vstudio/downloads/updates/sp/vs97/readme.asp

:O)Bruintje

0
 
LVL 2

Accepted Solution

by:
peterwest earned 100 total points
ID: 6876194
It might be worth changing the control name from Picture to Picture1 or something else.  I think that Form1.Picture normally refers to the Picture property of the form - so if you've got a control with the name Picture then it could cause problems.

There is also a problem with your declarations.  You declare objPrint as an Object but then try to pass it to the scale routine which is expecting a PictureBox object.  You could either:

1. Change the parameter required for the scaling to be an object too.

or

2. Change the declaration of objPrint to PictureBox.

You'd probably find the programme works quicker with the second option.  If you declare items as objects then late binding is used which can slow the application down.

Hope this helps,

Pete
0
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 
LVL 13

Expert Comment

by:crazyman
ID: 6876758
you are trying to change the scale mode of
frmPreview.Picture

this will be looking at the picture property of your form not your picture box, change its name.
0
 
LVL 1

Expert Comment

by:Barraza
ID: 6878891
Try removing the "As Double" from your function name and from the variable inside your function.  Let them be Variants.  For example...

Private Function ScaleInches (picPreview As PictureBox)
    Dim Ratio
    .....
    ....
End Function
0
 

Author Comment

by:posnorm
ID: 6887859
I wish to thank everyone for their interest in this question.  I have learned something from each comment.  There is no way to split up points.

The matter of early vs late binding is important, and I am familiarizing myself with the concept.

Thank you all again. -- Norm
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

758 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now