|
-
Nov 28th, 2000, 01:43 PM
#1
Thread Starter
Lively Member
For simplicity's sake, I need to change the base of an array from 0 to 1. I know that I can set it like
i=5
for i = 1 to i
however I remember reading or doing something somewhere where I changed the base in the general declarations of the function or sub. What did I do. Does this take effect universally? Thanks!
-
Nov 28th, 2000, 01:52 PM
#2
Used atmodule level to declare the default lower bound forarray subscripts.
Syntax
Option Base {0 | 1}
Remarks
Because the default base is 0, the Option Base statement is never required. If used, thestatement must appear in amodule before anyprocedures. Option Base can appear only once in a module and must precede arraydeclarations that include dimensions.
Note The To clause in the Dim, Private, Public, ReDim, and Static statements provides a more flexible way to control the range of an array's subscripts. However, if you don't explicitly set the lower bound with a To clause, you can use Option Base to change the default lower bound to 1. The base of an array created with the the ParamArray keyword is zero; Option Base does not affect ParamArray (or the Array function, when qualified with the name of its type library, for example VBA.Array).
The Option Base statement only affects the lower bound of arrays in the module where the statement is located.
-
Nov 28th, 2000, 02:41 PM
#3
Frenzied Member
Technique!
Option Base should not be used. It is a bad technique.
You should explicitly declare all array bounds.
Code:
Dim MyFirstArray(0 to 25, 1 to 50)
Dim MotherArray(1 to 7)
In many years as a Mainframe programmer, I saw much time wasted by myself and others due to relying on system defaults and/or statements like "Option Base". Where conveneient to do so, it is alwaysw better to avoid syntax which affects code far from where the syntax is placed.
I always initialize variables that should be initialized, even though I know that VB does it for me. Once in a while, the VB initialize is not what I want. While I do not initialize Variables used in For-next Loops (The for does it explicitly), I do initialize various temporay variables. For example a friend of mine went nuts recently because he did a quick modify of a Function which hunted for the maximum value in an array. He wanted it to find a minimum value. He changed the conditional tests, but never initialized a temp variable. The VB default zero initialize worked fine for finding the max, but left something to be desired when hunting for a minimum.
Live long & prosper.
The Dinosaur from prehistoric era prior to computers.
Eschew obfuscation!
If a billion people believe a foolish idea, it is still a foolish idea!
VB.net 2010 Express
64Bit & 32Bit Windows 7 & Windows XP. I run 4 operating systems on a single PC.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|