Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
R P R P is offline
external usenet poster
 
Posts: 4
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 141
Default 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   Report Post  
Posted to microsoft.public.excel.programming
R P R P is offline
external usenet poster
 
Posts: 4
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default 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   Report Post  
Posted to microsoft.public.excel.programming
R P R P is offline
external usenet poster
 
Posts: 4
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default 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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Retreive a deleted file Janet Excel Discussion (Misc queries) 2 May 14th 10 11:38 AM
How do I retreive the last # in a column? Claudio Excel Worksheet Functions 2 February 21st 09 12:00 AM
retreive Access via ADO Souris Excel Programming 0 February 24th 08 03:11 AM
help with retreive print chessieman Excel Programming 1 September 22nd 05 01:00 PM
Retreive information from One Sheet to Another Vladymir Excel Discussion (Misc queries) 2 July 22nd 05 01:01 AM


All times are GMT +1. The time now is 07:59 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"