?
Solved

Microsoft VBScript runtime error '800a0009' Subscript out of range

Posted on 2012-08-19
11
Medium Priority
?
1,063 Views
Last Modified: 2012-08-21
I am getting the following error:
newGroupValues(k) = Split(Trim(GroupValues(k)), "=") 'Error Line 56: Microsoft VBScript runtime error '800a0009' Subscript out of range
For clarity I am posting full code below:
Thanks in advance for any help given.
<%
Response.Write("Page:" & "tempScript" & currentPage & ".asp#    db22:" & strDB22 & "#<br/>dt22:" & strDBT22 & "#    intDetail22:" & intstrDetail22 & "#    strD22:" & strSession22 & "#    PageID:" & currentPage & "#<br/>")
Dim server_tb 'As String = Nothing
Dim user_tb 'As String = Nothing
Dim pswrd_tb 'As String = Nothing
Dim timeout_tb 'As String = Nothing
Dim database_tb 'As String = Nothing
Dim table_tb 'As String = Nothing
Dim connstr 'As String = "@" & detailsLabelappTest
Dim str1() 'As String = connstr.Split(";"c)
connstr = "@" & strDB22
Response.Write("strDB22:" & strDB22 & "#")
Dim strString 'As String
Dim arrValues 'As Variant
Dim GroupValues() 'As Variant
Dim newGroupValues() 'As Variant
strString = strDB22
if strString = "" then

else
arrValues = Split(Trim(strString), ";")
j = 0
For i = 0 To UBound(arrValues)
    If Trim(arrValues(i)) <> "" Then
        ReDim Preserve GroupValues(j) 'As Variant
        GroupValues(j) = arrValues(i)
        j = j + 1
    End If
Next
Response.Write("<br/>")
For i = 0 To UBound(GroupValues)
    Response.Write ("(" & i & ")" & GroupValues(i) & "#&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;")
Next
Response.Write("&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;")
Dim k : k = 3
newGroupValues(k) = Split(Trim(GroupValues(k)), "=") 'Error Line 56: Microsoft VBScript runtime error '800a0009' Subscript out of range
database_tb = Cstr(newGroupValues(k))
Response.Write ("(" & k & ")" & Split((GroupValues(k)), "=") & "#&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;")
end if
Response.Write("<br/>")
table_tb = strDBT22
'Response.Write("De6:" & "&nbsp;server_tb:" & server_tb & "#&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;user_tb:" & user_tb & "#&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;pswrd_tb:" & pswrd_tb & "#&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;database_tb:" & database_tb & "#&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;table_tb:" & table_tb & "#&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;intDetail:" & intstrDetail22 & "#")
Session("Server") = server_tb
Session("UserName") = user_tb
Session("Password") = pswrd_tb
Session("DatabaseSelected") = database_tb
'Session("TrustedSelected") = trusted_tb
Session("TableSelected") = table_tb
'Session["IsConnectionInfoSet"] = true;
%>
0
Comment
Question by:homeshopper
  • 6
  • 4
11 Comments
 
LVL 76

Expert Comment

by:GrahamSkan
ID: 38309660
You seem to be trying to set one item of an array to an array created by a Split instruction on a single item in another array.

Can you say what you are hoping to do here?
0
 

Author Comment

by:homeshopper
ID: 38309762
I have the following variables:
Response.Write("Page:" & "tempScript" & currentPage & ".asp#    db22:" & strDB22 & "#<br/>dt22:" & strDBT22 & "#    intDetail22:" & intstrDetail22 & "#    strD22:" & strSession22 & "#    PageID:" & currentPage & "#<br/>")
Dim connstr
Dim str1()
Dim user_tb
Dim pswrd_tb
Dim timeout_tb
Dim database_tb
Dim table_tb
connstr = "@" & strDB22
Response.Write("strDB22:" & strDB22 & "#")

This will display connection string etc as below:
strDB22:Data Source=dinosaur1;User ID=sa;Password=sasa; Initial Catalog=Cams2;#

Now, what I am trying to achieve is the following:
database_tb = Cams2 ' this should come from string strDB22
table_tb = strDBT22  ' this line ok for table name.
server_tb = dinosaur1 ' this should come from string strDB22
user_tb = sa ' this should come from string strDB22
pswrd_tb = sasa ' this should come from string strDB22
0
 
LVL 54

Expert Comment

by:Scott Fell, EE MVE
ID: 38309807
strDB22="Data Source=dinosaur1;User ID=sa;Password=sasa; Initial Catalog=Cams2;"
arrDB22=split(strDB22,";")

for each x in arrDB22
    xField=split(x,"=")
     select case xField
      case "Data Source"
           server_tb = xField(1)
        case "User ID"
           user_tb=xField(1)

        case "Password"
               pswrd_tb=xField(1)
        case "Initial Catalog"
               database_tb=xField(1)
      end select

next
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 

Author Comment

