About a "invisible" variable

  • Thread starter E. Omar Troccoli K.
  • Start date
E

E. Omar Troccoli K.

En blanco
Hi,

This answer is the "evolution" of my last question:

I still working in my template, the final part, but have a little final problem (little for masters, great for novices): I have a variable "A" in a UserForm1. That variable is a string, formed adding words filled in 7 ComboBoxes. When I set "MsgBox A" at UserForm1 level, MsgBox display the correcti string. That string I want to use at final, to auto-set the name of the document. Well, the variable A have the right string at UserForm1 level. I declared variable A as public in the "Declaration, General" in the UserForm1, and the string is "formed" inside the "Public Sub CommandButton1_Click()" module. That module is inside the UserForm1.

At this point, everything allright. When I want to close the document, in "this document" part, I declare too variable A as Public, but the variable at this level es empty, have no string at all. If you, in that instance, set "MsgBox A", the message is empty, with no string at all. Then, I can´t use this string to set the document name. I can't understand because I've declared as public the A variable, and understand that this thing do it "visible" in all modules of the document. Is too evident that I'm no doing something too basic in that point, and some help will be great for me.

Regards,



Omar
 
J

Jezebel

Start by reading Help on variable scope. Your variable is declared in
UserForm1, so it exists only as long as the form does. Making it public
means that the variable can be reference from outside the form, but only as
a property of the form:

MsgBox UserForm1.A

And the variable ceases to exist when you unload the form.

Your second declaration of a variable with the same name is creating a
second variable that is entirely independent.




En blanco
Hi,

This answer is the "evolution" of my last question:

I still working in my template, the final part, but have a little final
problem (little for masters, great for novices): I have a variable "A" in a
UserForm1. That variable is a string, formed adding words filled in 7
ComboBoxes. When I set "MsgBox A" at UserForm1 level, MsgBox display the
correcti string. That string I want to use at final, to auto-set the name of
the document. Well, the variable A have the right string at UserForm1 level.
I declared variable A as public in the "Declaration, General" in the
UserForm1, and the string is "formed" inside the "Public Sub
CommandButton1_Click()" module. That module is inside the UserForm1.

At this point, everything allright. When I want to close the document, in
"this document" part, I declare too variable A as Public, but the variable
at this level es empty, have no string at all. If you, in that instance, set
"MsgBox A", the message is empty, with no string at all. Then, I can´t use
this string to set the document name. I can't understand because I've
declared as public the A variable, and understand that this thing do it
"visible" in all modules of the document. Is too evident that I'm no doing
something too basic in that point, and some help will be great for me.

Regards,



Omar
 
W

Word Heretic

G'day "E. Omar Troccoli K." <[email protected]>,

Dim MyForm as UserForm1
Set MyForm = new userform1
with myform
.show
msgbox .a
end with
set myform=nothing

E. Omar Troccoli K. said:
En blanco
Hi,

This answer is the "evolution" of my last question:

I still working in my template, the final part, but have a little final problem (little for masters, great for novices): I have a variable "A" in a UserForm1. That variable is a string, formed adding words filled in 7 ComboBoxes. When I set "MsgBox A" at UserForm1 level, MsgBox display the correcti string. That string I want to use at final, to auto-set the name of the document. Well, the variable A have the right string at UserForm1 level. I declared variable A as public in the "Declaration, General" in the UserForm1, and the string is "formed" inside the "Public Sub CommandButton1_Click()" module. That module is inside the UserForm1.

At this point, everything allright. When I want to close the document, in "this document" part, I declare too variable A as Public, but the variable at this level es empty, have no string at all. If you, in that instance, set "MsgBox A", the message is empty, with no string at all. Then, I can´t use this string to set the document name. I can't understand because I've declared as public the A variable, and understand that this thing do it "visible" in all modules of the document. Is too evident that I'm no doing something too basic in that point, and some help will be great for me.

Regards,



Omar

Steve Hudson

Word Heretic, Sydney, Australia
Tricky stuff with Word or words for you.
Email (e-mail address removed)
Products http://www.geocities.com/word_heretic/products.html

Replies offlist may require payment.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top