SPONSORS:






User Tag List

Thanks Thanks:  0
Likes Likes:  0
Dislikes Dislikes:  0
Results 1 to 3 of 3
  1. #1
    Member
    Join Date
    May 2006
    Location
    Palo Alto, CA
    Posts
    83
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Total Downloaded
    0

    SPLIT, Option Explicit and Type Mismatch

    I have been frustrated by the SPLIT method. In the following simple code:

    sLongText = "AAAxxxBBBxxxCCCxxxDDD"
    aText = Split(sLongText,"xxx")

    the result is:

    aText(0) = "AAA"
    aText(1) = "BBB"
    aText(2) = "CCC"
    aText(3) = "DDD"

    but I can't get the same result if I include "Option Explicit"

    When I use the following code:

    Option Explicit
    Dim aText(3), sLongText
    sLongText = "AAAxxxBBBxxxCCCxxxDDD"
    aText = Split(sLongText,"xxx")

    The result is a type mismatch on the last line.

    I have also tried different ways to declare the array: Dim aText(), Dim aText(100), with the same result.

    Are there special rules around 'Option Explicit' with arrays?

  2. #2
    Advanced Member Anshoo Arora's Avatar
    Join Date
    Oct 2007
    Location
    New Delhi, India
    Posts
    635
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Total Downloaded
    0

    Re: SPLIT, Option Explicit and Type Mismatch

    try this:

    <font class="small">Code:</font><hr /><pre>
    Option Explicit

    Dim aText, sLongText

    sLongText = "AAAxxxBBBxxxCCCxxxDDD"
    aText = Split(sLongText,"xxx")
    </pre><hr />
    Regards,

    Anshoo Arora
    Relevant Codes

  3. #3
    Moderator
    Join Date
    Jul 2005
    Location
    Delhi
    Posts
    15,575
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    7 Thread(s)
    Total Downloaded
    0

    Re: SPLIT, Option Explicit and Type Mismatch

    aText(3) is your problem. You can't have a fixed array for using split. You need to use a variant.

 

 

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Search Engine Optimisation provided by DragonByte SEO v2.0.36 (Pro) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
Resources saved on this page: MySQL 11.54%
vBulletin Optimisation provided by vB Optimise v2.6.4 (Pro) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
User Alert System provided by Advanced User Tagging v3.2.8 (Pro) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
vBNominate (Lite) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
Feedback Buttons provided by Advanced Post Thanks / Like (Pro) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
Username Changing provided by Username Change (Free) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
BetaSoft Inc.
Digital Point modules: Sphinx-based search
All times are GMT -8. The time now is 10:01 AM.

Copyright BetaSoft Inc.