 |
| Classic ASP Basics For beginner programmers starting with "classic" ASP 3, pre-".NET." NOT for ASP.NET 1.0, 1.1, or 2.0 |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the Classic ASP Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|
|

November 5th, 2003, 09:55 AM
|
|
Authorized User
|
|
Join Date: Sep 2003
Posts: 72
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Decomposing a String
HEllo everybody. I have a text field In which users enters didits like 1,2,3,4,5,6,100,2036 How can I break the string to get digits seperated from Comma. PLease Please help me in this regard.
I am in deep trouble.
Bye
Zaeem Sherazi
__________________
Zaeem Sherazi
|
|

November 5th, 2003, 10:24 AM
|
 |
Friend of Wrox
|
|
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
|
|
aryNumbers = Split(sList, ",")
This will return you an array of the numbers.
Peter
----------------------------------------
Work smarter, not harder.
|
|

November 6th, 2003, 12:27 AM
|
|
Authorized User
|
|
Join Date: Sep 2003
Posts: 72
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Hello I am using this code for decomposing the string but it gives me Error "Unhandeld Data Type Ocuured"
Please guide me in this regard.
<%dim a,aryNumbers,i
a="he"
a=a&","
a=a&"ge"
for i=0 to 7
aryNumbers = Split(a, ",")
response.Write(aryNumbers)
next
%>
Zaeem Sherazi
|
|

November 6th, 2003, 12:56 AM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 596
Thanks: 1
Thanked 3 Times in 3 Posts
|
|
Zaeem,
aryNumbers is an array after the split so you must itentify the elemetn you wish to use
ie
response.write(aryNumers(0))
or
response.write(aryNumbers(1))
there are only two items in the array "he" and "ge"
so you code would write one of those elements seven times
======================================
They say, best men are moulded out of faults,
And, for the most, become much more the better
For being a little bad.
======================================
|
|

November 6th, 2003, 12:59 AM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 596
Thanks: 1
Thanked 3 Times in 3 Posts
|
|
If you wish to list the items in the array, try
for i = 0 to ubound(aryNumbers)
response.write(aryNumbers(i) & "<BR>")
next
======================================
They say, best men are moulded out of faults,
And, for the most, become much more the better
For being a little bad.
======================================
|
|

November 6th, 2003, 01:17 AM
|
|
Authorized User
|
|
Join Date: Sep 2003
Posts: 72
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
I am using this code now but there is same error "Response object, ASP 0106 (0x80020005)
An unhandled data type was encountered.
"
<%dim a,b,aryNumbers(50),i
a="he"
a=a&","
a=a&"ge"
for i = 0 to 100'UBound(aryNumbers)
aryNumbers(i) = Split(a, ",")
response.write(aryNumbers(i))
next
%>
I am thankful to u for ur quick reply.
Bye
Zaeem Sherazi
|
|

November 6th, 2003, 01:33 AM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 596
Thanks: 1
Thanked 3 Times in 3 Posts
|
|
Zaeem,
You do not need to identify the index when you are assigning to the array.
aryNumbers refers to all the contents of the array as one object and aryNumbers(i) refers to one item in that array.
So the line
aryNumbers(i) = Split(a, ",")
should be
aryNumbers = Split(a, ",")
also the array only has 2 elements ("he" and "ge"), you can not list 101 items in the array.
and you do not wish to split the array in the loop as you are efectively doing it 100 times, this needs to be done before the loop.
try this code below but make sure you begin to understand it as well ,you will use arrays and split many times in asp
Code:
<%
' declare the variables
dim a,aryNumbers,i
' set the varable a to be a comma seperated string of anything
a="a,b,c,d,e,f"
' split the string into elements and assign them to the array
aryNumbers = Split(a, ",")
'loop through the elements in the array
'and write out there value and a new line break
'ubound is the index of the last array element
for i = 0 to UBound(aryNumbers)
response.write(aryNumbers(i) & "<BR>")
next
%>
let me know how you go
======================================
They say, best men are moulded out of faults,
And, for the most, become much more the better
For being a little bad.
======================================
|
|

November 6th, 2003, 04:41 AM
|
|
Authorized User
|
|
Join Date: Sep 2003
Posts: 72
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Thanx buddy it worked fine. Believe me you saved me.
I am very grateful to u for this favor.and hope to get same help in the future.
Bye
Zaeem Sherazi
|
|

November 6th, 2003, 04:59 AM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 596
Thanks: 1
Thanked 3 Times in 3 Posts
|
|
No Worries, Good luck with it all.
======================================
They say, best men are moulded out of faults,
And, for the most, become much more the better
For being a little bad.
======================================
|
|

November 7th, 2003, 01:07 AM
|
|
Authorized User
|
|
Join Date: Sep 2003
Posts: 72
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Hello Budy now the split function works fine,but now I have different scenario. that is newarr=split(a,",")return the array of elements.
Now I am pathing that array into the query
<% dim newarr,tem
for i=0 to Ubound(newarr)
select * from key_word where key_words='"&newarr(i)&"',connection,2,2
tem=rs("key_word_id").value 'Error Here
r.close
next
tem
%>
after that I will the keyword id from temp but it will give error that
"type mismatch". Now as usual u can help me in this regards.
I am waiting for ur mail.
Bye
Zaeem Sherazi
|
|
 |