Results 1 to 15 of 15

Thread: Migrating from VB6 to VB.Net

  1. #1

    Thread Starter
    Fanatic Member pvbangera's Avatar
    Join Date
    Sep 2001
    Location
    Mumbai, India
    Posts
    961

    Thumbs up Migrating from VB6 to VB.Net

    Nobody likes VB.Net at first instance. VB6 programmers, who just migrate to VB.Net keep on cursing themseleves for migrating, as they miss so many useful things in VB6 (like control array, shortcut keys in property window, etc). But later on they are pleased when they are aware of the strength of VB.Net.

    Now, as the VB.Net community is growing faster and even www.vbforums.com has a seperate section with more than 10K threads as on date, here's an attempt to share our experience while migrating from VB6 to VB.Net.

    I hereby request you to share your problem(s) and solution(s) during the migration. I also hereby request the moderator of this site to make this thread sticky for sometime so that the users are aware of the same.

    So... who's the first to post?

    Regards,

    Prakash

  2. #2

    Thread Starter
    Fanatic Member pvbangera's Avatar
    Join Date
    Sep 2001
    Location
    Mumbai, India
    Posts
    961
    Here's the first one. Well, its basic thing. But could be useful for someone.

    I wanted to show a form 'Form1' in my project from my Sub Main. I used the following code.

    VB Code:
    1. Sub Main
    2.    Form1.Show
    3. End Sub

    The code doesn't work. So the solution is...

    Declare a new instance of the form
    VB Code:
    1. Dim frmMain as New Form1
    Then display the form.
    VB Code:
    1. frmMain.ShowDialogue
    2. 'Or
    3. Application.Run("frmMain")


  3. #3

    Thread Starter
    Fanatic Member pvbangera's Avatar
    Join Date
    Sep 2001
    Location
    Mumbai, India
    Posts
    961
    No one yet to contribute??

  4. #4
    Member SnappleBoy's Avatar
    Join Date
    Aug 2002
    Location
    Israel!
    Posts
    41
    I'll try!

    Vb.net - no control arrays! Very sad...
    The solution: Something else!

    instead of simply using design view to create control arrays you do the following:
    VB Code:
    1. Const N = 4
    2.     Private mytextboxes() As TextBox
    3.  
    4.     Private Sub CreateMyTextBoxes()
    5.         ReDim mytextboxes(N)
    6.         Dim i As Short
    7.         For i = 1 To N
    8.             mytextboxes(i) = New TextBox
    9.             With mytextboxes(i)
    10.                 .name = "TB" & i
    11.                 .tag = i
    12.                 .location = New Point(50 + i * 50, 20 + i * 20)
    13.             End With
    14.             Me.controls.add(mytextboxes(i)) 'Add to the form
    15.             AddHandler mytextboxes(i).TextChanged, AddressOf SomeSub 'Add the event to some sub
    16.         Next
    17.     End Sub
    18.  
    19.     Private Sub SomeSub(ByVal sender As System.Object, ByVal e As System.EventArgs)
    20.         messagebox.show("Textbox " & sender.tag & " changed!")
    21.     End Sub

    That's it!

    EDIT:syntax glitches fixed
    Last edited by SnappleBoy; Apr 3rd, 2004 at 10:18 AM.
    i like my icon, made it myself...

    except for Buttercap of course.
    and for the symbol in the back that is copied from Slipknot...


    I like the icon i use but isn't really mine.

  5. #5
    Fanatic Member
    Join Date
    Jul 2003
    Posts
    830
    So how do you make the above work? Do you have an actual example in a zip file?

    I was just experiencing this issue in VB6 migrating to VB.NET. The issue of Control Arrays that is.

    Thanks!

  6. #6
    Member SnappleBoy's Avatar
    Join Date
    Aug 2002
    Location
    Israel!
    Posts
    41
    Actually that's it!
    Just copy paste the above code(Now proprly cased and tested)
    and call the CreateMyTextBoxes() whenever from wherever.
    Have fun!
    i like my icon, made it myself...

    except for Buttercap of course.
    and for the symbol in the back that is copied from Slipknot...


    I like the icon i use but isn't really mine.

  7. #7
    Fanatic Member
    Join Date
    Jul 2003
    Posts
    830
    Thanks! I saw a few errors and try to fix them, but did not have much fortune. It works now though just as you have it. Thanks again!

    If I add a label to capture the names of the textboxes though....aren't they actually named differently? My understanding is limited, but aren't control arrays supposed to be named the same thing?

    Private Sub Form1_Load(ByVal sender As System.Object, _
    ByVal e As System.EventArgs) Handles MyBase.Load

    CreateMyTextBoxes()
    End Sub


    Const N = 4
    Private mytextboxes() As TextBox

    Private Sub CreateMyTextBoxes()
    ReDim mytextboxes(N)
    Dim i As Short
    For i = 1 To N
    mytextboxes(i) = New TextBox
    With mytextboxes(i)
    .Name = "TB" & i
    .Tag = i
    .Location = New Point(50 + i * 50, 20 + i * 20)


    End With
    Me.Controls.Add(mytextboxes(i)) 'Add to the form
    AddHandler mytextboxes(i).TextChanged, AddressOf SomeSub 'Add the event to some sub
    Next

    Label1.Text = mytextboxes(1).Name.ToString & " " & mytextboxes(2).Name.ToString _
    & " " & mytextboxes(3).Name.ToString & " " & mytextboxes(4).Name.ToString
    End Sub

    Private Sub SomeSub(ByVal sender As System.Object, ByVal e As System.EventArgs)
    MessageBox.Show("Textbox " & sender.tag & " changed!")
    End Sub


    End Class
    Last edited by birthjay; Apr 3rd, 2004 at 08:20 PM.

  8. #8
    Member SnappleBoy's Avatar
    Join Date
    Aug 2002
    Location
    Israel!
    Posts
    41
    Don't exactly understand your question but just to clarify things:
    This is not a control array. It's something else. I don't know what to call it.

    The names of the controls does not matter!
    you don't even have to name them!(in the loop)
    because obviously you can't write in the code before you compile TB1.text="hello"
    because the compiler doesn't know any "TB1"
    you can reference them only by using mytextboxes(n)

    Instead of the index that was sent in control arrays i use the sender.tag value in the events.

    i hope this helps. :)
    i like my icon, made it myself...

    except for Buttercap of course.
    and for the symbol in the back that is copied from Slipknot...


    I like the icon i use but isn't really mine.

  9. #9
    Fanatic Member
    Join Date
    Jul 2003
    Posts
    830
    Thanks! I am a bit of a newby and I appreciate the explanation. I will give it some study.

  10. #10
    Frenzied Member DevGrp's Avatar
    Join Date
    Nov 2001
    Location
    Charlotte, NC
    Posts
    1,256
    Originally posted by SnappleBoy
    I'll try!

    Vb.net - no control arrays! Very sad...
    The solution: Something else!

    instead of simply using design view to create control arrays you do the following:
    VB Code:
    1. Const N = 4
    2.     Private mytextboxes() As TextBox
    3.  
    4.     Private Sub CreateMyTextBoxes()
    5.         ReDim mytextboxes(N)
    6.         Dim i As Short
    7.         For i = 1 To N
    8.             mytextboxes(i) = New TextBox
    9.             With mytextboxes(i)
    10.                 .name = "TB" & i
    11.                 .tag = i
    12.                 .location = New Point(50 + i * 50, 20 + i * 20)
    13.             End With
    14.             Me.controls.add(mytextboxes(i)) 'Add to the form
    15.             AddHandler mytextboxes(i).TextChanged, AddressOf SomeSub 'Add the event to some sub
    16.         Next
    17.     End Sub
    18.  
    19.     Private Sub SomeSub(ByVal sender As System.Object, ByVal e As System.EventArgs)
    20.         messagebox.show("Textbox " & sender.tag & " changed!")
    21.     End Sub

    That's it!

    EDIT:syntax glitches fixed
    No worries control arrays are back in the next version of VB.NET

  11. #11
    Member SnappleBoy's Avatar
    Join Date
    Aug 2002
    Location
    Israel!
    Posts
    41
    but we don't need it!!!
    i was kidding! don't bring control arrays back for the sake of me!
    w/o control arrays the files are much smaller and besides it's more fancy doing things this way... you know, coding stuff is much more cooler than "visual design" err. where did that come from? i remember the days... when basic wasn't visual and programmers had self respect hehe just kidding...
    Last edited by SnappleBoy; Apr 4th, 2004 at 01:56 PM.
    i like my icon, made it myself...

    except for Buttercap of course.
    and for the symbol in the back that is copied from Slipknot...


    I like the icon i use but isn't really mine.

  12. #12

    Thread Starter
    Fanatic Member pvbangera's Avatar
    Join Date
    Sep 2001
    Location
    Mumbai, India
    Posts
    961
    Well, here's another way. Not only for SnappleBoy

    1. Pulldown as many text boxes u want on ur form.
    2. Add TextBoxArray control on ur form.
    3. In Region "Windows Form Designer generated code" u will find customised settings like AcceptsReturn, Autosize, Backcolor etc for each TextBoxes. There you add the following code.

    VB Code:
    1. Me.MyTextBoxArray.SetIndex(Me.MyTextBox1, i)
    2. 'where "i" is ur index number. could be any positive number

    Your TextBox control array is ready.

    Hope it helps someone

    Regards

  13. #13
    Member SnappleBoy's Avatar
    Join Date
    Aug 2002
    Location
    Israel!
    Posts
    41

    design view is for chumps.

    (Bender(Futurama) Paraphrased)
    i like my icon, made it myself...

    except for Buttercap of course.
    and for the symbol in the back that is copied from Slipknot...


    I like the icon i use but isn't really mine.

  14. #14
    New Member
    Join Date
    Jan 2005
    Posts
    5

    Question Re: Migrating from VB6 to VB.Net

    Hello,

    I have a fairly complex app that I plan to migrate to VB.NET. My main concern is the graphics part of the app.

    The app is a design tool and has a picture box to display the graphics. Line and PolyBezier are the main graphics functions that are being used.

    I remeber reading that VB.NET graphics work very differently from VB6.0 and hence was wondering if this could hinder the migration. Would it rather be better to start from a scratch in VB.NET than migrate?

    Your comments would be highly appreciated.

    Thanks in advance.

  15. #15

    Thread Starter
    Fanatic Member pvbangera's Avatar
    Join Date
    Sep 2001
    Location
    Mumbai, India
    Posts
    961

    Re: Migrating from VB6 to VB.Net

    migrating from vb6 to vb.net thru the wizard was never appreciated by anyone. 1st of all the wizard was developed not by microsoft but by a third party company. there are so many flaws in it.

    i would suggest, u better start with a new project in .net, right from scratch.

    regards and all the best

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