Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
Retreive a variable
Is it possible for my UserForm code to retrieve a variable declared and set in the main procedure? I am testing to see if the code is run on my computer or not. I already have this Boolean value set in the main procedure but I do not see how to retrieve this value from my UseForm code. I could run the test again from the UserForm but I have run across this problem before and thought I might seek a solution. I should say that I have already thought of creating a Static function that holds this value. I am just curious if there is a easier (better) way? -- |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
Retreive a variable
On Apr 12, 2:10 pm, "R P" wrote:
Is it possible for my UserForm code to retrieve a variable declared and set in the main procedure? I am testing to see if the code is run on my computer or not. I already have this Boolean value set in the main procedure but I do not see how to retrieve this value from my UseForm code. I could run the test again from the UserForm but I have run across this problem before and thought I might seek a solution. I should say that I have already thought of creating a Static function that holds this value. I am just curious if there is a easier (better) way? -- See if you can massage your code to look like this: Private Sub MainProcedure() ... ... bnVariable = ... Call LoadForm(bnVariable) End Sub '-------------------------------- Private Sub LoadForm(Result as Boolean) Load Form1 Form1.TextBox1.Value = Result Form1.Show End Sub Is that what you're looking for?? Chris |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
Retreive a variable
Actually I need the opposite. Something like this:
Sub Main() Dim my_computer as Integer If (InStr(1, LCase(Environ("UserProfile")), "randy") Or_ InStr(1, LCase(Environ("UserProfile")), "safety")) Then mycomputer = 1 .. .. End Sub Private Sub UserForm_Initialize() Dim my_computer as Integer my_computer = Main.my_computer End Sub Except Main.my_computer does not work "cht13er" wrote in message ... On Apr 12, 2:10 pm, "R P" wrote: Is it possible for my UserForm code to retrieve a variable declared and set in the main procedure? I am testing to see if the code is run on my computer or not. I already have this Boolean value set in the main procedure but I do not see how to retrieve this value from my UseForm code. I could run the test again from the UserForm but I have run across this problem before and thought I might seek a solution. I should say that I have already thought of creating a Static function that holds this value. I am just curious if there is a easier (better) way? -- See if you can massage your code to look like this: Private Sub MainProcedure() ... ... bnVariable = ... Call LoadForm(bnVariable) End Sub '-------------------------------- Private Sub LoadForm(Result as Boolean) Load Form1 Form1.TextBox1.Value = Result Form1.Show End Sub Is that what you're looking for?? Chris |
#4
Posted to microsoft.public.excel.programming
|
|||
|
|||
Retreive a variable
InStr(1, LCase(Environ("UserProfile")), "safety")) Then mycomputer = 1
Assuming your use of mycomputer instead of my_computer was simply a typo, add a Module to your project and put this declaration in its code window... Public my_computer As Integer Then, make sure you remove this line... Dim my_computer as Integer from the Main subroutine. As long as you do not declare a my_computer variable in any of your procedures, every procedure will have (read and write) access to the globally available my_computer variable. Rick "R P" wrote in message . .. Actually I need the opposite. Something like this: Sub Main() Dim my_computer as Integer If (InStr(1, LCase(Environ("UserProfile")), "randy") Or_ InStr(1, LCase(Environ("UserProfile")), "safety")) Then mycomputer = 1 . . End Sub Private Sub UserForm_Initialize() Dim my_computer as Integer my_computer = Main.my_computer End Sub Except Main.my_computer does not work "cht13er" wrote in message ... On Apr 12, 2:10 pm, "R P" wrote: Is it possible for my UserForm code to retrieve a variable declared and set in the main procedure? I am testing to see if the code is run on my computer or not. I already have this Boolean value set in the main procedure but I do not see how to retrieve this value from my UseForm code. I could run the test again from the UserForm but I have run across this problem before and thought I might seek a solution. I should say that I have already thought of creating a Static function that holds this value. I am just curious if there is a easier (better) way? -- See if you can massage your code to look like this: Private Sub MainProcedure() ... ... bnVariable = ... Call LoadForm(bnVariable) End Sub '-------------------------------- Private Sub LoadForm(Result as Boolean) Load Form1 Form1.TextBox1.Value = Result Form1.Show End Sub Is that what you're looking for?? Chris |
#5
Posted to microsoft.public.excel.programming
|
|||
|
|||
Retreive a variable
Thanks Rick,
Yes, that was a typo I added that global declaration to my main module and it seems to work great. Was there a reason why you wanted me to add a module rather than declaring it in my main module? "Rick Rothstein (MVP - VB)" wrote in message ... InStr(1, LCase(Environ("UserProfile")), "safety")) Then mycomputer = 1 Assuming your use of mycomputer instead of my_computer was simply a typo, add a Module to your project and put this declaration in its code window... Public my_computer As Integer Then, make sure you remove this line... Dim my_computer as Integer from the Main subroutine. As long as you do not declare a my_computer variable in any of your procedures, every procedure will have (read and write) access to the globally available my_computer variable. Rick "R P" wrote in message . .. Actually I need the opposite. Something like this: Sub Main() Dim my_computer as Integer If (InStr(1, LCase(Environ("UserProfile")), "randy") Or_ InStr(1, LCase(Environ("UserProfile")), "safety")) Then mycomputer = 1 . . End Sub Private Sub UserForm_Initialize() Dim my_computer as Integer my_computer = Main.my_computer End Sub Except Main.my_computer does not work "cht13er" wrote in message ... On Apr 12, 2:10 pm, "R P" wrote: Is it possible for my UserForm code to retrieve a variable declared and set in the main procedure? I am testing to see if the code is run on my computer or not. I already have this Boolean value set in the main procedure but I do not see how to retrieve this value from my UseForm code. I could run the test again from the UserForm but I have run across this problem before and thought I might seek a solution. I should say that I have already thought of creating a Static function that holds this value. I am just curious if there is a easier (better) way? -- See if you can massage your code to look like this: Private Sub MainProcedure() ... ... bnVariable = ... Call LoadForm(bnVariable) End Sub '-------------------------------- Private Sub LoadForm(Result as Boolean) Load Form1 Form1.TextBox1.Value = Result Form1.Show End Sub Is that what you're looking for?? Chris |
#6
Posted to microsoft.public.excel.programming
|
|||
|
|||
Retreive a variable
I wasn't thinking when I wrote that... your Main subroutine is already in a
Module, so you can use that. Just put the Public variable declaration in the (General)(Declarations) section; that is, not within any procedures. Rick "R P" wrote in message . .. Thanks Rick, Yes, that was a typo I added that global declaration to my main module and it seems to work great. Was there a reason why you wanted me to add a module rather than declaring it in my main module? "Rick Rothstein (MVP - VB)" wrote in message ... InStr(1, LCase(Environ("UserProfile")), "safety")) Then mycomputer = 1 Assuming your use of mycomputer instead of my_computer was simply a typo, add a Module to your project and put this declaration in its code window... Public my_computer As Integer Then, make sure you remove this line... Dim my_computer as Integer from the Main subroutine. As long as you do not declare a my_computer variable in any of your procedures, every procedure will have (read and write) access to the globally available my_computer variable. Rick "R P" wrote in message . .. Actually I need the opposite. Something like this: Sub Main() Dim my_computer as Integer If (InStr(1, LCase(Environ("UserProfile")), "randy") Or_ InStr(1, LCase(Environ("UserProfile")), "safety")) Then mycomputer = 1 . . End Sub Private Sub UserForm_Initialize() Dim my_computer as Integer my_computer = Main.my_computer End Sub Except Main.my_computer does not work "cht13er" wrote in message ... On Apr 12, 2:10 pm, "R P" wrote: Is it possible for my UserForm code to retrieve a variable declared and set in the main procedure? I am testing to see if the code is run on my computer or not. I already have this Boolean value set in the main procedure but I do not see how to retrieve this value from my UseForm code. I could run the test again from the UserForm but I have run across this problem before and thought I might seek a solution. I should say that I have already thought of creating a Static function that holds this value. I am just curious if there is a easier (better) way? -- See if you can massage your code to look like this: Private Sub MainProcedure() ... ... bnVariable = ... Call LoadForm(bnVariable) End Sub '-------------------------------- Private Sub LoadForm(Result as Boolean) Load Form1 Form1.TextBox1.Value = Result Form1.Show End Sub Is that what you're looking for?? Chris |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Retreive a deleted file | Excel Discussion (Misc queries) | |||
How do I retreive the last # in a column? | Excel Worksheet Functions | |||
retreive Access via ADO | Excel Programming | |||
help with retreive print | Excel Programming | |||
Retreive information from One Sheet to Another | Excel Discussion (Misc queries) |