Solved

Sorry, this is not a question, but informations to those who are giving the first steps on VB

Posted on 2000-05-04
36
226 Views
Last Modified: 2010-05-02
I've found on the net this article that may help those who are giving the first steps on Visual Basic. Hope it helps...
(It is not my intention underestimate the good things on VB...so, sorry VB lovers)

"Stob - January 2000


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? Let's 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, preceding it with Let if you are a fusspot of the
first order. 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."
0
Comment
Question by:mbarreto022800
  • 10
  • 10
  • 7
  • +3
36 Comments
 

Author Comment

by:mbarreto022800
Comment Utility
BTW:Your free to comment...
0
 
LVL 14

Expert Comment

by:mcrider
Comment Utility
More like 16 ways.... ;-)
0
 
LVL 14

Expert Comment

by:mcrider
Comment Utility
Going for those 3 points with static...


Public Static Function Counter()
    Dim iVal: iVal = iVal + 1: Counter = iVal
End Function


Every time you call the Function Counter, you get the next number... starting at 1 until you terminate your program.


Cheers!®©
0
 
LVL 14

Expert Comment

by:mcrider
Comment Utility
As in:

   Dim X
   X=Counter 'X is 1
   X=Counter 'X is now 2
   X=Counter 'X is now 3

;-)
0
 

Author Comment

by:mbarreto022800
Comment Utility
You know, I have worked in Unix systems for 4 years, using C .
I'm working in windows in the last 2 years, using VB...now i know the meaning of fustrated :).
Some things are more interessing and neat in Bill's world, but in the other hand is very fustrating having to handle with our bugs, windows bugs and VB bugs...
Imagine all the bugs generated around the world by programers that don't this "traps" on VB code. And in most cases they don't really know what they did wrong, making them lose a lot of hours in front of the PC.
I think Bill should pay all this hours, dont you :) ?

Cheers!
0
 
LVL 38

Expert Comment

by:PaulHews
Comment Utility
Hey mcrider, that's 5 points for static!
(2 for guessing what it does.)
If you submit the same answer again do you get 10 points?

Also she left out the under-documented print methods, the wonderful printer object and what happens if you leave out Option Explicit (which is the default behaviour of the IDE)

Yeah there are a few problems with the language and environment, but it's still so much quicker to develop (certain kinds of) Windows apps with it.

Some of this is avoidable:
7. Dim A as variant

A = Array(4.5, 4.71, ....)

8.  Ever heard of enum (yeah, I know it's not quite the same.)

9.  Ever heard of Long?

10. Ok, she's just being silly now.  Assignment in C?  x = 1;  VB? x = 1
I know the = operator is overloaded for comparisons, but what's so tricky about that?  The use of Set is useful to remind you that you are using a different kind of variable (Object reference.)  It's rarely a big problem.

12.5 Turn off syntax checking in options.  The code coloring will still notify you of a syntax error.

12.7 Full (CTRL+F5) compile is just as accessible as Run (F5)

For the most part part, tho' I have to agree.  Guilty as charged.

0
 
LVL 12

Expert Comment

by:mark2150
Comment Utility
Has anyone but me noticed a really *odd* state-sensitive *BUG* in the VB environment?

If you're using the .Line command in a routine, and you set a breakpoint in a sub and you change something in that sub when you attempt to resume execution you get a error on a perfectly good line? You have to stop the project, make a nonsense change to the line (like changing it's indentation by one space either way) and then restart

How about this one?

You minimize the IDE and if you use <Alt Tab> it doesn't show up on the task list. When you maximize it from the taskbar you only get the very top bar of the window. If you click on [_] twice it comes back to full screen again.

Or how about the one where the screen doesn't repaint in the IDE properly and when you move controls they leave 'shadows' or 'holes' on the screen?

Or who was the idiot that defaulted the IDE *NOT* to automatically save the project when you click on [Run].

M
0
 

Author Comment

by:mbarreto022800
Comment Utility
I have to agree with PaulHews that many problems programers have, is due the fact that they don't know very well to use the IDE.
But I don't agree with the mutch quicker to develop thing. I think that's ok if you are wrinting an app for home use. But building comercial apps in VB, in most of the cases quicker means that you'r going to loose a lot of time tracking bugs.
And the fact that some of them are result from VB (...and sometimes windows  itself), is the main problem.

0
 
LVL 12

Expert Comment

by:mark2150
Comment Utility
Debugging in VB is a nightmare when you start getting sequence sensitivities and events firing in unexpected orders.

One thing that would help but got dropped in the conversion from QBASIC to VB is the <Back up> button. Used to be in the old DOS QB-IV days you could single step with <F8> and step *backwards* with <Shift F8>. That way you could set a breakpoint at an entry into a subroutine, step back and find out where the routine was being called from.

