<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Defining a Globally available Variable in VBA Forum</title>
    <link>https://forums.autodesk.com/t5/vba-forum/defining-a-globally-available-variable/m-p/1391749#M41833</link>
    <description>Hi,&lt;BR /&gt;
&lt;BR /&gt;
Textboxes hold data as text.   Although you can write numbers to a text box, &lt;BR /&gt;
I have found it useful when querying them from the textbox to use&lt;BR /&gt;
Variable = Val(Textbox)&lt;BR /&gt;
&lt;BR /&gt;
You could use CInt or CDbl but these create errors if there are any &lt;BR /&gt;
non-numeric characters in the textbox.&lt;BR /&gt;
&lt;BR /&gt;
"I define this variable in the class as above"  Do you mean module?  Public &lt;BR /&gt;
variables in VBA are defined the same way as VB&lt;BR /&gt;
&lt;BR /&gt;
Public 'Variable' As 'Type'&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
-- &lt;BR /&gt;
&lt;BR /&gt;
Laurie Comerford&lt;BR /&gt;
CADApps&lt;BR /&gt;
www.cadapps.com.au&lt;BR /&gt;
"bcbii" &lt;SMCKENZIE&gt; wrote in message &lt;BR /&gt;
news:4914327@discussion.autodesk.com...&lt;BR /&gt;
Hi,&lt;BR /&gt;
&lt;BR /&gt;
I do not understand what is so different between VBA and VB 6, but I was&lt;BR /&gt;
able to, in VB 6 to define a global variable by:&lt;BR /&gt;
&lt;BR /&gt;
Public 'Variable' As 'Type'&lt;BR /&gt;
&lt;BR /&gt;
This variable was defined like this in a Module (to keep things cleaner), if&lt;BR /&gt;
I do the same thing with VBA, the variable does not transfer between the&lt;BR /&gt;
dialogs.&lt;BR /&gt;
&lt;BR /&gt;
I define this variable in the class as above (it is an integer), in one&lt;BR /&gt;
dialog, I set its value from a text box in one dialog (call this one dlg2)&lt;BR /&gt;
(this dialog is started via a button in another dialog - ill call it dlg1).&lt;BR /&gt;
After filling out the text box and pressing the ok button on dlg2 (okay sets&lt;BR /&gt;
the variable) a message box pops up displaying the value in the variable,&lt;BR /&gt;
the dlg2 closes.  Back in dlg1, another message box appears, the value for&lt;BR /&gt;
the variable is now 0.&lt;BR /&gt;
&lt;BR /&gt;
Just wondering if somebody out there could tell me what I am doing wrong in&lt;BR /&gt;
defining a variable that has the ability to pass between dialogs?&lt;BR /&gt;
&lt;BR /&gt;
Thank you&lt;/SMCKENZIE&gt;</description>
    <pubDate>Thu, 28 Jul 2005 22:40:17 GMT</pubDate>
    <dc:creator>Anonymous</dc:creator>
    <dc:date>2005-07-28T22:40:17Z</dc:date>
    <item>
      <title>Defining a Globally available Variable</title>
      <link>https://forums.autodesk.com/t5/vba-forum/defining-a-globally-available-variable/m-p/1391747#M41831</link>
      <description>Hi,&lt;BR /&gt;
