1

What is THE best way or resource to learn VB6 fast. I need to get up to speed in a new position asap and I'm coming from a foundation of self taught VBA. So I have two main needs. Firstly, iron out bad habits, secondly (and more importantly) understanding efficient way to structure code and functions etc.

Thanks

Marcoq
  • 21
  • 1
  • 1
    The only good reason for learning VB6 is so you can correctly migrate code out of it into something that still has a supported development environment (VB6's development environment [went into end-of-life](http://msdn.microsoft.com/en-us/vstudio/ms788708) four years ago; the runtime is still supported through Windows 8 at least so apps that are *already* built still work). If your new position requires structuring *new* VB6 code, recommend having a word with management about their migration path. – T.J. Crowder Mar 19 '12 at 11:14
  • @BoltClock: :-) Yeah. Although I can totally see new positions for people at companies that desperately need help migrating code *off* VB6... – T.J. Crowder Mar 19 '12 at 11:15
  • 2
    `@Marcoq`: Following on from my earlier comment: So if you've self-taught yourself VBA, you're already in good shape and mostly you just need VB6 reference information, which you'll find [here](http://msdn.microsoft.com/en-us/library/ff405713.aspx). But again, that's assuming they don't have you writing new VB6 code. – T.J. Crowder Mar 19 '12 at 11:17
  • 1
    Try some of the other questions on learning VB6. [learn VB6 from a Java background](http://stackoverflow.com/questions/166138/learning-vb6) [good tutorial for VB6](http://stackoverflow.com/questions/1595737/good-tutorial-for-visual-basic-6) [which book for VB6](http://stackoverflow.com/questions/3831236/which-book-i-should-prefer-for-vb6) – MarkJ Mar 19 '12 at 17:18

2 Answers2

3

If you are still a young vibrant programmer, run away! VB6 is a dead-end. This VB6 gig only makes sense if you're positioning yourself as a VB6'er gun-for-hire ("have laptop, will travel") type - where, if you're lucky, you might get to be about as essential as a COBOL coder. So if you must...

Check out the links MarkJ gives in his comments above. You can also google "vb6 coding standards" or "visual basic 6 books" for more ideas. "Hardcore Visual Basic" by Bruce McKinney, available on-line for free at http://vb.mvps.org/hardcore/ (lots of good stuff here about Win32 API and COM), Chapter 1, "Language Purification", is worth a read, and should be helpful in addressing some bad habits.

My advise would be to learn C# or Java (as MarkJ recommends) on the side and track down good books or websites about coding standards and best practices written for these languages. From there, adopt or adapt what you can into your VB6 coding style.

Here are my VB6 Specific Anti-Bad-Habit Tips:

(1) Always use Option Explicit. Be careful with, or otherwise avoid, the other Option statements.

(2) Avoid DoEvents - instead find a way to make it happen with Timers or Events. Know what a main event loop is. Know what the message pump is. Know that a VB6 app is at its core a main event loop that services its message pump (hidden from the VB6 programmer). DoEvents is a cheat that often ends in tears.

(3) Avoid Option Base. Avoid To in dimensioning arrays. The first element of an array should have an index of zero.

(4) Do not Dim variables inside of an If ... EndIf, Do ... Loop, For ... Next, or any other such block - it will lead to confusion over scope in VB.NET land (or for people familiar with other languages). It may make code harder to read or follow.

(5) Always Dim with As - i.e. don't use Variant or Object unless absolutely necessary. Unlearn the variable decorations such as $ (String) or % (Integer) - in other words, don't use them, use As.

(6) Prefer For Each over For whenever possible and appropriate.

(7) Prefer ByVal over ByRef for numeric parameters that won't be changed as a side effect by a Sub or Function.

(8) Regard On Error Resume Next as something toxic and to be avoided whenever possible. Must you use it? Comment verbosely explaining why it's needed, then turn it off ASAP. Maybe encapsulate it in its own Sub or Function.

(9) Learn about the Model/View/Controller (MVC) design pattern. Avoid placing any business logic into a Form.

(10) Prefer Boolean (True vs False) over Integer (0 vs 1 or -1) or (heaven help us!) String ("N" vs "Y"). Assuming Dim MyFlag As Boolean, know that If MyFlag = True Then raises my suspicion that the other coder doesn't get Boolean. Prefer If MyFlag Then and If Not MyFlag Then.

(11) ActiveX/COM development isn't for wimps - and should be done with proper understanding of Binary Compatibility and within Virtual PC.

rskar
  • 4,607
  • 25
  • 21
0

Whether you are learning VB6 to maintain existing VB6 or migrate it to .NET or other more modern language, you should try to come up to speed on standard object-oriented methodology. Classes, objects, encapsulation, inheritence (VB6 uses mostly interface inheritence but if you can get a handle on that then you are 90% there). Also, VBA does not have forms right, so you will need to understand how the VB6 GUI Forms archetecture works.

tcarvin
  • 10,715
  • 3
  • 31
  • 52