Results 1 to 4 of 4

Thread: [RESOLVED] Variables

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Dec 2005
    Posts
    230

    Resolved [RESOLVED] Variables

    is it correct to declare variables like this in Vb.NET ?:

    Dim a, b, c as integer

    or it should be:

    Dim a as integer
    dim b as integer
    dim c as integer

    Cuz i read somewhere that if i declare "Dim a, b, c as integer" then only c will be treat as integer , a and b are variants.

  2. #2
    New Member
    Join Date
    Mar 2006
    Posts
    5

    Re: Variables

    Variant isn't supported in .net - it's been replaced by object - defining variables like that is fine - in your example all are integers.

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

    Re: Variables

    what you read was probably about VB6, when the

    Dim a, b, c as integer, resulted in a and b being variants...

    As gordon freeman mentioned, they have changed this for .NET

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Variables

    As has been said, there is no technical issue with declaring multiple variables on a single line. In fact, you can even do this:
    VB Code:
    1. Dim x As String, y As Integer, z As Boolean
    Having said that, it is generally considered better practice to declare each variable on a different line, regardless of whether they are the same type or not.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

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