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

    VBA with Excel:Declaring string variable

    I am comparatively new to VBA programming.Till now, all the variables I have used were of type "Dim".

    I now have to use a string variable in VBA.How to declare a string variable?
    The variable may have a value "DL" or "LL".It needs to be one dimensional array variable.

    Please , please help!!

  2. #2
    Join Date
    Aug 2006
    Posts
    145

    Re: VBA with Excel:Declaring string variable

    Dim isn't a Type, it tells to VB to dimension a variable as a particular type, e.g. for a string:
    Code:
    Dim MyVariable As String
    since you've been omitting a Type in your declarations VB has been declaring them as Variants - which are slow and use more memory, e.g.
    Code:
    ' these are the same thing
    Dim MyVariable
    Dim MyVariable As Variant

  3. #3
    Join Date
    May 2005
    Posts
    26

    Re: VBA with Excel:Declaring string variable

    Can I have:

    Dim MyVariable(10) as string

    And then,

    MyVariable = "DL"

    Should I put the value of the variable in double codes?

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

    Re: VBA with Excel:Declaring string variable

    With a string array you can have

    MyVariable(0) = "DL" thru MyVariable(10) = "DL"

    or, 11 dimensions of the array. You can use multi-dimensional arrays as well. arr(2,3,4)=33
    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!

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