Results 1 to 3 of 3

Thread: [RESOLVED] Center Object or Control

  1. #1

    Thread Starter
    Addicted Member beic's Avatar
    Join Date
    Jun 2012
    Posts
    150

    Resolved [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

  2. #2
    PowerPoster
    Join Date
    Nov 2017
    Posts
    3,116

    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

  3. #3

    Thread Starter
    Addicted Member beic's Avatar
    Join Date
    Jun 2012
    Posts
    150

    Re: Center Object or Control

    Quote Originally Posted by OptionBase1 View Post
    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
  •  



Click Here to Expand Forum to Full Width