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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Runtime error 424:Object Required - used to work before 2000 1

Status
Not open for further replies.

joannef

Programmer
May 15, 2002
16
0
0
CA
I have this resizing code in my standard module that used to work before I moved to a Windows 2000 OS.


Public Sub Form_Resize(frm As Form)
'Passes in the name of a form and does the form resizing

ActiveForm.Move 0, 0, Screen.Width, Screen.Height
...

End SUB

Now I get a runtime error and the only choices I have to define the variable are with Screen.activeform and MDIForm.active, neither work .. any suggestions?

I have checked my references and all seems ok.

Joanne



 


Use the Me Keyword:

'In a module
Public Sub resizeForm(frm As Form)
frm.Move 0, 0, Screen.Width, Screen.Height
End Sub


' Form Code
Private Sub Form_Load()
resizeForm Me
End Sub



Mark


A molehill man is a pseudo-busy executive who comes to work at 9 AM and finds a molehill on his desk. He has until 5 PM to make this molehill into a mountain. An accomplished molehill man will often have his mountain finished before lunch
- Fred Allen
 
That helped me get to my next problem :)

Dim ctl as controls

For Each ctl In frm.Controls
ctl.Top = ctl.Top * Heightratio
Next ctl

Any suggestions? And I do appreciate your help with this.

Joanne
 

Dim ctl As Control ' (not Controls)

I assume HeightRatio is calculated prior...


Mark


A molehill man is a pseudo-busy executive who comes to work at 9 AM and finds a molehill on his desk. He has until 5 PM to make this molehill into a mountain. An accomplished molehill man will often have his mountain finished before lunch
- Fred Allen
 
Here is the full sub routine.

This was working, could updating to Service Pack 3 have made need new references?

Public Sub Form_Resize(frm As Form)
'Passes in the name of a form and does the form resizing

On Error GoTo Errhandler

Dim Heightratio
Dim Widthratio
Dim ctl As Control


frm.Move 0, 0, Screen.Width, Screen.Height
Heightratio = Screen.Height / 7200
Widthratio = Screen.Width / 9600

For Each ctl In frm.Controls
ctl.Top = ctl.Top * Heightratio
ctl.Height = ctl.Height * Heightratio
ctl.Left = ctl.Left * Widthratio
ctl.Width = ctl.Width * Widthratio
ctl.Font.Size = ctl.Font.Size * Heightratio
Next ctl
Exit Sub
Errhandler:
Resume Next

End Sub

I still get stuck mostly now on labels and items in a combobox, from what I can tell from the immediate window.

Thank you again for your response.

Joanne
 


A couple of notes:

- It's generally a bad idea to use the name of an existing form event (Form_Resize) as a Public Sub name. If you were to include code behind the form for the resize event, and called the Public sub with the frm parameter, you will get a Wrong Number of Arguments error--since the form's local call to Resize accepts no parameter. It's better to give public subs a unique name like: Public Sub ResizeThisForm(frm as Form)

- The code appears to adjust the form size to full screen, without maximizing the form and resize the controls based on the available form space (screen.Height & screen.Width). Which seemingly worked when I cut an pasted the code in a new project module (renamed to DoForm_Resize) and called from the Form_Load event. I'm running XP Pro with no additional references added to the standard vb project.

- What specific error are you getting with the labels and combo boxes?




Mark

"You guys pair up in groups of three, then line up in a circle."
- Bill Peterson, a Florida State football coach
 
I wqas getting runtime error 424 object required .. which with your help moved it along until now i get the error runtime error 383 'Height' property is read only, when I look at the control it seems to show "". If I say do all but ctl = "" it resizes the form wrong.

What boggles me most is this worked fine up until I updated to SP3. When I developed it in Win 98 I had issues bringing it to Windows 2000. I worked those out and now I have this nagging one appearing.

I will take your advice and rename the subroutine.

Thanks

Joanne
 
Hurray!! The renaming of the subroutine fixed everything. Thank you so much for your time and knowledge.

I will have to remember that as programs get "smarter" with newer versions, I will have to use better programming techniques from ths start to keep up with it.

Joanne
 
I lied, but at least now it starts the application and its only when I switch forms that it gives me the same runtime error 383 I had before.

And I do think it is the comboboxes causing the trouble at the moment.

Back to the grindstone.

Joanne

 
The Height property of a Combobox is read-only. Its height seems to be proportional to the font-size. You could exclude any combobox from the height adjustment:

For Each ctl In frm.Controls
ctl.Top = ctl.Top * Heightratio
If Not TypeOf ctl Is ComboBox Then
ctl.Height = ctl.Height * Heightratio
End If
ctl.Left = ctl.Left * Widthratio
ctl.Width = ctl.Width * Widthratio
ctl.Font.Size = ctl.Font.Size * Heightratio
Next ctl

Mark

"You guys pair up in groups of three, then line up in a circle."
- Bill Peterson, a Florida State football coach
 
Got any suggestions for type of when it gives an error on the list items in the combo box. For example if the items in the combobox are

Type1
Type2
Type2

When I run the resize it will tell me the control is of type "Type1" not list or combobox and therefore gets into the code.

Thanks :)

Joanne

 

Hmmmmmmm. The items in a combo box shouldn't even be a factor since they won't be in the Form's Control collection. Are they maybe a Usercontrol which have the combo box inserted in them? If so, then you'll have to also exclude them from the height resizing as you did the regular combo boxes before (as well as the Font resizing).

If Not (TypeOf ctl Is ComboBox or Typeof ctl is Type1 or ...)Then

End if



Mark

"You guys pair up in groups of three, then line up in a circle."
- Bill Peterson, a Florida State football coach
 
They are just a regular combobox with a set of list values, because the list values have no type of ctl I cannot seem to exclude them from being resized.

Thanks for taking the time to look into this.

Joanne
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top