-
Aug 11th, 2020, 03:41 PM
#1
Thread Starter
Addicted Member
[RESOLVED] Center Object or Control
Hi there,
I'm trying to make a combined Object and Control Center function, but I'm getting error message saying:
"object doesn't support property or method"
I'm calling my function like this at run-time:
Code:
Call CenterObject(Me, Picture1)
Code:
Public Function CenterObject(objPARENT As Object, objCTL As Control)
With objPARENT
If TypeOf objPARENT Is Form Then
.objCTL.Left = (.ScaleWidth / 2) - (.objCTL.Width / 2)
.objCTL.Top = (.ScaleHeight / 2) - (.objCTL.Height / 2)
Else
.objCTL.Left = (.Width / 2) - (.objCTL.Width / 2)
.objCTL.Top = (.Height / 2) - (.objCTL.Height / 2)
End If
End With
End Function
Thank you for your support!
Kind regards,
Viktor
-
Aug 11th, 2020, 03:51 PM
#2
Re: Center Object or Control
You're passing the control itself to the Sub (see next sentence), so use the passed control variable rather than whatever you are trying to do accessing it via the parent variable's With statement. Also, why is it a Function if there is nothing being returned?
Code:
With objPARENT
If TypeOf objPARENT Is Form Then
objCTL.Left = (.ScaleWidth / 2) - (objCTL.Width / 2)
objCTL.Top = (.ScaleHeight / 2) - (objCTL.Height / 2)
Else
objCTL.Left = (.Width / 2) - (objCTL.Width / 2)
objCTL.Top = (.Height / 2) - (objCTL.Height / 2)
End If
End With
-
Aug 11th, 2020, 04:33 PM
#3
Thread Starter
Addicted Member
Re: Center Object or Control
Originally Posted by OptionBase1
You're passing the control itself to the Sub (see next sentence), so use the passed control variable rather than whatever you are trying to do accessing it via the parent variable's With statement. Also, why is it a Function if there is nothing being returned?
Code:
With objPARENT
If TypeOf objPARENT Is Form Then
objCTL.Left = (.ScaleWidth / 2) - (objCTL.Width / 2)
objCTL.Top = (.ScaleHeight / 2) - (objCTL.Height / 2)
Else
objCTL.Left = (.Width / 2) - (objCTL.Width / 2)
objCTL.Top = (.Height / 2) - (objCTL.Height / 2)
End If
End With
Yes, Thank you for that, you helped me alot.
Regarding Function, it was intended to return Boolean "True or False" upon TypeOf = Form detection, but didn't implemented it yet.
Kind regards,
Viktor
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|