Solved

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

Posted on 2003-11-19
8
635 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
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 
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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
syntax error on ASP ? 6 46
Hide row when retrieving data from database 6 61
Server Timeout with Loop 6 45
alert(innerHTML); 8 18
I have helped a lot of people on EE with their coding sources and have enjoyed near about every minute of it. Sometimes it can get a little tedious but it is always a challenge and the one thing that I always say is:  The Exchange of information …
This demonstration started out as a follow up to some recently posted questions on the subject of logging in: http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28634665.html and http://www.experts-exchange.com/Programming/…
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.

810 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