I've also seen bugs that only show at full speed but work fine when single stepping. These also tend to be event sequence sensitive.

M
0
 

Author Comment

by:mbarreto022800
Comment Utility
That's wright..and you have have forgoten the bugs that only apear on the executable and not on the IDE.
That's neat, you shoul'd try :)).

Cheers!
0
 

Author Comment

by:mbarreto022800
Comment Utility
Ok, this is supose to help newbies on VB.
Not to make them think that VB is a nightmare...ok, sometimes it is :), but we have problems on every languages. Some are worse than anothers, but we have to handle it.
What matters, is that we share this kind of information, because Microsoft makes people think that it's all very easy, and very potent at the same time :)...

Cheers.
0
 
LVL 15

Expert Comment

by:ameba
Comment Utility
She is frustrated because VB syntax is 'different'. This is very primitive, it's equivalent to racism.
0
 
LVL 12

Expert Comment

by:mark2150
Comment Utility
Not 'different', *inconsistent*. That array index/control index issue is a pain. Just sloppy workmanship on M$'s part. Like leaving out the .Print method on the M$Chart control.

Don't get me wrong. I like VB. I'm good at VB. But I'd rather see more stability and follow thru than these endless new versions that keep you on the M$ upgrade treadmill.

Do we really *need* a new OS version ever couple of years? Why not *stabilize* the one they've got.

If a service pack includes new features, then it's not a "service pack" but an "upgrade". If these new features now require you to upgrade the rest of your system/software then this is *extortion*. A service pack should *NOT* add new features. It should ONLY fix known bugs.

VB is a deceptive language. It gives the illusion that programs can be rapidly developed because you can create pretty screens quickly. However this is illusionary because while the screen development time is shortened then debugging and coding time to get things *working* in a real system has gone up exponentially.

M
0
 
LVL 15

Expert Comment

by:ameba
Comment Utility
>That array index
If you mean 3.:
3. is advantage. Some editors do not support [] with some keyboard definitions.

So, I can use Notepad to write few code lines:
   F(3) = 55
I cannot type this in Notepad:
   F[3] = 55
'[' is AltGr-F, when I press AltGr, it activates menu.
0
 

Author Comment

by:mbarreto022800
Comment Utility
What do you think about n. 5, ameba ?
0
 

Author Comment

by:mbarreto022800
Comment Utility
What do you think about n. 5, ameba ?
0
 

Author Comment

by:mbarreto022800
Comment Utility
Sorry about the eco :)...
I think that no one here is trying to "bring down" VB. And I think that she's not frustated only because VB is different.
Her frustations today, may be yours tomorow.
Imagine you are in a boat that floats, but is linking water by all this "tiny holes". You think your making a save journey but then in the middle of it, you feel water on your knees. That's ok, if you made accidentaly those holes.
But wen you find out that they already came with the boat... that's her frustation.


0
 
LVL 15

Expert Comment

by:ameba
Comment Utility
Instead of this primitive, trying to be humorous, non-competent article written by very frustrated person, I suggest:

http://www.vb2themax.com/ItemBank.asp?PageID=MistakeBank
It is useful, and no Hahahaha-s.

>What do you think about n. 5

>>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.

I use Index to move elements up/down in collection, but I have never seen first Index to be 0. Always 1.
0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 38

Expert Comment

by:PaulHews
Comment Utility
mark2150:

I know there is no backup command, but isn't the calling stack a better way to see where the call came from?  