by:homeshopper
ID: 38311101
Thank you for your comment.
I ran your suggest code as is, it asked for arrDB22, x, and xField to be defined.
So I declared Dim arrDB22, x, xField
I must be missing something, because I get error as follows:
Microsoft VBScript runtime error '800a000d' Type mismatch
/sqlScriptClassicData/scriptFrame/tempScript1.asp, line 125
select case xField
Thanks in advance for any help given.
0
 
LVL 54

Expert Comment

by:Scott Fell, EE MVE
ID: 38311238
try  select case xField(0)
0
 

Author Comment

by:homeshopper
ID: 38311280
Thank you, but new error now:
Microsoft VBScript runtime error '800a0009'
Subscript out of range: '[number: 0]'
I have put a Response.Write in the code:
arrDB22:Data Source=dinosaur1#          arrDB22:User ID=sa#          arrDB22:Password=sasa#          arrDB22: Initial Catalog=Cams2#          arrDB22:#
for each x in arrDB22
Response.Write("arrDB22:" & x & "#&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;")
    xField=split(x,"=")
     select case xField(0)
      case "Data Source"
           server_tb = xField(1)
        case "User ID"
           user_tb=xField(1)
        case "Password"
               pswrd_tb=xField(1)
        case "Initial Catalog"
               database_tb=xField(1)
      end select
next
0
 
LVL 54

Accepted Solution

by:
Scott Fell,  EE MVE earned 2000 total points
ID: 38311513
<%

strDB22="Data Source=dinosaur1;User ID=sa;Password=sasa; Initial Catalog=Cams2;"
if right(strDB22,1)=";" then
	strDB22=left(strDB22,len(strDB22)-1)
end if
arrDB22=split(strDB22,";")
for each x in arrDB22
   xField=split(x,"=")
	 response.write xField(0) & "=" & xField(1)&"<br>" 'just to see what is going oin
	 if xField(0)="Initial Catalog" then
	 		database_tb= xField(1)
	end if
	 if xField(0)="User ID" then
	 		user_tb= xField(1)
	end if
	 if xField(0)="Data Source" then
	 		server_tb= xField(1)
	end if
	 if xField(0)="Password" then
	 		pswrd_tb= xField(1)
	end if

next

response.write "password="&pswrd_tb

%>

Open in new window

0
 

Author Comment

by:homeshopper
ID: 38311685
Thank you for your help. Your new code displays:
Data Source=dinosaur1
User ID=sa
Password=sasa
Initial Catalog=Cams2
password=sasa
I also made some ajustments with your original code and got that to work also.
I now have two working methods to choose from.
In your first I took out leading space before Initial Catalog
Then added line strDB22 = strDB22 & "@=@"
This displays the following:
strDB22:Data Source=dinosaur1;User ID=sa;Password=sasa;Initial Catalog=Cams2;@=@#
arrDB22:Data Source=dinosaur1#
arrDB22:User ID=sa#
arrDB22:Password=sasa#
arrDB22:Initial Catalog=Cams2#
arrDB22:@=@#

server_tb:dinosaur1#
user_tb:sa#
pswrd_tb:sasa#
database_tb:Cams2#
lastItem_tb:@#

The complete code used is below:
<%
Dim arrDB22, x, xField, server_tb, user_tb, pswrd_tb, database_tb, lastItem_tb
strDB22="Data Source=dinosaur1;User ID=sa;Password=sasa;Initial Catalog=Cams2;"
strDB22 = strDB22 & "@=@"
arrDB22=split(strDB22,";")
Response.Write("strDB22:" & strDB22 & "#<br/>")
for each x in arrDB22
Response.Write("arrDB22:" & x & "#<br/>")
    xField=split(x,"=")
     select case xField(0)
      case "Data Source"
           server_tb = xField(1)
      case "User ID"
           user_tb=xField(1)
      case "Password"
               pswrd_tb=xField(1)
      case "Initial Catalog"
               database_tb=xField(1)
      case "@"
               lastItem_tb=XField(1)
      end select
next
Response.Write("<br/>")
Response.Write("server_tb:" & server_tb & "#<br/>user_tb:" & user_tb & "#<br/>pswrd_tb:" & pswrd_tb & "#<br/>database_tb:" & database_tb & "#<br/>lastItem_tb:" & lastItem_tb & "#" )
%>

Once again, Thank you for all your help.
0
 

Author Comment

by:homeshopper
ID: 38311716
I'll use your second method and award points to your last post as complete solution.
Thanks again.
0
 
LVL 54

Expert Comment

by:Scott Fell, EE MVE
ID: 38313189
Great!  
Sometimes it is just the data. The main thing I was trying to accomplish was creating an array inside of an array.

Part of making this work is getting clean data which is why I did the code below to get rid of the trailing semi colon.

if right(strDB22,1)=";" then
      strDB22=left(strDB22,len(strDB22)-1)
end if
0
 

Author Comment

by:homeshopper
ID: 38315260
Yes, I agree. Thank you for the code. It is a method I can use time & time again.
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Not long ago I saw a question in the VB Script forum that I thought would not take much time. You can read that question (Question ID  (http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/Q_28455246.html)28455246) Here (http…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses

850 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