Go Back  Xtreme Visual Basic Talk > Legacy Visual Basic (VB 4/5/6) > General > Problem with Property Let


Reply
 
Thread Tools Display Modes
  #1  
Old 06-11-2001, 10:02 PM
planet-boss
Guest
 
Posts: n/a
Question Problem with Property Let


I've got a problem creating a class. Could someone take a quick look and see what I'm doing wrong? The code works great (to resize a form to match the size of the forms' .picture) when it is in a BAS module, but when I put it in a class module, if hangs on f = SizeTheForm. Says "Invalid use of property." The problem is somehow passing the form to the class. Here it is:

In the projects only form (form1):

Private TheFile As String

Option Explicit

Private Sub Form_Load()
Dim Blob As New FormSizer

TheFile = "C:\Test JPEG's\A cute picture.jpg"


Form1.Picture = LoadPicture(TheFile)
Blob.SizeTheForm = Me

Set Blob = Nothing

End Sub



Then in the class module:

Option Explicit

Private w As Long
Private h As Long
Private f As Form

Property Let SizeTheForm(ByRef f As Form)

f = SizeTheForm 'This is where it hangs - "Invalid use of property"
w = f.Picture.Width 'Gets the picture width in HiMetric units
h = f.Picture.Height 'Gets the picture height in HiMetric units

Select Case f.ScaleMode
Case 0 'the form to be sized is in ScaleMode 0, User
f.ScaleMode = 1 'Temporarily resets f.ScaleMode to Twips for manipulation...
w = f.ScaleX(w, vbHimetric, vbTwips)
h = f.ScaleY(h, vbHimetric, vbTwips)
w = w + f.Width - f.ScaleWidth
h = h + f.Height - f.ScaleHeight
f.Move f.Left, f.Top, w, h 'Resizes the form - All X, Y coordinates...
f.ScaleMode = 0 'Returns f.ScaleMode to User...
Case 1 'the form to be sized is in ScaleMode 1, Twips - Doesn't need to be converted...
w = f.ScaleX(w, vbHimetric, vbTwips) 'Converts the HiMetric width to Twips - vbTwips because ScaleMode of the form is set to 1 - Twips
h = f.ScaleY(h, vbHimetric, vbTwips) 'Converts the HiMetric height to Twips - vbTwips because Scale Mode of the form is set to 1 - Twips
w = w + f.Width - f.ScaleWidth 'Adds the border width offset -ScaleWidth IS THE INSIDE OF THE FORM, Width IS THE ENTIRE FORM!!!
h = h + f.Height - f.ScaleHeight 'Adds the border height offset - ScaleHeight IS THE INSIDE OF THE FORM, Height IS THE ENTIRE FORM!!!
f.Move f.Left, f.Top, w, h 'Resizes the form - All X, Y coordinates...
Case 2 'the form to be sized is in ScaleMode 2, Points
f.ScaleMode = 1 'Temporarily resets f.ScaleMode to Twips for manipulation...
w = f.ScaleX(w, vbHimetric, vbTwips)
h = f.ScaleY(h, vbHimetric, vbTwips)
w = w + f.Width - f.ScaleWidth
h = h + f.Height - f.ScaleHeight
f.Move f.Left, f.Top, w, h 'Resizes the form - All X, Y coordinates...
f.ScaleMode = 2 'Returns f.ScaleMode to Points...
Case 3 'the form to be sized is in ScaleMode 3, Pixels
f.ScaleMode = 1 'Temporarily resets f.ScaleMode to Twips for manipulation...
w = f.ScaleX(w, vbHimetric, vbTwips)
h = f.ScaleY(h, vbHimetric, vbTwips)
w = w + f.Width - f.ScaleWidth
h = h + f.Height - f.ScaleHeight
f.Move f.Left, f.Top, w, h 'Resizes the form - All X, Y coordinates...
f.ScaleMode = 3 'Returns f.ScaleMode to Pixels...
Case 4 'the form to be sized is in ScaleMode 4, Characters
f.ScaleMode = 1 'Temporarily resets f.ScaleMode to Twips for manipulation...
w = f.ScaleX(w, vbHimetric, vbTwips)
h = f.ScaleY(h, vbHimetric, vbTwips)
w = w + f.Width - f.ScaleWidth
h = h + f.Height - f.ScaleHeight
f.Move f.Left, f.Top, w, h 'Resizes the form - All X, Y coordinates...
f.ScaleMode = 4 'Returns f.ScaleMode to Characters...
Case 5 'the form to be sized is in ScaleMode 5, Inches
f.ScaleMode = 1 'Temporarily resets f.ScaleMode to Twips for manipulation...
w = f.ScaleX(w, vbHimetric, vbTwips)
h = f.ScaleY(h, vbHimetric, vbTwips)
w = w + f.Width - f.ScaleWidth
h = h + f.Height - f.ScaleHeight
f.Move f.Left, f.Top, w, h 'Resizes the form - All X, Y coordinates...
f.ScaleMode = 5 'Returns f.ScaleMode to Inches...
Case 6 'the form to be sized is in ScaleMode 6, Millimeters
f.ScaleMode = 1 'Temporarily resets f.ScaleMode to Twips for manipulation...
w = f.ScaleX(w, vbHimetric, vbTwips)
h = f.ScaleY(h, vbHimetric, vbTwips)
w = w + f.Width - f.ScaleWidth
h = h + f.Height - f.ScaleHeight
f.Move f.Left, f.Top, w, h 'Resizes the form - All X, Y coordinates...
f.ScaleMode = 6 'Returns f.ScaleMode to Millimeters...
Case 7 'the form to be sized is in ScaleMode 7, Centimeters
f.ScaleMode = 1 'Temporarily resets f.ScaleMode to Twips for manipulation...
w = f.ScaleX(w, vbHimetric, vbTwips)
h = f.ScaleY(h, vbHimetric, vbTwips)
w = w + f.Width - f.ScaleWidth
h = h + f.Height - f.ScaleHeight
f.Move f.Left, f.Top, w, h 'Resizes the form - All X, Y coordinates...
f.ScaleMode = 7 'Returns f.ScaleMode to Centimeters...
Case Else
MsgBox "Problem With ScaleMode In SizeTheForm!"
End Select

End Property


Reply With Quote
  #2  
Old 06-11-2001, 11:08 PM
JDT JDT is offline
Original Contributor

Retired Moderator
* Guru *
 
Join Date: Jan 2001
Location: Watch Window
Posts: 2,781
Default Re: Problem with Property Let

Comment out this line and see if it works:

<pre> f = SizeTheForm 'This is where it hangs - "Invalid use of property"</pre>

It looks like f is the form being passed in and you can't assign it to the property let itself. There is alot of things to pay attention to in order to use classes correctly so post back if you still have trouble.

JDT

__________________
JDT
Reply With Quote
  #3  
Old 06-11-2001, 11:30 PM
planet-boss
Guest
 
Posts: n/a
Default Re: Problem with Property Let

JDT, it works perfectly now, but why? How does it know that f is SizeTheForm? Very confusing...

Reply With Quote
  #4  
Old 06-12-2001, 12:43 AM
Yoda's Avatar
Yoda Yoda is offline
Contributor

Retired Leader
* Expert *
 
Join Date: Apr 2001
Location: Gent, Belgium
Posts: 479
Default Re: Problem with Property Let

This is a wild guess, but I think you should use fidderent var names for your private variable and your property parameter. In my opinion, the property parameter overrules the private parameter, making the error giving line recursive. So mayme you should go with :

Private mForm as Form

Or smth like that

<font color=green>Do or do not
There is no try</font color=green>
__________________
Do or do not,
There is no try
Reply With Quote
  #5  
Old 06-12-2001, 01:02 AM
planet-boss
Guest
 
Posts: n/a
Default Re: Problem with Property Let

Yoda, I still don't see how the private parameter gets assigned at all... When I rem'd out f = ResizeTheForm it worked perfectly, but I don't understand how VB figured out that f was the form it was passed, except that it was the only form declared in the class. Trying to figure out how to explicitly assign the form to the private variable that will manipulate it. Very confusing to me. I would be less confused if it didn't work so well when I removed f = SizeTheForm... It is assuming f = the form it is being passed. Drives me crazy when software assumes anything! I must be a control freak... Thanks for helping me out. Trying to get up to speed, so it means a lot how helpful so many people are.

Reply With Quote
  #6  
Old 06-12-2001, 01:19 AM
JDT JDT is offline
Original Contributor

Retired Moderator
* Guru *
 
Join Date: Jan 2001
Location: Watch Window
Posts: 2,781
Default Re: Problem with Property Let

It new f was a form because it was declared as a form in the parameters list. And it worked because it was passed by reference. It is just like a sub or function in any module.

It looks like you are misusing the power of a class object. What you are doing does not need a class. A class is reserved for an object. An object is something that can be defined by its properties and methods. When you use this Let procedure to resize your form, it is not really a property of that object, just a result. If this is to be placed in a class module, it should be a method (function) that the object can perform. Without seeing all your code and understanding your objectives it is hard to point you in the right direction but if you are just getting a feel for class modules then you are on the right track.

JDT

__________________
JDT
Reply With Quote
  #7  
Old 06-12-2001, 01:35 AM
Yoda's Avatar
Yoda Yoda is offline
Contributor

Retired Leader
* Expert *
 
Join Date: Apr 2001
Location: Gent, Belgium
Posts: 479
Default Re: Problem with Property Let

I agree here. This was not the place to use a property. A method would be right here. That way you can pass your form (by reference) to the method and you'll be without return value.
Of course when you want to assign extra methods and properties to a certain number of forms you can use a class module, but like JDT says, you're trying to complicate a simple problem.

<font color=green>Do or do not
There is no try</font color=green>
__________________
Do or do not,
There is no try
Reply With Quote
  #8  
Old 06-12-2001, 01:53 AM
planet-boss
Guest
 
Posts: n/a
Default Re: Problem with Property Let

Okay... I will make it a method. I am trying to learn VB by creating a few dll's that I can use later on, like screening text box entries, resizing forms to match their pictures, loading arrays & collections etc... Only been at VB for a few weeks, and am a bit overwhelmed. Thanks for your help!

Reply With Quote
  #9  
Old 06-12-2001, 01:57 AM
JDT JDT is offline
Original Contributor

Retired Moderator
* Guru *
 
Join Date: Jan 2001
Location: Watch Window
Posts: 2,781
Default Re: Problem with Property Let

If you are into Dll's and Class's after only a few weeks then you are doing quite well. Since this is going to be part of a Dll then with a sub or function, you are harnessing the power correctly.

Good luck

JDT

__________________
JDT
Reply With Quote
  #10  
Old 06-12-2001, 02:02 AM
planet-boss
Guest
 
Posts: n/a
Default Re: Problem with Property Let

Complicating a simple problem... The story of my life! I'm pedaling my tricycle as fast as I can... please be patient with me. Thanks again for the insightful help.

Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
 
 
-->