Also, you can back up a little by dragging the yellow current instruction pointer back up the page.  (Not the same I know, as the instructions executed are not "undone," but careful use can help.  Also you can't step back out of a sub that has been called with this, which is a bummer.)

I agree that the UI is the easiest thing to set up and the trickiest thing to debug!
0
 
LVL 12

Expert Comment

by:mark2150
Comment Utility
Combo box listindex starts at 0 not 1...

M
0
 
LVL 15

Expert Comment

by:ameba
Comment Utility
Yes, it can be very frustrating to change language. New rules, you are a newbie...
0
 
LVL 15

Expert Comment

by:ameba
Comment Utility
Combo box listindex starts at 0 not 1...
This is not a VBA.Collection.
0
 

Author Comment

by:mbarreto022800
Comment Utility
ok, ameba, every one is a critic...
maybe we all are getting used to the "mistakes" that we can't commit.
But I don't think that is normal that a programer should have to worry about microsoft "mistakes".
I've used C on Unix and it was a very "primitive" work, using vi editor and command line compiling, linking ...
but i have never had to worry about bugs on the compiler or even on the operating system. not even whith service packs...
0
 
LVL 2

Expert Comment

by:bhamilto
Comment Utility
Does anyone know why the default is TWIPS?  Usually I don't care - or if I do I want pixels.
0
 
LVL 15

Expert Comment

by:ameba
Comment Utility
tradition?

"The twip is 1/20th of a point, a traditional measure in printing"

http://www.whatis.com/twip.htm






50 EE points = 1000 EE twips ?
0
 
LVL 14

Expert Comment

by:mcrider
Comment Utility
Well if we're going to talk about bugs, this is my all-time favorite...

Add a picturebox called Picture1 to a form and do this:

    Picture1.FontBold = True
    Picture1.Print "Hello World"
   

When you run the code above everything works beautifully...

Now try this:

    With Picture1
        .FontBold = True
        .Print "Hello World"
    End With


GOTCHA!! It doesn't work!


Cheers!®©
0
 
LVL 15

Expert Comment

by:ameba
Comment Utility
This is not a bug. 'With object' can be used only with object properties and methods.
'Print' is not a method of a PictureBox (or Form) - you can check Help or Object Browser.
It really does not belong to PictureBox or Form but can be used with these objects.

This is documented, but I agree it can be confusing.
0
 
LVL 12

Expert Comment

by:mark2150
Comment Utility
Ok ameba, if .Print isn't a method then *why* can it be used? I mean you either have a convention where only methods can be used or you don't. This "sometimes but not always" crap is the bane of programmers. I *hate* coding 'special case' handlers. It clouds the logic of my code, bloats to .EXE and is generally a waste of *my* time (read coding $$$$) because someone at M$ decided to take a short-cut or was sloppy. A documented bug is still a bug.

..Print doesn't appear as a method to the !@#$%^ Printer object!

Printing was added to VB as an afterthought. Garbage like that shows up all the time. The M$Chart control can't print, some objects don't support .print, etc. I think the development team just forgot about needing to print until they were 90% done.

M
0
 
LVL 15

Expert Comment

by:ameba
Comment Utility
M, I agree. Print method is a heavy hack, it was not added when VB controls were programmed, but later, probably by other VB team.
VB engine interprets code line and catches '.Print' statement... uh

' copy this code, and uncomment the second line
Private Sub Form_Click()
    With Me
        '.?
    End With
End Sub
0
 
LVL 14

Expert Comment

by:mcrider
Comment Utility
Sorry ameba read the With help page again... This is what *MY* copy of the help page on With says:

"With Statement

Executes a series of statements on a single object or a user-defined type."



In the above line, the word statements is a hotspot.  When you click on it, you get this definition of statement:

"statement

A syntactically complete unit that expresses one kind of action, declaration, or definition. A statement generally occupies a single line, although you can use a colon (:) to include more than one statement on a line. You can also use a line-continuation character (_) to continue a single logical line onto a second physical line."



According to the above definition,

      Picture1.Print "Hello World"

is a proper statement using the object Picture1.  Therefore,

      With Picture1
            .Print "Hello World"
      End With

should work, but doesn't.



Cheers!®©


0
 
LVL 15

Expert Comment

by:ameba
Comment Utility
I checked documentation for Picture control: Print is not in the list of properties/methods, and
"Remarks
You can also use a PictureBox control to group OptionButton controls and to display output from graphics methods and text written with the Print method."

but ok, if you insist, you can call this a bug.
---------------------------
There was something also with the Line method (I didn' check if this is documented):

Private Sub Form_Click()
    ' this works beautifully
    With Me
        .Line 9, 0, 0, 500, 500, 0
    End With
End Sub

    ' Now try this
    Me.Line 9, 0, 0, 500, 500, 0




M wrote:
>someone at M$ decided to take a short-cut

Nooo! Line Method supports this second syntax:
    Line (0, 0)-(500, 500), 0
Obviously, MS put TWO independant dev teams to work on Line method. :)
0
 
LVL 38

Expert Comment

by:PaulHews
Comment Utility
Heh heh,  ... This thread should be called "Let the flames begin!!!"
0
 
LVL 15

Expert Comment

by:ameba
Comment Utility
Maybe, but this is competent discussion: mark2150, mcrider, you ... having lots of experience. There are no arguments like
'ha, I am not used to it', so it is not good
'my integer is bigger than your integer'

Frustration doesn't show much, as it shows in the article, i.e.
 frust(ameba) < frust(stob)
0
 
LVL 14

Accepted Solution

by:
mcrider earned 50 total points
Comment Utility
;-)

What about them points for "static"...
0
 

Author Comment

by:mbarreto022800
Comment Utility
Hey mcrider, that text was writen by Stob, not me... anyway I'm giving you this "question" points, because you where the first to enter the discussion :), and you got that right about the "Static".

BTW: I have a realy nasty problem on my hands with VB6/crystal reports... The question is "RichtTextBox formated text on a Crystal Report" and i'm offering 175 points. Anyone could help me?
0
 
LVL 14

Expert Comment

by:mcrider
Comment Utility
mbarreto,

I understand that the text was written by Stob... Thanks for the point anyhow!


Cheers!®©
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now