Results 1 to 5 of 5

Thread: Classic VB6 conversion

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Aug 2003
    Location
    Edinburgh, UK
    Posts
    2,773

    Classic VB6 conversion

    VB6 and VB.NET are very similar in many ways.

    I am having a difficulty trying to see whats going on, partly because of the method being literally over 5,000 lines of code but also partly because things are being done here there and everywhere.

    I am trying to convert it ultimately to C# but VB.NET is fine.

    Code:
    Dim validScenario as tScenario
    
    if condition then
       with validScenario
          .MsgType = "blah"
       end with
    
    else if condition2
       with validScenario
          .SomeProp = 1
       end with
    else
    ...
    end if
    so what is going on there? Everytime there is a with, is it using a new instance of the type or is it just using the existing instance and modifying the relevant properties?

    I know what with is used for, makes you write less code and faster in performance when using it on the long type. But im puzzled by the above VB6 code.

    should I be created a new instance everytime or not?

    MVP 2007-2010 any chance of a regain?
    Professional Software Developer and Infrastructure Engineer.

  2. #2
    INXSIVE Bruce Fox's Avatar
    Join Date
    Sep 2001
    Location
    Melbourne, Australia
    Posts
    7,429

    Re: Classic VB6 conversion

    Possibly this may have made more sense (to write less code):
    Code:
    With validScenario
    if condition then
          .MsgType = "blah"
    else if condition2
          .SomeProp = 1
    else
    ...
    end if
    End with
    Of course that thought is just based on the info provided, and as you alluded to, it's more complex than that

  3. #3
    I don't do your homework! opus's Avatar
    Join Date
    Jun 2000
    Location
    Good Old Europe
    Posts
    3,863

    Re: Classic VB6 conversion

    ... and each time (both code versions) the same instance is being used, and that shouldn't be altered.
    You're welcome to rate this post!
    If your problem is solved, please use the Mark thread as resolved button


    Wait, I'm too old to hurry!

  4. #4
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    Re: Classic VB6 conversion

    If that is the entire block of code, then I have to assume tScenario is a valuetype, because you don't ever actually call a New constructor to create an instance of it.

    Regarding the With keyword, no new instance is created, it is from a compiler perspective the same thing as:

    Code:
    Dim validScenario as tScenario
    if condition then
          validScenario.MsgType = "blah"
    else if condition2
          validScenario.SomeProp = 1
    else
    ...
    end if

  5. #5

    Thread Starter
    PowerPoster
    Join Date
    Aug 2003
    Location
    Edinburgh, UK
    Posts
    2,773

    Re: Classic VB6 conversion

    thanks all. much appreciated - i thought as much that it would be using the same instance.

    MVP 2007-2010 any chance of a regain?
    Professional Software Developer and Infrastructure Engineer.

Posting Permissions

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



Click Here to Expand Forum to Full Width