Why is a Variant parameter changing its type on function call

0 votes

I was going to ask for assistance when I discovered the cause of the odd behavior. I thought I'd mention it because it seems incredibly cryptic and in case anyone else encounters a similar situation. I'd like to know why this occurs if any of the experts can shed some light on it.

I'm invoking a procedure that registers UserForm metrics. The statement is:

Public Sub SaveFormSettings(FormReference As Variant)

I use the Variant type because UserForms are classes (different types). The user form uses the following call to save its metrics:

SaveFormSettings Me

I often called this from the QueryClose event of the userforms so that the locations and sizes could be restored using RestoreFormSettings on the subsequent run (the form metrics are no longer available at the UserForm Terminate event).

Recently, I developed an intermediate routine that, in addition to calling SaveFormSettings, performs additional work. I now call this intermediate routine in the QueryClose event. What that routine entails is:

Public Sub QueryCloseEvent(FormReference As Variant, Optional SaveSettings As Boolean = True)

And it does this:

If SaveSettings Then SaveFormSettings (FormReference)

There was no compilation error reported. However, the FormReference parameter is now of type "Controls" rather than a UserForm type, such as MyForm1, when it is passed to the SaveFormSettings method. When the routine tries to obtain the name of the form to create the registry key value, it encounters an error as a result of:

n = FormReference.Name & " Form Metrics"

This statement worked when I didn't have the intervening QueryClose function.

Now as it turns out, while typing up this question and analyzing my code for possible errors, I discovered that the problem is caused by the parentheses around the FormReference. When I changed the code to:

If SaveSettings Then SaveFormSettings FormReference ' <-- no parens

It now works as intended. Why?

Jan 22, 2023 in Others by Kithuzzz
• 38,010 points
201 views

1 answer to this question.

0 votes

Remove parentheses

If SaveSettings Then SaveFormSettings FormReferen

This will solve your issue.

answered Jan 22, 2023 by narikkadan
• 63,420 points

Related Questions In Others

0 votes
1 answer

What is a name function in JavaScript & how to define it?

A named function declares a name as ...READ MORE

answered Mar 7, 2019 in Others by Frankie
• 9,830 points
4,242 views
0 votes
1 answer

What is a callback function?

Callback function is a function which is ...READ MORE

answered Jun 13, 2019 in Others by sunshine
• 1,300 points
907 views
0 votes
1 answer
0 votes
1 answer

What is the impact of covid-19 on a global economy?

Covid-19 that is co-corona,vi-virus,d-development,19-In the year 2019.The ...READ MORE

answered Mar 19, 2020 in Others by Niroj
• 82,880 points
781 views
0 votes
1 answer

Retrieve epay.info Balance with VBA and Excel

This code should log you in, provided ...READ MORE

answered Sep 5, 2018 in Blockchain by digger
• 26,740 points
913 views
0 votes
1 answer

How to load file to Excel Power query from SFTP site

Currently, I don't think there is a ...READ MORE

answered Dec 3, 2018 in Power BI by Upasana
• 8,620 points
3,237 views
0 votes
1 answer

Using VBA Excel to create a gramatically correct list

The Excel AND function is a logical ...READ MORE

answered Feb 9, 2022 in Others by gaurav
• 23,260 points
527 views
0 votes
2 answers

How to copy a formula horizontally within a table using Excel VBA?

Hi so basically, create an adjacent column ...READ MORE

answered Feb 16, 2022 in Others by Edureka
• 13,670 points
767 views
0 votes
1 answer

Is there a way to test a formula result in excel and type it only once, all within one cell and not using a user defined function?

Use the Let function: =LET(Value,A1+B2+C4+G3+B4,IF(Value>10,"No",Value)) I hope this helps ...READ MORE

answered Jan 9, 2023 in Others by narikkadan
• 63,420 points
415 views
0 votes
1 answer

Why is just an ID in the URL path a bad idea for SEO?

yes it affects the click through rates ...READ MORE

answered Feb 20, 2022 in Others by narikkadan
• 63,420 points
316 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP