CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 8 of 8
  1. #1
    Join Date
    Aug 2014
    Posts
    26

    Dim my variables

    I was just wandering should I dim my variables in a form? If I don't, it still does the calculation but should I do it anyway?

  2. #2
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Re: Dim my variables

    DIM statements are used to control the TYPE of the variable. Non-DIM variables are OBJECTS in VB6
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  3. #3
    Join Date
    Aug 2014
    Posts
    26

    Re: Dim my variables

    Thanks.

  4. #4
    Join Date
    Jul 2008
    Location
    WV
    Posts
    5,362

    Re: Dim my variables

    You should always Dim all variables.
    You should also have the little box checked under the editor properties to require variable declaration also known as Option Explicit.

    Not dimming your vars leads to poor performance and makes it much harder to debug your code and can cause some unexpected results.
    Always use [code][/code] tags when posting code.

  5. #5
    Join Date
    Aug 2014
    Posts
    26

    Re: Dim my variables

    Thank you.

  6. #6
    Join Date
    Aug 2014
    Posts
    26

    Re: Dim my variables

    But how do I do that? For example 'dim a as integer' Is that correct?

  7. #7
    Join Date
    Jul 2008
    Location
    WV
    Posts
    5,362

    Re: Dim my variables

    Yes though you should use descriptive names for your variables
    Code:
    Option Explicit
    Dim Qty As Integer
    Dim Cost as Currency
    Dim PartNumber as String
    You can also place more than one on a line like
    Code:
    Dim Qty as Integer, Cost as Currency
    Always use [code][/code] tags when posting code.

  8. #8
    Join Date
    Aug 2014
    Posts
    26

    Re: Dim my variables

    Thank 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

Featured