Page 1 of 2 12 LastLast
Results 1 to 15 of 18
  1. #1
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Yilgarn region of Toronto, Ontario
    Posts
    5,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Changed coding standards for VB.NET (Office97 et a

    I think I'm about to reorgainize my libraries of VBA code. I've read from time to time, various articles about VB.Net as it differes from, say VB6.

    Although I'm still writing in VBA, it seems as if this might be a good time to clean up my act just in case I want to move to .NET down the road.

    What basic, general, things can I clean up as I go, based on your (dear reader) experience?

    1) ByVal or By ref are now required as explicit declarations for parameters to Function and Subroutine procedures
    2) On Error no longer exists (hooray!)
    3) other?

  2. #2
    Platinum Lounger
    Join Date
    Dec 2000
    Location
    Queanbeyan, New South Wales, Australia
    Posts
    3,730
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Changed coding standards for VB.NET (Office97 et a

    Our site gave up on the idea of converting- but as a large government site, the can afford to. They actually went from VB6 to C#- future releases of VS may well be dropping some VB features which were seen as compromises.

    I'd suspect that much of the stuff you may be trying to do would be better rewritten as well- as there are a lot of new (and different) methods for doing the old things in new ways. I've had to wrestle with a lot of OO type of concepts, and a completely different way of doing things, but it has been worth it.

    Removing "On error" is NOT an admission that code will always run error free. But the "try/catch" construct is a lot more flexible than to "On error", and can be done at a top level, applying to many levels below, if just standard error conditions are expected.
    Subway Belconnen- home of the Signboard to make you smile. Get (almost) daily updates- follow SubwayBelconnen on Twitter.

  3. #3
    Silver Lounger
    Join Date
    Jan 2001
    Location
    Indianapolis, Indiana, USA
    Posts
    1,862
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Changed coding standards for VB.NET (Office97 et a

    I'll agree wholeheartedly with Geoff!

    There are a number of new features and design patterns with .NET that make a direct conversion seem like it's not always the best approach. It's been so long since I've used VBA/VB6 that I've forgotten a lot of the differences. (I would have a very hard time going back to VBA/VB6/VBScript!)

    You might check some of the Microsoft resources for more specific details: Converting Code from VBA to Visual Basic.NET.

    From what I remember, the Do While-Wend/EndWhile construct is slated to be removed from future versions of VB. There are a number of other legacy practices that are supported by .NET but not necessarily the best method (OnError vs. Try/Catch).

    One good thing to note with .NET - when creating new code, the IDE automatically adds ByVal as the default for parameters. This saves a few keystrokes, assuming most of your parameters are ByVal.

    Hope this helps!

  4. #4
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Changed coding standards for VB.NET (Office97 et a

    Get used to working with objects because everything is an object in .Net, so even a string variable has methods and properties. Your code will need to be converted and the best conversion involves heavy use of classes because VB.Net finally supports inheritance and allows overloaded constructors. I love it, but I'm still on a learning curve trying to convert stuff to .Net while maintaining Access XP apps as well. There's a lot of legacy support in .Net, but I recommend you not rely on it. There are entirely different ways of doing things in .Net that are worth learning.
    Charlotte

  5. #5
    Gold Lounger
    Join Date
    Dec 2000
    Location
    New Hampshire, USA
    Posts
    3,386
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Changed coding standards for VB.NET (Office97 et a

    On Error was not removed.

  6. #6
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Changed coding standards for VB.NET (Office97 et a

    True, Howard, but Try Catch is the construction of choice. On Error is there primarily for easy code migration.
    Charlotte

  7. #7
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Yilgarn region of Toronto, Ontario
    Posts
    5,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Changed coding standards for VB.NET (Office97

    > much of the stuff you may be trying to do would be better rewritten as well-

    You're right. Much of my stuff from over five years back (OK, over three years back), looks horrible. Back in the days when i thought it was smart to pass the name of an object, rather than the object itself.

    I think that's part of my thinking here - if I'm going to rationalise my library code, I may as well clean up as much as I can as I go. It'll cost, but then working with shoddy library code is expensive, too.

  8. #8
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Yilgarn region of Toronto, Ontario
    Posts
    5,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Changed coding standards for VB.NET (Office97

    > the Do While-Wend/EndWhile construct is slated to be removed

    Interesting. I've never liked that. I much prefer the (to me) simpler-looking While-Wend.
    I'm relieved to hear that ther's at least one thing i won't have to worry about.

  9. #9
    Platinum Lounger
    Join Date
    Dec 2000
    Location
    Queanbeyan, New South Wales, Australia
    Posts
    3,730
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Changed coding standards for VB.NET (Office97

    Maybe, as a separate thread, you might like to post a simple routine, and have people suggest a way it may be written in VB .Net (or even C#- there's talk that MS is throwing more support behind C#, despite the talk of .Net supporting all .Net languages)
    Subway Belconnen- home of the Signboard to make you smile. Get (almost) daily updates- follow SubwayBelconnen on Twitter.

  10. #10
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Yilgarn region of Toronto, Ontario
    Posts
    5,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Changed coding standards for VB.NET (Office97

    > you might like to post a simple routine,

    OK. I'll do that.

    I now have five libraries - UWord.dot, UPPT.PPT, UExcel.XLS, UAccess.MDB and (ta!da!) a general appliaction-independant UGen.BAS.

    This last one would be the most suitable candidate; it contains my string-handling, array-handling, numeric hhandling routines; there should be something in there that appeals to the converted converters.

  11. #11
    Silver Lounger
    Join Date
    Jan 2001
    Location
    Indianapolis, Indiana, USA
    Posts
    1,862
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Changed coding standards for VB.NET (Office97

    It's funny that all of the "serious" coders use C#, while VB is left for everyone else. I've used both (much more VB than C#) and I could go either way.

    In the current version (2003), I find that I can write VB more productively. The intellisense is much more abundant and does not require fully qualified object names in order to pop up. Another small advantage of VB is the With block, which does not exist in C#.

    The biggest advantage of C# now is the inline XML documentation feature (//<summary>blah blah</summary>, etc). This allows developers to include descriptions and helpful information within the code component, which will display in the object browser. Unfortunately, the current version of VB does not support this out of the box.

    Studio 2005 will add that feature to VB, bringing it up to a par with C# (despite the few minor differences remaining).

  12. #12
    Platinum Lounger
    Join Date
    Dec 2000
    Location
    Queanbeyan, New South Wales, Australia
    Posts
    3,730
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Changed coding standards for VB.NET (Office97

    We started coding in VB .Net- and then converted everything to C#. I'm not sure the reasons for the change- it was before I was directly involved. I did hear that there were some things which could be done in C# which could not be done in VB. And I'm sure there's no truth to the rumour that the switch was made because C# programmers get paid more <img src=/S/evilgrin.gif border=0 alt=evilgrin width=15 height=15>.

    I used to get caught with the case sensitivity of C++, but I find that I'm almost always using the autocomplete (Ctrl + space)- which I now find to my chagrin was available in VB6 but which I never knew.
    Subway Belconnen- home of the Signboard to make you smile. Get (almost) daily updates- follow SubwayBelconnen on Twitter.

  13. #13
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: Changed coding standards for VB.NET (Office97

    What a headache. It's bad enough learning JavaScript to write client-side web page code, keeping straight the differences between VBA and VBScript in the Office and Classic ASP contexts. Now a good number of the code samples I read at Microsoft.com and elsewhere are in C#. Java anyone?

  14. #14
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Changed coding standards for VB.NET (Office97

    One of the nice things about VS.Net is that the help file contains examples in the several development languages, so you can look at the ones for the language you use. <img src=/S/thumbup.gif border=0 alt=thumbup width=15 height=15>
    Charlotte

  15. #15
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Changed coding standards for VB.NET (Office97

    Be prepared for some shocks, Chris. A great deal of that is built in with VB.Net. You want to format a string? Format is a method of the string class. In fact, a lot of the functions used to manipulate values in VB/VBA have been recreated as methods of the object classes. Format, Split, Replace, Join, etc.
    Charlotte

Page 1 of 2 12 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •