![]() |
![]() |
|
|||||||
| Excel Questions All Excel/VBA questions - formulas, macros, pivot tables, general help, etc. Please post to this forum in English only. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Board Regular
Join Date: Feb 2002
Posts: 117
|
How do you declare a varible such as X to be listed as public? If I code in:
Option Explicit Public x as Integer on one form, how do you get the value of X on another form? I thought if you Public a varible on one form, it see's it on every other form and module. Can someone explain this to me? |
|
|
|
|
|
#2 |
|
MrExcel MVP
Join Date: Feb 2002
Location: Portland, OR USA
Posts: 1,374
|
Form modules are class modules, so a global variable in a form can't be seen by other modules. If you want a variable that can be seen by multiple forms, declare it in a regular module.
Hope this helps, Russell |
|
|
|
|
|
#3 |
|
Board Regular
Join Date: Feb 2002
Posts: 117
|
So what your saying Russel is that you can only declare a global varible in a regular module, but not on a form? So why does VB allow you to make a public statement on a form, when it dosnt do anything?
Anyway, here's the scoop; I have four checkboxes that are in one frame (Ive created an array). The X varible = the checkboxes index property. So if X=index in the Check1_Click event of a form, how does one get the value of X in another form to read the index property in this form?? |
|
|
|
|
|
#4 | |
|
MrExcel MVP
Join Date: Feb 2002
Location: Portland, OR USA
Posts: 1,374
|
Quote:
Userform1.X where X is your public form variable. This isn't the best way to do this, but it will work. You can control who can set / retrieve your form variables using Property Let and Property Get. But if you're only using it for other forms to read, the above way should be good enough. Hope this was clear, Russell |
|
|
|
|
![]() |
| Bookmarks |
| Thread Tools | |
| Display Modes | |
|
|