Results 1 to 2 of 2

Thread: Mini-Tutorial: VB6 -> VB.NET introduction

  1. #1

    Thread Starter
    Frenzied Member Phill64's Avatar
    Join Date
    Jul 2005
    Queensland, Australia

    Mini-Tutorial: VB6 -> VB.NET introduction

    Ok, so you have used VB6 for years but suddenly you have migrated to VB.NET and don't have a clue... i have put this together to help get you started

    the biggest issue you will have is forms... forms are no longer magically existant, they must be instantiated and have references passed to each other to access them.

    here is a tutorial for using multiple forms: http://www.devcity.net/Articles/94/1/multipleforms.aspx (compliments of gigemboy)

    but even before you visit there i recommend doing this simple exercise that will train you for instantiating objects. Control arrays no longer exist ( you say)
    never fear, we can make them ourselves at runtime if we like. Ok, here is how to make a control array of 5 buttons

    Make 5 buttons on the form from code
    Dim buttonArray(5) as Button
    but, that wont do the job.. what we have made is 5 empty "containers" for buttons, they need to be populated with an "instance" of an object
    buttonArray(0) = New Button
    that will instantiate the first one, what you need to do is use a for loop to instantiate them all. Also give them x and y co-ords and make them visible

    The next problem faced is hw on earth do i know if they are clicked?
    first, make a sub ready to handle a button click event
    Sub ButtonArray_Clicked(ByVal sender As System.Object, ByVal e As System.EventArgs)
     'sender will be the button that was clicked
    End Sub
    notice the layout is the same as any other button click event, it must have the same variables

    now, in your for loop, you need to add a "handler" to link the buttons click event with that sub, doing so is as simple as
    AddHandler ButtonArray(0).Click, AddressOf ButtonArray_Click
    how do i know which one is clicked?
    well, you may notice i noted that "sender" will be the button that was clicked.. but it is of type Object so how can we use it? this is yet another hurdle, object is the general type of all classes.. but we know that for this particular sub, it will always be a Button, so we can safety DirectCast it into a Button (As an object it is still a button.. but it doesnt know that it is, basically)

    Sub ButtonArray_Clicked(ByVal sender As System.Object, ByVal e As System.EventArgs)
     'sender will be the button that was clicked (in object form)
     Dim buttonClicked as Button = DirectCast(sender,Button)
     'now buttonClicked is the sender object in its correct Button form
    End Sub
    To extend on this simple array, experiment with using an ArrayList, declaring it at form level "Private ButtonArray As New ArrayList" so that you can add and remove controls from it at will.

    If you are into graphics, when it comes time, don't use bltbit, readup on GDI+, included in .NET and very useful, do a search on this site for it.

    Good Luck
    Last edited by Phill64; Dec 17th, 2007 at 11:14 AM.

  2. #2
    Fanatic Member uniquegodwin's Avatar
    Join Date
    Jul 2005

    Re: Mini-Tutorial: VB6 -> VB.NET introduction

    This is a very good and simple article for vb6 guys who probably feel tired to read pages and pages of text.This one is neat.

    But,I think you could add a few words in this thread like migrating from vb6 to vb.net...vb.net for vb6 developers,etc.in some conext...or maybe use a sentence for example like...this will be very good for vb6 developers migrating to .Net..
    If you mention a few phrases like that,I think this would come on top in the google search.Many people would need this vbforums results come within top 5 on google many times if it contains specific information.
    Last edited by uniquegodwin; Mar 15th, 2006 at 01:39 PM. Reason: adding some more comments :)

    Help someone else with what someone helped you!

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