Solved

An object question

Posted on 2002-03-17
6
163 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
[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: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
Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

 
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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
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…

717 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