Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Split a DB field content 4

Status
Not open for further replies.

Herminio

Technical User
May 10, 2002
189
PT
I'm having a problem here, i have a field in a DB that supports 250 char, i need to split it in order to use only blocks of 50 chars and then make a line break on it, i don't know what's the best way to do it, is it better to split and append the "\n" when the text is submited to the DB or when it's read from the DB?

Either way can someone help me with the split code?

Thanks in advance

Herminio, Portugal
 
I wrote this quickly and it seems to work

temptext="ajiocvncxklviocxllfewnk,ndsfvnkldsjicxviocskdjhkl+
jfkldsjflkdsufiodsfjldsfjldsfjldsjkldfgfdgsfdgsddfgsfdgsfdgs
dgsdfgsevererhregsghfred"
templen=len(temptext)/50

dim blockarray(5)

blockarray(0)=left(temptext,50)

for count=1 to templen+1
blockarray(count)=mid(temptext,(count*50)+1,50)
next

for count=1 to templen+1
response.write blockarray(count-1) & &quot;<BR>&quot;
next Saturday 12.00
im6.gif
im2.gif
im2.gif
20.00
im5.gif
im4.gif
im7.gif
3.00am
im8.gif
Sunday [img http
 
i've tried to use your code and at the end this is what's happening:

Microsoft VBScript runtime error (0x800A000D)
[string: &quot;primeiro testelfdijl&quot;]'
/opiniao/splitarray.asp, line 26

this is the code

<%
op = opin(&quot;opiniao&quot;)

tempOpin = len(op)/50

Dim blockarray(5)
blockarray(0) = left(op,50)

for count=1 to op+1 --> line 26
blockarray(count)=mid(op,(count*50)+1.50)
next

for count=1 to op+1
response.write blockarray(count-1)& &quot;<br>&quot;
next

%>

Can you tell me what's wrong?
 
blockarray(count)=mid(op,(count*50)+1.50)
should be
blockarray(count)=mid(op,(count*50)+1,50)

its 1 , 50 not 1.50 Saturday 12.00
im6.gif
im2.gif
im2.gif
20.00
im5.gif
im4.gif
im7.gif
3.00am
im8.gif
Sunday [img http
 
You've also used the wrong variable:

for count=1 to tempOpin + 1 --> line 26 --James
 
i've made the changes and now this:

Microsoft VBScript runtime error (0x800A0009)
Format out of interval: 'count'
/opiniao/splitarray.asp, line 27

Code:

<%
op = opin(&quot;opiniao&quot;)
tempOpin = len(op)/50

Dim blockarray(5)
blockarray(0) = left(op,50)

for count=1 to tempOpin+1
blockarray(count)= mid(op,(count*50)+1,50) --> line 27
next

for count=1 to op+1
response.write blockarray(count-1)& &quot;<br>&quot;
next

%>
 
Do the same for Line 30

for count=1 to op+1

should be

for count=1 to tempOpin+1
BDC.
 
for count=1 to op+1

should be

for count=1 to tempopin+1 Saturday 12.00
im6.gif
im2.gif
im2.gif
20.00
im5.gif
im4.gif
im7.gif
3.00am
im8.gif
Sunday [img http
 
Hang on, hang on. I think there's an easier way of doing this:

Code:
op = opin(&quot;opiniao&quot;)

lines = Len(op) / 50

For i = 1 To lines
	Response.Write Mid(op, i * 50 + 1, 50) & &quot;<br>&quot;
Next

Does that work? --James
 
No but this does,

op = opin(&quot;opiniao&quot;)

lines = Len(op) / 50

For i = 0 To lines
Response.Write Mid(op, i * 50 + 1, 50) & &quot;<br>&quot;
Next

;-)
BDC.
 
i've done that, but the last error i reported keeps on making me nuts, but now on line 26

format out of interval: count
 
Oops, sorry. I went back and changed my code just before I submitted my post but missed that!

Herminio, can you post the code you have now? This works fine for me. --James
 
Thank's to you all guys, it's working, one star for each one of you, you're just great(as always).

Thanks

Herminio, Portugal
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top