Thirteen Ways to loathe VB
corliss at alaskapm.org
corliss at alaskapm.org
Wed Mar 22 14:22:29 CST 2000
Greetings:
Recently ran across this article by Verity Stob, and I had to pass it on.
:-)
==============================================================================
Thirteen ways to loathe VB
==========================
Verity Stob has recently been press-ganged into a
Visual Basic project. For the benefit of other programmers who may be
brought down in this way, she has prepared an executive summary of her
experience.
1. Procedure and function call. This area of Basic has come on in leaps and
bounds. Whereas in the bad old days you had to use GOSUB, these days you
have subs ('subs' is the preferred baby-speak for what grown-ups call
procedures or void functions) and functions. You write:
Subname Param1, Param2
to call sub Subname and:
Result = FuncName(Param1, Param2)
to call function FuncName. Notice the useful difference in syntax, with and
without parentheses, which serves more purposes than I can describe. It is of
course a syntax error to write:
Subname(Param1, Param2)
but the good news is you can write:
FuncName(Param1, Param2)
to call a function and ignore its return. However, if Param1 or Param2
are reference parameters - and they will be unless you have specifically
demanded value parameters - they will be treated in this specific case as
value parameters, and any assignment to them discarded on exit from
FuncName.
Obviously the syntax:
Call FuncName(Param1, Param2)
fixes this, and causes Param1 and Param2 to be treated as reference
parameters.
Right.
2. Variable declaration. This is achieved using the intuitive keyword Dim.
To declare an integer I write
Dim I As Integer
To declare a whole load of integers write:
Dim I, J, K, L As Integer
Actually (haha got you!) this doesn't work. This declares I, J, and K as
variants and only L as an Integer. This almost never matters, except quite
often.
3. Calling functions and accessing arrays. In most languages you can
distinguish between a call to function F with parameter 3 and a reference to
array F index 3 because one is written F(3) and the other F[3]. In Visual
Basic they are both written F(3).
Yes.
4. Another thing about arrays. The index of the first element is 0, unless
it is set to 1 by a directive.
5. But there are also collections, modern object-oriented versions of arrays.
And the first element of these is usually 1, unless it happens to be 0.
Sometimes it is 0 and sometimes it is 1, depending on where you found it. Do
you feel lucky, punk? Well, do ya?
6. Did I mention 'object-oriented' back there? Hahahahahahahahahahahahaha.
7. Initialisation. This area of Basic has come on in leaps and bounds.
Whereas in the bad old days you had to use a completely barbaric mechanism
based on the keywords DATA and READ, this has now been swept away. The
fragment below illustrates the modern way to initialise an array in code.
Dim A(20) As Double
A(0) = 4.5 May work, may not, who can tell?
A(1) = 4.71
A(2) = 4.82
A(3) = 4.92
...
You get the idea.
8. Arrays of constants. No such thing. Anyway, what would you do with 'em if
you had 'em?
9. The type Integer declares a 16-bit integer. That's right, sixteen bits.
Yes I am using the latest version. Unbelievable, isn't it? Lets have a big
warm EXE welcome back to code that dies suddenly around the 33 KB mark.
10. Assignment. This area of BASIC has come on in leaps and bounds. Whereas
in the bad old days you used the operator for assignment, preceding it with
LET if you were a fusspot of the first order, these days you use the =
operator for assignment. Or Set if it's an object. Which is compulsory not
optional.
11. Logic. This particular language is supposed to be easy and intuitive, so
here's a test for you. Suppose that Check1 is a checkbox on a form, and you
execute the code:
Dim b As Boolean, c As Boolean
b = Check1.Value
c = Not Check1.Value
Then b as expected will contain True if the checkbox is checked and False
if the checkbox is unchecked. What do you think c will contain? (Clue: always
True. No, really.)
12. The four magic constants of the apocalypse:
Nothing,
Null,
Empty,
and Error.
12.5 The stupid editor, which by default will put up a whining dialog if you
try to leave a line which it recognises as syntactically incorrect. Like when
you leave an incomplete line temporarily to go and copy a long identifier into
the clipboard, for example.
12.7 The stupid compiler, which by default does a 'compile' so superficial
that you can get runtime errors caused by an If missing its End If.
12.8 Procedures, sorry 'Subs', can be declared Public, Private, or Static.
Two points to anybody who correctly guesses what Static does. Three points to
anybody who can suggest a sane use for it.
13. Bill is making even more money out of this. And I am powerless to stop
him. In fact, I am helping him.
=============================================================================
--Arthur Corliss
Perl Monger/Alaska Perl Mongers
http://www.alaskapm.org/
=================================================
Mailing list info: If at any time you wish to (un|re)subscribe to
the list send the request to majordomo at hfb.pm.org. All requests
should be in the body, and look like such
subscribe anchorage-pm-list
unsubscribe anchorage-pm-list
More information about the Anchorage-pm
mailing list