&lt;BR /&gt;
I do not understand what is so different between VBA and VB 6, but I was &lt;BR /&gt;
able to, in VB 6 to define a global variable by:&lt;BR /&gt;
&lt;BR /&gt;
Public 'Variable' As 'Type'&lt;BR /&gt;
&lt;BR /&gt;
This variable was defined like this in a Module (to keep things cleaner), if &lt;BR /&gt;
I do the same thing with VBA, the variable does not transfer between the &lt;BR /&gt;
dialogs.&lt;BR /&gt;
&lt;BR /&gt;
I define this variable in the class as above (it is an integer), in one &lt;BR /&gt;
dialog, I set its value from a text box in one dialog (call this one dlg2) &lt;BR /&gt;
(this dialog is started via a button in another dialog - ill call it dlg1). &lt;BR /&gt;
After filling out the text box and pressing the ok button on dlg2 (okay sets &lt;BR /&gt;
the variable) a message box pops up displaying the value in the variable, &lt;BR /&gt;
the dlg2 closes.  Back in dlg1, another message box appears, the value for &lt;BR /&gt;
the variable is now 0.&lt;BR /&gt;
&lt;BR /&gt;
Just wondering if somebody out there could tell me what I am doing wrong in &lt;BR /&gt;
defining a variable that has the ability to pass between dialogs?&lt;BR /&gt;
&lt;BR /&gt;
Thank you</description>
      <pubDate>Thu, 28 Jul 2005 22:14:57 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vba-forum/defining-a-globally-available-variable/m-p/1391747#M41831</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2005-07-28T22:14:57Z</dc:date>
    </item>
    <item>
      <title>Re: Defining a Globally available Variable</title>
      <link>https://forums.autodesk.com/t5/vba-forum/defining-a-globally-available-variable/m-p/1391748#M41832</link>
      <description>it's the programming Gods telling you not to use global variables &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;BR /&gt;
If you must, place it in ThisDrawing. Better to create a Class Module.&lt;BR /&gt;
"bcbii" &lt;SMCKENZIE&gt; wrote in message &lt;BR /&gt;
news:4914327@discussion.autodesk.com...&lt;BR /&gt;
Hi,&lt;BR /&gt;
&lt;BR /&gt;
I do not understand what is so different between VBA and VB 6, but I was&lt;BR /&gt;
able to, in VB 6 to define a global variable by:&lt;BR /&gt;
&lt;BR /&gt;
Public 'Variable' As 'Type'&lt;BR /&gt;
&lt;BR /&gt;
This variable was defined like this in a Module (to keep things cleaner), if&lt;BR /&gt;
I do the same thing with VBA, the variable does not transfer between the&lt;BR /&gt;
dialogs.&lt;BR /&gt;
&lt;BR /&gt;
I define this variable in the class as above (it is an integer), in one&lt;BR /&gt;
dialog, I set its value from a text box in one dialog (call this one dlg2)&lt;BR /&gt;
(this dialog is started via a button in another dialog - ill call it dlg1).&lt;BR /&gt;
After filling out the text box and pressing the ok button on dlg2 (okay sets&lt;BR /&gt;
the variable) a message box pops up displaying the value in the variable,&lt;BR /&gt;
the dlg2 closes.  Back in dlg1, another message box appears, the value for&lt;BR /&gt;
the variable is now 0.&lt;BR /&gt;
&lt;BR /&gt;
Just wondering if somebody out there could tell me what I am doing wrong in&lt;BR /&gt;
defining a variable that has the ability to pass between dialogs?&lt;BR /&gt;
&lt;BR /&gt;
Thank you&lt;/SMCKENZIE&gt;</description>
      <pubDate>Thu, 28 Jul 2005 22:39:58 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vba-forum/defining-a-globally-available-variable/m-p/1391748#M41832</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2005-07-28T22:39:58Z</dc:date>
    </item>
    <item>
      <title>Re: Defining a Globally available Variable</title>
      <link>https://forums.autodesk.com/t5/vba-forum/defining-a-globally-available-variable/m-p/1391749#M41833</link>
      <description>Hi,&lt;BR /&gt;
&lt;BR /&gt;
Textboxes hold data as text.   Although you can write numbers to a text box, &lt;BR /&gt;
I have found it useful when querying them from the textbox to use&lt;BR /&gt;
Variable = Val(Textbox)&lt;BR /&gt;
&lt;BR /&gt;
You could use CInt or CDbl but these create errors if there are any &lt;BR /&gt;
non-numeric characters in the textbox.&lt;BR /&gt;
&lt;BR /&gt;
"I define this variable in the class as above"  Do you mean module?  Public &lt;BR /&gt;
variables in VBA are defined the same way as VB&lt;BR /&gt;
&lt;BR /&gt;
Public 'Variable' As 'Type'&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
-- &lt;BR /&gt;
&lt;BR /&gt;
Laurie Comerford&lt;BR /&gt;
CADApps&lt;BR /&gt;
www.cadapps.com.au&lt;BR /&gt;
"bcbii" &lt;SMCKENZIE&gt; wrote in message &lt;BR /&gt;
news:4914327@discussion.autodesk.com...&lt;BR /&gt;
Hi,&lt;BR /&gt;
&lt;BR /&gt;
I do not understand what is so different between VBA and VB 6, but I was&lt;BR /&gt;
able to, in VB 6 to define a global variable by:&lt;BR /&gt;
&lt;BR /&gt;
Public 'Variable' As 'Type'&lt;BR /&gt;
&lt;BR /&gt;
This variable was defined like this in a Module (to keep things cleaner), if&lt;BR /&gt;
I do the same thing with VBA, the variable does not transfer between the&lt;BR /&gt;
dialogs.&lt;BR /&gt;
&lt;BR /&gt;
I define this variable in the class as above (it is an integer), in one&lt;BR /&gt;
dialog, I set its value from a text box in one dialog (call this one dlg2)&lt;BR /&gt;
(this dialog is started via a button in another dialog - ill call it dlg1).&lt;BR /&gt;
After filling out the text box and pressing the ok button on dlg2 (okay sets&lt;BR /&gt;
the variable) a message box pops up displaying the value in the variable,&lt;BR /&gt;
the dlg2 closes.  Back in dlg1, another message box appears, the value for&lt;BR /&gt;
the variable is now 0.&lt;BR /&gt;
&lt;BR /&gt;
Just wondering if somebody out there could tell me what I am doing wrong in&lt;BR /&gt;
defining a variable that has the ability to pass between dialogs?&lt;BR /&gt;
&lt;BR /&gt;
Thank you&lt;/SMCKENZIE&gt;</description>
      <pubDate>Thu, 28 Jul 2005 22:40:17 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vba-forum/defining-a-globally-available-variable/m-p/1391749#M41833</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2005-07-28T22:40:17Z</dc:date>
    </item>
    <item>
      <title>Re: Defining a Globally available Variable</title>
      <link>https://forums.autodesk.com/t5/vba-forum/defining-a-globally-available-variable/m-p/1391750#M41834</link>
      <description>Hmm,&lt;BR /&gt;
&lt;BR /&gt;
Okay so I tried the following and still something isn't transferring over, i &lt;BR /&gt;
have a text box on dlg1 called txtInc, I make my changes in dlg2 in the text &lt;BR /&gt;
box called txtIncrement.  Now when I push okay, and return to dlg1, I have &lt;BR /&gt;
programmed the following code:&lt;BR /&gt;
&lt;BR /&gt;
Private sub cmdIncrement_click()&lt;BR /&gt;
&lt;BR /&gt;
   dlg2.Show vbModal&lt;BR /&gt;
&lt;BR /&gt;
   txtInc.text = dlg2.txtIncrement.Text&lt;BR /&gt;
&lt;BR /&gt;
End Sub&lt;BR /&gt;
&lt;BR /&gt;
From what I have done in other vb6 apps, this works, teh value from &lt;BR /&gt;
txtIncrement will be put into txtInc, but not in this app???&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
"Paul Richardson" &lt;SPAMTHIS&gt; wrote in message &lt;BR /&gt;
news:4914361@discussion.autodesk.com...&lt;BR /&gt;
it's the programming Gods telling you not to use global variables &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;BR /&gt;
If you must, place it in ThisDrawing. Better to create a Class Module.&lt;BR /&gt;
"bcbii" &lt;SMCKENZIE&gt; wrote in message&lt;BR /&gt;
news:4914327@discussion.autodesk.com...&lt;BR /&gt;
Hi,&lt;BR /&gt;
&lt;BR /&gt;
I do not understand what is so different between VBA and VB 6, but I was&lt;BR /&gt;
able to, in VB 6 to define a global variable by:&lt;BR /&gt;
&lt;BR /&gt;
Public 'Variable' As 'Type'&lt;BR /&gt;
&lt;BR /&gt;
This variable was defined like this in a Module (to keep things cleaner), if&lt;BR /&gt;
I do the same thing with VBA, the variable does not transfer between the&lt;BR /&gt;
dialogs.&lt;BR /&gt;
&lt;BR /&gt;
I define this variable in the class as above (it is an integer), in one&lt;BR /&gt;
dialog, I set its value from a text box in one dialog (call this one dlg2)&lt;BR /&gt;
(this dialog is started via a button in another dialog - ill call it dlg1).&lt;BR /&gt;
After filling out the text box and pressing the ok button on dlg2 (okay sets&lt;BR /&gt;
the variable) a message box pops up displaying the value in the variable,&lt;BR /&gt;
the dlg2 closes.  Back in dlg1, another message box appears, the value for&lt;BR /&gt;
the variable is now 0.&lt;BR /&gt;
&lt;BR /&gt;
Just wondering if somebody out there could tell me what I am doing wrong in&lt;BR /&gt;
defining a variable that has the ability to pass between dialogs?&lt;BR /&gt;
&lt;BR /&gt;
Thank you&lt;/SMCKENZIE&gt;&lt;/SPAMTHIS&gt;</description>
      <pubDate>Thu, 28 Jul 2005 23:27:21 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vba-forum/defining-a-globally-available-variable/m-p/1391750#M41834</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2005-07-28T23:27:21Z</dc:date>
    </item>
    <item>
      <title>Re: Defining a Globally available Variable</title>
      <link>https://forums.autodesk.com/t5/vba-forum/defining-a-globally-available-variable/m-p/1391751#M41835</link>
      <description>I would set the form to Modal at design time if&lt;BR /&gt;
needed, which is the default Modal is Readonly&lt;BR /&gt;
at runtime inVBA I believe.&lt;BR /&gt;
&lt;BR /&gt;
Create two forms each with a textbox1.&lt;BR /&gt;
Add following code to each see if it helps.&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
'userform1&lt;BR /&gt;
Private Sub UserForm_Click()&lt;BR /&gt;
    UserForm2.TextBox1.Text = _&lt;BR /&gt;
        Me.TextBox1.Text&lt;BR /&gt;
    Me.Hide&lt;BR /&gt;
    UserForm2.Show&lt;BR /&gt;
End Sub&lt;BR /&gt;
&lt;BR /&gt;
'userform2&lt;BR /&gt;
Private Sub UserForm_Click()&lt;BR /&gt;
    Me.Hide&lt;BR /&gt;
    UserForm1.Show&lt;BR /&gt;
End Sub&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
"bcbii" &lt;SMCKENZIE&gt; wrote in message &lt;BR /&gt;
news:4914353@discussion.autodesk.com...&lt;BR /&gt;
Hmm,&lt;BR /&gt;
&lt;BR /&gt;
Okay so I tried the following and still something isn't transferring over, i&lt;BR /&gt;
have a text box on dlg1 called txtInc, I make my changes in dlg2 in the text&lt;BR /&gt;
box called txtIncrement.  Now when I push okay, and return to dlg1, I have&lt;BR /&gt;
programmed the following code:&lt;BR /&gt;
&lt;BR /&gt;
Private sub cmdIncrement_click()&lt;BR /&gt;
&lt;BR /&gt;
   dlg2.Show vbModal&lt;BR /&gt;
&lt;BR /&gt;
   txtInc.text = dlg2.txtIncrement.Text&lt;BR /&gt;
