Wrox Programmer Forums

Need to download code?

View our list of code downloads.

| FAQ | Members List | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old November 5th, 2003, 09:55 AM
Authorized User
 
Join Date: Sep 2003
Location: islamabad, pk, Pakistan.
Posts: 72
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to zaeem Send a message via Yahoo to zaeem
Default 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
Reply With Quote
  #2 (permalink)  
Old November 5th, 2003, 10:24 AM
planoie's Avatar
Friend of Wrox
Points: 16,481, Level: 55
Points: 16,481, Level: 55 Points: 16,481, Level: 55 Points: 16,481, Level: 55
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2003
Location: Clifton Park, New York, USA.
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

aryNumbers = Split(sList, ",")

This will return you an array of the numbers.

Peter
----------------------------------------
Work smarter, not harder.
Reply With Quote
  #3 (permalink)  
Old November 6th, 2003, 12:27 AM
Authorized User
 
Join Date: Sep 2003
Location: islamabad, pk, Pakistan.
Posts: 72
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to zaeem Send a message via Yahoo to zaeem
Default


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
Reply With Quote
  #4 (permalink)  
Old November 6th, 2003, 12:56 AM
Friend of Wrox
Points: 2,376, Level: 20
Points: 2,376, Level: 20 Points: 2,376, Level: 20 Points: 2,376, Level: 20
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: , , Australia.
Posts: 596
Thanks: 1
Thanked 3 Times in 3 Posts
Default

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.
======================================
Reply With Quote
  #5 (permalink)  
Old November 6th, 2003, 12:59 AM
Friend of Wrox
Points: 2,376, Level: 20
Points: 2,376, Level: 20 Points: 2,376, Level: 20 Points: 2,376, Level: 20
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: , , Australia.
Posts: 596
Thanks: 1
Thanked 3 Times in 3 Posts
Default

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.
======================================
Reply With Quote
  #6 (permalink)  
Old November 6th, 2003, 01:17 AM
Authorized User
 
Join Date: Sep 2003
Location: islamabad, pk, Pakistan.
Posts: 72
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to zaeem Send a message via Yahoo to zaeem
Default

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
Reply With Quote
  #7 (permalink)  
Old November 6th, 2003, 01:33 AM
Friend of Wrox
Points: 2,376, Level: 20
Points: 2,376, Level: 20 Points: 2,376, Level: 20 Points: 2,376, Level: 20
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: , , Australia.
Posts: 596
Thanks: 1
Thanked 3 Times in 3 Posts
Default

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.
======================================
Reply With Quote
  #8 (permalink)  
Old November 6th, 2003, 04:41 AM
Authorized User
 
Join Date: Sep 2003
Location: islamabad, pk, Pakistan.
Posts: 72
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to zaeem Send a message via Yahoo to zaeem
Default

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
Reply With Quote
  #9 (permalink)  
Old November 6th, 2003, 04:59 AM
Friend of Wrox
Points: 2,376, Level: 20
Points: 2,376, Level: 20 Points: 2,376, Level: 20 Points: 2,376, Level: 20
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: , , Australia.
Posts: 596
Thanks: 1
Thanked 3 Times in 3 Posts
Default

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.
======================================
Reply With Quote
  #10 (permalink)  
Old November 7th, 2003, 01:07 AM
Authorized User
 
Join Date: Sep 2003
Location: islamabad, pk, Pakistan.
Posts: 72
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to zaeem Send a message via Yahoo to zaeem
Default

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
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
how to find a string in another string in vb6 satish_k VB How-To 3 March 30th, 2007 12:17 PM
Casting String array to string Samatha ASP.NET 1.0 and 1.1 Professional 1 December 5th, 2006 07:46 AM
syntax to find a string in a string cole SQL Server 2000 2 October 10th, 2005 06:06 PM
how to replace a string with another string/number crmpicco Javascript How-To 4 March 14th, 2005 12:59 PM



All times are GMT -4. The time now is 09:23 AM.


Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.