Click to See Complete Forum and Search --> : Break recordset data up


Steve_FX
07-31-2005, 09:38 PM
Hopefully somebody can help me with this... I’m building a website based upon external XML data that I have no control over... I’ve successfully incorporated all of the data in an appropriate database however one of the recordset fields contains all of the image data.

e.g.

{8900/8907-1-b.jpg,8900/8907-1-sph.jpg,8900/8907-b.jpg,8900/8907-h.jpg,8900/8907-m.jpg,8900/8907-rs.jpg,8900/8907-spb.jpg,8900/8907-sph.jpg}

Can somebody help explain/show (ASP/VB script) how I split this recordset down so that I can display each image:

8900/8907-sph.jpg
8900/8907-spb.jpg
etc

Wherever I want an image displayed...

Thanks

Steve

buntine
07-31-2005, 10:53 PM
You will need to use the Split function. The Split function will split a string into tokens based on the recurrance of a specific character (or substring).

In this case, the images are delimited with a comma; so:

Dim arrImages, strRecordVal
strRecordVal = <theRecordSetField>
strRecordVal = Replace(strRecordVal, "{", "") '| Remove the curly brackets if they are present.
strRecordVal = Replace(strRecordVal, "}", "")

arrImage = Split(strRecordVal, ",") '| Split into an array of image filenames.

You can now access the substrings via their respective indexes:

'| Loop through each filename.
Dim i
For i = 0 To UBound(arrImages)
Response.Write arrImages(i) & "<br />"
Next

Regards.

Steve_FX
08-01-2005, 12:00 AM
Thank you Andrew...

I seem however to be having one of those days... I guess I must get a little more sleep... can you do me a favour and make it almost idiot proof for me... this is my database recordset info... could you or somebody else kindly incorporate this within your code above so that it works... as I said I’m having one hell of a day here.

<%=(Recordset1.Fields.Item("Screenshots").Value)%>

Thank you

Steve

buntine
08-01-2005, 12:11 AM
No worries.

Give this a shot:

Dim arrImages, strRecordVal
strRecordVal = Recordset1.Fields.Item("Screenshots").Value
strRecordVal = Replace(strRecordVal, "{", "") '| Remove the curly brackets if they are present.
strRecordVal = Replace(strRecordVal, "}", "")

arrImage = Split(strRecordVal, ",") '| Split into an array of image filenames.

'| Loop through each filename.
Dim i
For i = 0 To UBound(arrImages)
Response.Write arrImages(i) & "<br />"
Next

Regards.

Steve_FX
08-01-2005, 12:23 AM
My day continues... I’ve just tried this solution and I’m now encountering this error:

Error Type:
Microsoft VBScript runtime (0x800A000D)
Type mismatch: 'UBound'

Any idea???

Steve

Steve_FX
08-01-2005, 01:01 AM
Success... for those interested the following code works... thanks Andrew your help much appreciated... as is everybody elses...

<%
dim arrStr
dim theStr

theStr = Recordset1.Fields.Item("Screenshots").Value
theStr = Replace(theStr, "{", "")
theStr = Replace(theStr, "}", "")

arrStr = Split(theStr,",")

for i=0 to Ubound(arrStr)
response.write(arrStr(i)) & "<br />"
next
%>

Steve

buntine
08-01-2005, 01:16 AM
Glad to see you got it working. ;)

Steve_FX
08-01-2005, 04:22 AM
A silly question... but I can now display the text of each image... however I do I actually show each image... ???

Steve

buntine
08-01-2005, 04:43 AM
Place the filename within an HTML img element. In correspondance with your code:

<%
dim arrStr
dim theStr

theStr = Recordset1.Fields.Item("Screenshots").Value
theStr = Replace(theStr, "{", "")
theStr = Replace(theStr, "}", "")

arrStr = Split(theStr,",")

for i=0 to Ubound(arrStr)
response.write("<img src=""" & arrStr(i) & """ alt=""some alternate text"" />")
next
%>

Regards.

Steve_FX
08-01-2005, 04:53 AM
thanks Andrew... and I've looked over your site and noted your also in Perth and planning to go to University soon... so I expect this is a mutually beneficial chance meeting...

Steve Cartwright

buntine
08-01-2005, 05:41 AM
Ahh. Great. I am guessing you are a lecturer? Or student?

Regards.