Consulting

Results 1 to 6 of 6

Thread: Solved: The use of [] brackets for assigning values or arrays

  1. #1
    VBAX Regular DoLoop's Avatar
    Joined
    May 2008
    Posts
    10
    Location

    Solved: The use of [] brackets for assigning values or arrays

    Hi,

    I've just discovered that assigning values from cells or a range of cells to single variables or arrays can be simply done by following code:

    [VBA]
    Sub AssigningValues ()

    Dim a, b, c, d

    a = [A1] 'single value referring to cell A1
    b = [A1:A10] '2D array
    c = [transpose(A1:A10)] '1D array
    d = [test] 'in case cell A1 has name "test"

    End sub
    [/VBA]

    Now, this looks a better method to me, than using

    [VBA].Cells(1,1)[/VBA]
    or
    [VBA].Range("A1").Value[/VBA]

    Can anyone tell me if this method is faultless? Or do I have to take into account some surprises?

    Thx.

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    It is well documented here in VBAX that I think it is sloppy, poor programming, and I think it shuld not be used.

    I would argue that it is slower than the the correct form, as it has to be evaulated. Others argue the reverse, but my tests show otherwise.
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  3. #3
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Similalrly, I think this is sloppy, poor programming

    [vba]

    Dim a, b, c, d
    [/vba]
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  4. #4
    I agree that not declaring your variable types up front is bad programming form. For me, once a program gets past a few pages of code I spend just as much time, if not more, debuging it than it took to actually type the initial code. By declaring variable types up front, you are starting off on the right foot for quick debuging and it only costs you an extra few seconds worth of key strokes.
    Vow this day in to the grounds of ergo post proctor hoctor, vis-a-vis telemundo.

  5. #5
    VBAX Tutor david000's Avatar
    Joined
    Mar 2007
    Location
    Chicago
    Posts
    276
    Location
    Johnske: Evaluate artical - really good!
    http://xlvba.3.forumer.com/index.php?showtopic=278

  6. #6
    VBAX Regular DoLoop's Avatar
    Joined
    May 2008
    Posts
    10
    Location
    I must admit that the declaring part is not the way to do. But this wasn't the issue for me. I only wanted to show the brackets.
    David,
    Thanks for the article. I've learnt a lot again!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •