|
|
|
|
|
Over the past few articles, we have discussed the interface designing part in VB. Let us now get to the basic of Visual Basic. And the basic of every programming language is its supported data types Let us start with variables. if you are a programmer, you should be knowing all these and can safely skip this part. Others please continue. Whatever data you are supposed to store on your program are stored in what we call as variables. Think of a variable as a jar that can hold various chocolates; you never know how many chocolates are in the jar at any given time unless you look in the jar. The same is true for a variable. A variable can hold a different value at different times. You programmatically look into it to find out its value. The name is given because the value held by the variable varies throughout the program. You use variables when you know that you'll have to deal with a quantity at some point but don't know its present value--such as the balance of your checking account. You know the account's balance today, but you have no idea what the balance will be in a month. Declaring VariablesYou create (that is, declare) a variable by using the following form: Dim Var As DataType Here Dim is a keyword defined by VB. Var is the name you will give to your variable. DataType is the predefined type of which you define your variable. Example: Dim counter as Integer Give sensible and context-related names to the variables. Though this is not imperative, it is advisable so that understanding and debugging of the program is simplified. Sizing variablesAt some point you may wonder whether you're using a variable of the right size, particularly with regard to numbers. A good rule of thumb is to go with the larger variable size if you don't have a very good idea of what the limit of your variable will be. For example, if you think that your program at some point might be required to use numbers with decimals or fractions, you might want to use Double and Single variable types instead of Integers and Longs. We have not yet discussed the data types supported by visual basic. This is because the scope of this is large and I want to devote an entire article to it. So in the next article, we take a look at the data types supported by VB6. Don't miss out.
Go To Page: 1
The copyright of the article Variables in VB in Learning Visual Basic is owned by Swapna Kamat. Permission to republish Variables in VB in print or online must be granted by the author in writing.
|
|
|
|