Solved

Trap Error Subscript out of range: '[number: 3]'

Posted on 2003-11-19
8
639 Views
Last Modified: 2007-11-27
Hi guys,
I have this code
Function SplitArray( strData )

          Dim arr
          Dim dict
          Dim nCounter

          Set dict = CreateObject("Scripting.Dictionary")
          arr = Split( strData, "/" )
          For nCounter = 0 To UBound(arr) Step 2


          dict(arr(nCounter)) = arr(nCounter+1)
           

Next

          Set SplitArray = dict

     End Function
this will call it
Set objValues = SplitArray( StrKey )

how can i trap the error if StrKey becomes an Odd number ?

Thanx
0
Comment
Question by:Sammy
8 Comments
 
LVL 19

Expert Comment

by:Dexstar
ID: 9782932
ainapure:

> xp_sendmail will work only if the server has MS Exchange installed on the
> machine that hosts the database server.

That is simply not true.  Any valid MAPI client will work just fine.

> Another way is to write a normal asp page that queries the information from
> database and sends out the mail. You can then schedule this asp page through
> a .vbs file which can be scheduled using the OS's task scheduler.

Even more simple would be to use the SQL Server's schedule mechanism.  It can run any program, script, or stored procedure.

In any event, there are several ways to schedule a task, and several ways to send database results via e-mail.  You just have to mix and match the options that help you the most.

Hope That Helps,
Dex*
0
 
LVL 19

Expert Comment

by:Dexstar
ID: 9782937
Sorry, wrong question.
0
 
LVL 19

Accepted Solution

by:
Dexstar earned 80 total points
ID: 9782998
sammy1971:

> how can i trap the error if StrKey becomes an Odd number ?

Where did you get that function?  I'm pretty sure I wrote it...  :)
Here is a version that handles the situation you mentioned.  It will simply just ignore the extra value.

      Function SplitArray( strData )
            Dim arr
            Dim dict
            Dim nCounter

            Set dict = CreateObject("Scripting.Dictionary")
            arr = Split( strData, "/" )
            For nCounter = 0 To UBound(arr) Step 2
                  If ( nCounter < UBound(arr) ) Then
                        dict(arr(nCounter)) = arr(nCounter+1)
                  End If
            Next

            Set SplitArray = dict
      End Function

Hope That Helps,
Dex*
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 4

Expert Comment

by:ainapure
ID: 9783067
sammy,

there is a function called Mod in vbscript that returns 0 if number is even or 1 if the number is odd. Here is a small modification to your code

******modified code*********
Function SplitArray( strData )

          Dim arr
          Dim dict
          Dim nCounter

          Set dict = CreateObject("Scripting.Dictionary")
          arr = Split( strData, "/" )
          For nCounter = 0 To UBound(arr) Step 2


          dict(arr(nCounter)) = arr(nCounter+1)
           

Next

          Set SplitArray = dict

     End Function
check=StryKey Mod 2
if check=0 then
Set objValues = SplitArray( StrKey )
else
'Write some message
end if
**********end code**********************

hope this helps
-amit
0
 
LVL 6

Expert Comment

by:Mike_Metro
ID: 9783105
       Set dict = CreateObject("Scripting.Dictionary")
        arr = Split( strData, "/" )
        For nCounter = 0 To UBound(arr) Step 2
            dict(arr(nCounter)) = arr(nCounter+1)

            If Ubound(arr) = nCounter + 2 Then  
               dict(arr(nCounter+2)) = ""
               Exit For
        Next
0
 
LVL 19

Expert Comment

by:Dexstar
ID: 9783115
Amit:

strKey is a string, not a numeric value, so you can't MOD on it.  The Asker wanted to know how to trap the error when strKey has an odd number of sections in it.

(I only recognized that because I wrote the original function for some other question...)

Dex*
0
 
LVL 27

Author Comment

by:Sammy
ID: 9783301
i guess i was over excited
now this

----
Function SplitArray( strData )
          Dim arr
          Dim dict
          Dim nCounter

          Set dict = CreateObject("Scripting.Dictionary")
          arr = Split( strData, "/" )
          For nCounter = 0 To UBound(arr) Step 2

               If ( nCounter < UBound(arr) ) Then
response.write "ODD"
else
                    dict(arr(nCounter)) = arr(nCounter+1)
response.write "Even"
               End If
          Next

          Set SplitArray = dict
     End Function

will always write ODD !!

0
 
LVL 19

Expert Comment

by:Dexstar
ID: 9783377
sammy:

Yeah, that's what it would do.  I think you want something more like this:

     Function SplitArray( strData )
          Dim arr
          Dim dict
          Dim nCounter

          Set dict = CreateObject("Scripting.Dictionary")
          arr = Split( strData, "/" )
          If ( ((UBound(arr)-LBound(arr)) MOD 2) = 0 ) Then
                    Response.Write "Even"
          Else
                    Response.Write "Odd"
          End If
         
          For nCounter = 0 To UBound(arr) Step 2
               If ( nCounter < UBound(arr) ) Then
                    dict(arr(nCounter)) = arr(nCounter+1)
               End If
          Next

          Set SplitArray = dict
     End Function

How's that?
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
How can I do a Massively massive community reviewing-and-grading site? 7 79
SQL to update characters in table column 6 157
Button to go back 3 38
Html split(text) 2 26
I would like to start this tip/trick by saying Thank You, to all who said that this could not be done, as it forced me to make sure that it could be accomplished. :) To start, I want to make sure everyone understands the importance of utilizing p…
I was asked about the differences between classic ASP and ASP.NET, so let me put them down here, for reference: Let's make the introductions... Classic ASP was launched by Microsoft in 1998 and dynamically generate web pages upon user interact…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

680 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question