Sammy
asked on
Trap Error Subscript out of range: '[number: 3]'
Hi guys,
I have this code
Function SplitArray( strData )
Dim arr
Dim dict
Dim nCounter
Set dict = CreateObject("Scripting.Di ctionary")
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
I have this code
Function SplitArray( strData )
Dim arr
Dim dict
Dim nCounter
Set dict = CreateObject("Scripting.Di
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
Sorry, wrong question.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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.Di ctionary")
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
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.Di
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
Set dict = CreateObject("Scripting.Di ctionary")
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
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
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*
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*
ASKER
i guess i was over excited
now this
----
Function SplitArray( strData )
Dim arr
Dim dict
Dim nCounter
Set dict = CreateObject("Scripting.Di ctionary")
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 !!
now this
----
Function SplitArray( strData )
Dim arr
Dim dict
Dim nCounter
Set dict = CreateObject("Scripting.Di
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 !!
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.Di ctionary")
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?
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.Di
arr = Split( strData, "/" )
If ( ((UBound(arr)-LBound(arr))
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?
> 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*