Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,494
Default strange problem with public variable

maybe someone can tell me if this is a bad idea, too.

i use a public variable to set the path and set it in the workbook open module
to keep from setting the path in 12 different modules.
Public fPath As String is in a standard module

If UCase(Environ("username")) = "GARYK" Then
fPath = ThisWorkbook.Path & "\Blends\"
Else
fPath = "\\Customers\Blends\"
End If
is in the workbook open module

i noticed i was losing the path, it was resetting to an empty string. what
caused it was going to the module with the public variables, making a change and
recompiling. even if i just deleted a space, it still reset the variable,

so my question is: is this a bad idea and will this ever reset during the course
of normal operation for my client? they never enter the vbe.



--


Gary



  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default strange problem with public variable

It depends on what your code does.

If you have any End statements (not "end if", "end Function", "end sub", "end
with" and the like), your variables will be reset.

Personally, I think adding an initialization routine wouldn't be a bad idea.

In a general module:

Public VarsAreInitialized As Boolean
Public fPath As String
'and as many more as you need

Sub InitializeVars()
If UCase(Environ("username")) = "GARYK" Then
fPath = ThisWorkbook.Path & "\Blends\"
Else
fPath = "\\Customers\Blends\"
End If
varsareinitialized = true
end sub

Then in your workbook_open event, replace the if/then/else code with Call
statement.

Call InitializeVars

And before you use any of these variables in any routine:

If varsareinitialized = false then
call initializevars
end if

It may save you some problems later. And makes changing and testing easier,
too.

Gary Keramidas wrote:

maybe someone can tell me if this is a bad idea, too.

i use a public variable to set the path and set it in the workbook open module
to keep from setting the path in 12 different modules.
Public fPath As String is in a standard module

If UCase(Environ("username")) = "GARYK" Then
fPath = ThisWorkbook.Path & "\Blends\"
Else
fPath = "\\Customers\Blends\"
End If
is in the workbook open module

i noticed i was losing the path, it was resetting to an empty string. what
caused it was going to the module with the public variables, making a change and
recompiling. even if i just deleted a space, it still reset the variable,

so my question is: is this a bad idea and will this ever reset during the course
of normal operation for my client? they never enter the vbe.

--

Gary


--

Dave Peterson
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,494
Default strange problem with public variable

thanks for the idea, dave.

--


Gary


"Dave Peterson" wrote in message
...
It depends on what your code does.

If you have any End statements (not "end if", "end Function", "end sub", "end
with" and the like), your variables will be reset.

Personally, I think adding an initialization routine wouldn't be a bad idea.

In a general module:

Public VarsAreInitialized As Boolean
Public fPath As String
'and as many more as you need

Sub InitializeVars()
If UCase(Environ("username")) = "GARYK" Then
fPath = ThisWorkbook.Path & "\Blends\"
Else
fPath = "\\Customers\Blends\"
End If
varsareinitialized = true
end sub

Then in your workbook_open event, replace the if/then/else code with Call
statement.

Call InitializeVars

And before you use any of these variables in any routine:

If varsareinitialized = false then
call initializevars
end if

It may save you some problems later. And makes changing and testing easier,
too.

Gary Keramidas wrote:

maybe someone can tell me if this is a bad idea, too.

i use a public variable to set the path and set it in the workbook open
module
to keep from setting the path in 12 different modules.
Public fPath As String is in a standard module

If UCase(Environ("username")) = "GARYK" Then
fPath = ThisWorkbook.Path & "\Blends\"
Else
fPath = "\\Customers\Blends\"
End If
is in the workbook open module

i noticed i was losing the path, it was resetting to an empty string. what
caused it was going to the module with the public variables, making a change
and
recompiling. even if i just deleted a space, it still reset the variable,

so my question is: is this a bad idea and will this ever reset during the
course
of normal operation for my client? they never enter the vbe.

--

Gary


--

Dave Peterson



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
Public variable Eric[_35_] Excel Programming 7 March 18th 07 06:54 AM
Public variable problem moonhk Excel Programming 13 December 8th 06 08:38 AM
Public variable Jack New Users to Excel 4 March 18th 06 09:35 PM
Public Variable Jason Excel Programming 4 April 12th 04 07:06 PM
public variable marwan hefnawy Excel Programming 1 September 5th 03 08:54 AM


All times are GMT +1. The time now is 06:32 PM.

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

About Us

"It's about Microsoft Excel"