144 CHAPTER 5 STORING AND RETRIEVING APPLICATION (Web site templates)
Monday, April 7th, 2008144 CHAPTER 5 STORING AND RETRIEVING APPLICATION DATA Determining Variable Scope A key concept you should be aware of when working with variables is scope. A variable s scope determines which parts of your REALbasic application can access a variable. Variables declared using the Dim statement are local in scope, which means the variables can only be accessed within the method where they were defined. For example, if you declare a variable named strUserName in a method belonging to a PushButton control, that variable can only be accessible by other programming statements associated with that method. You can declare a variable anywhere you want within a method, just as long as you declare it before other code statements that reference it. You can further refine variable scope with methods by declaring variables within If Then statements and looping statements. These types of statements, and any code stored within them, represent a block of code. Any variable declared within a code block is local only to that code block. For example, the following example shows a declaration statement located inside an If Then code block. Any other code statements in the method where this If Then code block resides will be unable to access the variable. Information on how to work with If Then and looping statements is available in Chapters 6 and 7. If intUserAge > 21 Then Dim blnAccessFiles As Boolean blnAccessFiles = True End If If, on the other hand, you need to set up a variable with a broader scope, you can add a module to your application and define the variable within the module. This gives the variable a global scope, meaning it can be accessed from any part of the application. Modules are dis cussed in Chapter 8. Tip In addition to being considered a good programming practice, limiting the scope of variables help to prevent the code in one part of your application from accidentally changing a similarly named variable s value in another part of your application. Converting Between Data Types As you work with variables in your REALbasic applications, at times, you might need to convert the data type of values stored in properties and variables. For example, any time you use an EditField control to collect numeric data from users, you need to convert that data from string to a numeric format because REALbasic treats anything entered into an EditField control as a string.
If you are in need for chaep and reliable webhost to host your website, our recommendation is http web server services.