[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
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
Re: Center Object or Control
Quote:
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