Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

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

Posted on 2003-11-19
8
638 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
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

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

 
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
HTML in email body has extra  tick marks 3 87
Connection to multiple databases 13 25
alert(innerHTML); 8 32
Adjust an existing ASP Query 45 15
Hello, all! I just recently started using Microsoft's IIS 7.5 within Windows 7, as I just downloaded and installed the 90 day trial of Windows 7. (Got to love Microsoft for allowing 90 days) The main reason for downloading and testing Windows 7 is t…
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/…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

790 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