Results 1 to 7 of 7

Thread: Split into an array?

  1. #1
    idover
    Guest

    Split into an array?

    i just came across this problem, and was wondering if someone could explain it to me... i have simplified the code...

    Code:
    Dim arrReferences()
    arrReferences = Split(strTemp, ",")
    the above code would always throw a type mismatch error... however, when i alter it to:

    Code:
    Dim arrReferences ' notice i removed the parentheses
    arrReferences = Split(strTemp, ",")
    it works like a charm... why would this be?... because of variant types?... i assumed that vb would prefer me telling it that i would be using this variable as an array...? i'm just curious...

  2. #2
    Frenzied Member
    Join Date
    Feb 2001
    Posts
    1,140
    It is just a quirk of VBScript. I've complained about it many times.
    Travis, Kung Foo Journeyman
    As always, RTFM.

    WWW Standards: HTML 4.01, CSS Level 2, ECMA 262 Bindings to DOM Level 1, JavaScript 1.3 Guide and Reference
    Perl: Learn Perl, Llama, Camel, Cookbook, Perl Monks, Perl Mongers, O'Reilly's Perl.com, ActiveState, CPAN, TPJ, and use Perl;
    YBMS, but Mozilla doesn't.

  3. #3
    Frenzied Member
    Join Date
    Feb 2001
    Posts
    1,140
    [2nd Attempt to Post: I think I just saw the DB take a crap.]

    I don't think VB/VBScript deals with pointers. I think the = operator can't recast an array to fit the results of the Split, but it can shove an array into a variant and let memory management clean up the mess.

    I could be wrong. I'm sure variants are just memory pointers to the OS, but I don't think the VB engines are aware of the smoke and mirrors.

    Anyway, you can't do cool things like...

    Code:
    myArray(3..7) = Split(myString, myDelim, 5)
    But I guess I've been spoiled by the Poetry of Perl.
    Travis, Kung Foo Journeyman
    As always, RTFM.

    WWW Standards: HTML 4.01, CSS Level 2, ECMA 262 Bindings to DOM Level 1, JavaScript 1.3 Guide and Reference
    Perl: Learn Perl, Llama, Camel, Cookbook, Perl Monks, Perl Mongers, O'Reilly's Perl.com, ActiveState, CPAN, TPJ, and use Perl;
    YBMS, but Mozilla doesn't.

  4. #4
    Black Cat JoshT's Avatar
    Join Date
    Nov 2000
    Location
    WNY, USA
    Posts
    4,032
    I don't think VB/VBScript deals with pointers.
    It does, but it shields the programmer from them. (There are hidden functions like StrPtr and VarPtr in VB that you can use to get pointers). I would think anything declared as a Variant or Object would have to be a pointer. It wouldn't make sense to me otherwise.
    Josh
    Get these: Mozilla Opera OpenBSD
    I have books for sale: "MCSD in a Nutshell" and "VB Distributed Exam Cram" - PM me for details. Will also trade for a decent ATX Pentium 2 MB/CPU/RAM combo.

  5. #5
    Frenzied Member monte96's Avatar
    Join Date
    Sep 2000
    Location
    Somewhere in AZ
    Posts
    1,379
    The short answer here is:

    Change
    Dim arrReferences()
    to
    Dim arrReferences
    oOOo--oOOo
    __/\/\onte96
    oOOo--oOOo
    Senior Programmer/Analyst
    MCP
    [email protected]
    [email protected]


    Your results may vary.. some restrictions may apply.. pricing and participation may vary.. not available in all states.. professional driver closed course..quantities limited..

  6. #6
    idover
    Guest
    thanks, but i think that i've already discussed that... i'm simply curious of why this has to be? i assumed that vb would appreciate me preparing it to use an array.. hence my dimensioning a dynamic array... instead, vb requires that the coder not use the parentheses... ?

  7. #7
    CMangano
    Guest

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