Results 1 to 5 of 5

Thread: Hey. look what I found.(.NET FAQ)

  1. #1

    Thread Starter
    Banished Cander's Avatar
    Join Date
    Dec 2000
    Location
    Why do you care?
    Posts
    6,913

    Hey. look what I found.(.NET FAQ)

    for you guys that have been in this forum since the beginning, you may remember a FAQ I had posted. Well after doing some cleanup, I found it on my harddrive. thought I would post it again for the benefit of the newbs.

    The VbWorld .NET FAQ was written and is maintained by the posters of the .NET forum. It concentrates
    most answers on VB .NET.
    What is .NET?
    .NET is Microsoft's new initiative to allow applications to run over the internet via Web
    Services. That is the common definition, but to developers it is so much more. .NET is a framework
    much like Java's Virtual Machine. Instead of code you write running on the Operating System, it
    runs ontop of the framework (Common Language Runtime). Because of this, this leaves open the
    possibility of .NET being ported to non-Windows platforms and you apps running on them. In
    addition, the framework provides mnay powerful classes that makes programmers lives much easier.
    A major big advantage of .NET over Java is that you are not locked into one language. You have a
    choice of many with more on the way. Currently it supports VB, C#, C++, Python, Perl, COBOL, and
    many more through add-ons provide by the company porting the language. See the resource links
    at the bottom of this FAQ for links to begin learning more about .NET. You will be very pleased
    with the improvements and power .NET provides.

    What do I need to start developing for .NET
    All you need is the .NET framework SDK. It is a free download from Microsoft. You do not require
    Visual Studio .NET as the SDK provides the compilers. Just use any text editor. Check the
    Resource links at the end of the FAQ for a link to a great .NET code editor and framework
    download links.

    It is also required that the users of your applications has the .NET framework isntalled(not the
    SDK) it is 21 meg download but smaller than the much bigger 130 meg SDK.

    How do I use API calls in .NET?
    There seems to be the big myth running around that you cannot use API calls in .NET applications.
    This is false. You can use API functions in your .NET apps pretty much the same way you always
    have before, BUT, there are some rules you need to know first. First off, the .NET framework
    already provides classes to many functions that you used to use the API for previously. So before
    you use a call, make sure there is no .NET way to do it as adding API calls makes your app
    unmanaged by the framework and it loses some of the benfits(such as security) of it. You can
    check http://www.allapi.net for a list of functions that are provided by the framework to replace
    using the API. NOTE: As of this time they have not included anything in the list, but bookmark
    it for later reference when they do.

    If you do end up having to use and API call, here is what is different.
    a) When calling a function, you can specify if it will return Ansi or Unicode. VB6 by default
    returned Ansi.
    VB Code:
    1. Public Declare Ansi functionname .....
    b) You will need to change return value and parameter datatypes. Dataypes have changed, so you
    will need to change them as appropriate. For instance:
    If it was Long in VB6, change it to Integer
    If it was Integer, change it to Short
    If it was Any, you will need to find out what the correct data type will be.

    How do I compile?
    You are provided with more than one way to compile your .NET apps.
    a) You can use the command line compiler's. For VB just type vbc.exe at the command line
    EX:
    Code:
       vbc.exe myApp.vb /t:exe
    That will compile the myApp.vb file to an executable named myApp.exe
    b) In Visual Studio .NET, right click on the project name in the Project Explorer and select
    Build or Rebuild.
    c) There are even classes provided by the .NET framework that will allow you to compile an
    application from your own program. But we will not get into this.

    The command line compiler is great as fledgling programmers wont need to dish out mucho cash for
    Visual Studio .NET(or search Morpheus and download 3 gigs :P).

    OK I compiled my app in Visual Studio .NET by selecting Build. Where is it?
    Check the \bin\ directory in the projects directory and you will find your compiled
    assmebly.

    Namespaces? Say what?
    Namepaces provide a sructured way to organize and access code. This can help in readability and
    decrease the problems of class naming conflicts.
    All classes built into the .NET framework uses Namespaces and you may have seen them used. For
    instance there is the System Namespace. Within this one resides other Namespaces and classes
    that you can use to access certain functions like:
    System.Data - This Namespace set gives access to the Database and XML classes for reading and
    writing.

    You may have also seen them used with the Imports statement. Imports allows you to predefine a
    Namespace so you only need to access the inner levels of it. For example:

    Instead having to perhaps type this multiple times:

    VB Code:
    1. a = New System.Threading.Thread(blah)
    2.    b = New System.Threading.Thread(blah2)

    you can shorten this using Imports

    VB Code:
    1. Imports System.Threading
    2.    
    3.    a = New Thread(blah)
    4.    b = New Thread(blah2)

    You can also easily create your own Namespaces in your own apps to sort multiple classes using
    the Namespace declaration statement

    VB Code:
    1. Namespace mySpace1
    2.       Class myClass1
    3.          ' Class code
    4.       End Class
    5.      
    6.       Class myClass2
    7.          ' Class code
    8.       End Class
    9.    End Namespace

    You will see alot of Namespaces as you learn and use Namespaces, so it is important you
    understand them.

    Whoa, no Open statement? How do I read and write a text file?
    I have not seen anyone ask this yet, but I know that File writing and reading is big time asked
    question for VB6 so since it has changed dramatically, I think it is appropriate to include some
    information on this. There really is not a whole lot to explain so we will just go straight to the
    code for reading and writing a text file.
    Writing:

    VB Code:
    1. Imports System
    2.    Imports System.IO
    3.    
    4.    dim myFileStream As FileStream
    5.    
    6.    Try
    7.       myFileStream = New FileStream("C:\mytextfile.txt", FileMode.OpenOrCreate, FileAccess.Write)
    8.       myFileStream.Write("Some text")
    9.    Finally
    10.       If Not (myFileStream Is Nothing) Then myFileStream.Close()
    11.    End Try

    Reading:
    VB Code:
    1. Imports System
    2.    Imports System.IO
    3.    
    4.     ' declare the StreamReader, for accessing the file
    5.     Dim strWriter As StringWriter = New StringWriter()
    6.     Dim TextFile As String = "C:\textfile.txt"
    7.     Console.SetOut(strWriter)
    8.  
    9.     Try
    10.         Dim din As StreamReader= File.OpenText(TextFile)
    11.         Dim str As String
    12.         Dim al As ArrayList = New ArrayList()
    13.    
    14.         Console.WriteLine("Reading data and inserting into an ArrayList...")
    15.         Console.WriteLine()
    16.    
    17.         Do
    18.            str = din.ReadLine()
    19.    
    20.            If str <> Nothing Then
    21.                al.Add(str)
    22.            End If
    23.         Loop Until str = Nothing
    24.    
    25.    
    26.         Console.WriteLine("Printing out the ArrayList.")
    27.         Console.WriteLine("---------------------------")
    28.    
    29.         Dim s As String
    30.    
    31.         For Each s in al
    32.                 Console.WriteLine (s)
    33.         Next s
    34.    
    35.     Catch E As Exception
    36.         Console.WriteLine("There was an error reading the file . Please ensure it is in the right
    37.  
    38. directory")
    39.     End Try

    The FileStream classes provide functionality for writing bytes, binary files, and goes back to using
    Seek for Random Access.

    Can I use a COM component in my VB .NET app?
    Yes you can, although keep in mind that doing so has the same downsides as using the API as your
    application becomes unmanaged.
    To add a COM component, just right click in the Project Explorer in Visual Studio .NET and select
    Add Reference. The goto the COM tab and find your component. What happens behind the scenes is
    that VS .NET creates a wrapper that makes that component usable in .NET.
    But this does add much overhead to your app, so please make sure before using a COM component
    that there is no .NET class/object to do what you need.

    I heared that dynamic arrays are gone? Is that true?
    Absolutly not. Dim and Redim arrays as you always hve before. It is quite possible those that say
    this maybe confused with dynamic control arrays as control arrays ARE gone.
    Stack Overflow
    See the features of Visual Studio 2010 and C# 4.0: The 10-4 show on Channel9

  2. #2

    Thread Starter
    Banished Cander's Avatar
    Join Date
    Dec 2000
    Location
    Why do you care?
    Posts
    6,913
    No control arrays? I need control arrays, what do I do?
    That is right no more control arrays. Time to worry? No not at all. With .NET you now have control
    collections to take its place. VB6 of course had this ability, but it could be a pain to get
    events wired up to them. .NET fixes this problem. Without going into too much detail, here is how
    to dynamically create a button, adding it to the control collection, and wiring up a Click event
    for it:

    VB Code:
    1. Dim myButton As New System.Windows.Forms.Button()
    2.    
    3.    myButton.Visible = True
    4.    myButton.Size = New Size(50,50)
    5.    myButton.Text = "Click me fool!"
    6.    
    7.    ' Add to the collection
    8.    Me.Controls.Add(myButton)
    9.    
    10.    ' Wire up Click event to the myButton_Click sub
    11.    AddHandler myButton.Click, AddressOf Me.myButton_Click
    12.    
    13.    Public Sub myButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
    14.       ' Your event code. Do whatever
    15.    End Sub

    Sure this may seem like a bit more work than before, but the flexibility it provides outways
    more coding and finger cramps(:P).

    Try..Catch..Finally? Whazzup wit dat?
    In previous versions of VB, we had to deal with On Error Goto. This was a pain as it unstructured,
    crappy, and limited. It could make code readability a chore. Now we have been graced with what
    other OOP languages have had, Try/Catch. This method gives use a cleaner and structured way to
    handle our exceptions and errors. Try allows you to intercept an error without flopping around
    to your goto's. You can even nest Try/Catches, and one of the biggies..mutliple Try/Catches in a
    routine. A Try is really easy to use:

    VB Code:
    1. Try
    2.       ' Do something that may cause an error you need to trap
    3.       Catch TheException
    4.          ' Do something when this error is fired
    5.       Catch ADifferentError
    6.          ' Do something else
    7.    End Try

    Very simple, very clean.

    ASP .NET? What is so great about it over ASP 3.0?
    Well I could go on all day as to the advantages of ASP .NET. But the 2 that really stand out are
    a) Full blown compiled code. No more cruddy script. Especially VB. No more variants! w00t!
    b) You can use ANY .NET language you wish. VB, C#, C++, etc.

    Also Web Form controls rock as they are just like HTML controls but they can be run on the server
    with server events being fired. Other things include saving session state, user controls, code
    behind and of course all the benefits of the choosen language.

    I think that is enough to wet any ASP developers appettite for more. See the Resources link if
    you are ready to jump into it.

    .NET Resources:
    Get the .NET framework SDK(For Developer)

    http://msdn.microsoft.com/downloads/...27/000/976/msd

    ncompositedoc.xml&frame=true
    Get the .NET framework distributable(For the end user. You dont need this if you have the SDK)

    http://msdn.microsoft.com/downloads/...27/001/829/msd

    ncompositedoc.xml
    http://www.gotdotnet.com
    http://www.asp.net
    http://www.dotnet101.com/
    Need a great editor and cannot afford Visual Studio .NET? Go here:

    http://www.icsharpcode.net/OpenSource/SD/default.asp
    Stack Overflow
    See the features of Visual Studio 2010 and C# 4.0: The 10-4 show on Channel9

  3. #3
    Frenzied Member DevGrp's Avatar
    Join Date
    Nov 2001
    Location
    Charlotte, NC
    Posts
    1,256
    Hey Cander, I was thinking about doing the same thing. I was just gonna search the forum for all the samples and provide C# and VB.NET conversions for each sample. I want to do an HTML version and a Word version. I'll start that project this weekend.
    Dont gain the world and lose your soul

  4. #4
    Hyperactive Member
    Join Date
    Apr 2003
    Location
    Three Rivers, MI
    Posts
    354
    I found this today searching for something else. It is a great post anyway so I am going to bump it back up to the top of the list.

    ^^^^ BUMP ^^^^

  5. #5

    Thread Starter
    Banished Cander's Avatar
    Join Date
    Dec 2000
    Location
    Why do you care?
    Posts
    6,913


    Needs some updating though. Maybe i will get some free time to update soon.
    Stack Overflow
    See the features of Visual Studio 2010 and C# 4.0: The 10-4 show on Channel9

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