&lt;BR /&gt;
End Sub&lt;BR /&gt;
&lt;BR /&gt;
From what I have done in other vb6 apps, this works, teh value from&lt;BR /&gt;
txtIncrement will be put into txtInc, but not in this app???&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
"Paul Richardson" &lt;SPAMTHIS&gt; wrote in message&lt;BR /&gt;
news:4914361@discussion.autodesk.com...&lt;BR /&gt;
it's the programming Gods telling you not to use global variables &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;BR /&gt;
If you must, place it in ThisDrawing. Better to create a Class Module.&lt;BR /&gt;
"bcbii" &lt;SMCKENZIE&gt; wrote in message&lt;BR /&gt;
news:4914327@discussion.autodesk.com...&lt;BR /&gt;
Hi,&lt;BR /&gt;
&lt;BR /&gt;
I do not understand what is so different between VBA and VB 6, but I was&lt;BR /&gt;
able to, in VB 6 to define a global variable by:&lt;BR /&gt;
&lt;BR /&gt;
Public 'Variable' As 'Type'&lt;BR /&gt;
&lt;BR /&gt;
This variable was defined like this in a Module (to keep things cleaner), if&lt;BR /&gt;
I do the same thing with VBA, the variable does not transfer between the&lt;BR /&gt;
dialogs.&lt;BR /&gt;
&lt;BR /&gt;
I define this variable in the class as above (it is an integer), in one&lt;BR /&gt;
dialog, I set its value from a text box in one dialog (call this one dlg2)&lt;BR /&gt;
(this dialog is started via a button in another dialog - ill call it dlg1).&lt;BR /&gt;
After filling out the text box and pressing the ok button on dlg2 (okay sets&lt;BR /&gt;
the variable) a message box pops up displaying the value in the variable,&lt;BR /&gt;
the dlg2 closes.  Back in dlg1, another message box appears, the value for&lt;BR /&gt;
the variable is now 0.&lt;BR /&gt;
&lt;BR /&gt;
Just wondering if somebody out there could tell me what I am doing wrong in&lt;BR /&gt;
defining a variable that has the ability to pass between dialogs?&lt;BR /&gt;
&lt;BR /&gt;
Thank you&lt;/SMCKENZIE&gt;&lt;/SPAMTHIS&gt;&lt;/SMCKENZIE&gt;</description>
      <pubDate>Fri, 29 Jul 2005 01:48:39 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vba-forum/defining-a-globally-available-variable/m-p/1391751#M41835</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2005-07-29T01:48:39Z</dc:date>
    </item>
    <item>
      <title>Re: Defining a Globally available Variable</title>
      <link>https://forums.autodesk.com/t5/vba-forum/defining-a-globally-available-variable/m-p/1391752#M41836</link>
      <description>The difference in this case is not between VBA and VB6.  The&lt;BR /&gt;
difference is in the code you have in the two.  You say that&lt;BR /&gt;
your global variable is declared as public in a module in VB6.&lt;BR /&gt;
That gives it application scope and lifetime.  In VBA you have&lt;BR /&gt;
it declared as public in a class.  That gives it application scope&lt;BR /&gt;
but class lifetime - when the object goes away, so does the&lt;BR /&gt;
variable that is a part of it.  If dlg2 is a UserForm whose hidden&lt;BR /&gt;
global "As New" variable is "dlg2" and when you say it gets&lt;BR /&gt;
closed you mean it gets unloaded then you need to extend&lt;BR /&gt;
the lifetime of  the object until you can retrieve the value.&lt;BR /&gt;
Try this based on the code in your second post:&lt;BR /&gt;
[code]&lt;BR /&gt;
Private Sub cmdIncrement_Click()&lt;BR /&gt;
    'dlg2.Show vbModal&lt;BR /&gt;
    Dim d As dlg2&lt;BR /&gt;
    Set d = New dlg2&lt;BR /&gt;
    d.Show vbModal&lt;BR /&gt;
    'txtInc.Text = dlg2.txtIncrement.Text&lt;BR /&gt;
    txtInc.Text = d.txtIncrement.Text&lt;BR /&gt;
    Set d = Nothing&lt;BR /&gt;
End Sub&lt;BR /&gt;
[/code]</description>
      <pubDate>Fri, 29 Jul 2005 11:54:59 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vba-forum/defining-a-globally-available-variable/m-p/1391752#M41836</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2005-07-29T11:54:59Z</dc:date>
    </item>
  </channel>
</rss>

