By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,845 Members | 1,272 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,845 IT Pros & Developers. It's quick & easy.

From The Old Times

P: 1
I used to be a Fortran programmer, trying now VB. It atosnishes me that "initial values asigned to a program", at the very top of the VB code took the new values calculated else were is it that a "normal" feature for VB or thre's something wrong with the VB version I've got?
Thanks for the answers
Aug 26 '08 #1
Share this Question
Share on Google+
2 Replies

Expert Mod 2.5K+
P: 2,545
Hi, and Welcome to Bytes!

If variables are declared at the top of a code module instead of within each procedure or subroutine they will be global in scope to that module. Further, if the code is in a public module (one which Access shows in the Modules tab, and not form or report code modules which are effectively private in scope) then such variables are global to the whole application. In such circumstances values can be carried forward from a previous use.

This can also happen if a variable is defined using the Static keyword to allow values to be retained between procedure calls, instead of being destroyed on completion. And one other circumstance springs to mind: parameters passed to subroutines and functions are passed by reference by default (as pointers to the actual value) so changes made to such values within the sub or function will also change the local copy of the variable in the calling routine - a sort of deliberate side effect - unless the keyword ByVal is used to ensure that the value alone is passed.

The norm in VB and VBA is to define variables within local functions and subroutines, not globally to the code module unless there is a need for such global variables. Further, even though VBA uses implied default values for variables (0 for numeric values, empty strings for strings, and so on), it is good practice not to rely on this but to explicitly zero or specify the state for the variables used.

I am not sure from what you wrote if any of these situations applies to you; it would have helped if you had posted a sample of your code for us to see.

Aug 26 '08 #2

Expert 2.5K+
P: 3,532
Stew has given an excellent overview on the use of variables within Access VBA. Like Stewart, I'm not sure if it will be of any use to you because, to be frank, I have no idea what
It atosnishes me that "initial values asigned to a program", at the very top of the VB code took the new values calculated else were
means. Perhaps if you could review your original post and rephrase it more clearly we could be of more help to you.

Linq ;0)>
Aug 27 '08 #3

Post your reply

Sign in to post your reply or Sign up for a free account.