Another VB question

T

the other john

I'm trying to enhance a script to do the following things.

1). detect the first four words of a paragraph and stylize them
(already does that)
2). Capitalize and stylize the first letter of each paragraph (already
does that via style sheet)
3). Count the number of paragraphs (or number of "vbcrlf & vbcrfl") so
I can insert a images in specific places (i.e. I want to dynamically
insert image 1 in paragraph 1, image 2 into para 2, etc.)

This third item I can't figure out. I've tried it a few ways but keep
running to problems.

Thanks!!!

The following script was provided by Mike Brind, thanks Mike. It
currently can produce results for the first 2 items I listed above but
not exactly the way I want it to. It places an image into the first
paragraph for each "record" but that's not what I want.

Dim str, i, spacepos, word
for wank = 1 to 7
if rsForums.EOF then exit for
if wank = 1 then
response.write "<img id='picFloat' src='testoboy.jpg'
class='picBorderThin'>"
End if
if wank = 2 then
response.write "<img id='picFloat' src='me.jpg'
class='picBorderThin'>"
End if
Response.Write "<p><span id='firstWords'>"
storyFix = replace(rsForums("T_MESSAGE"),vbcrlf & vbcrlf, "<p>")
story = replace(storyFix,"<p>", "</p>" & vbcrlf & "<p>")
for i = 1 to 4
spacepos = instr(story," " )
word = left(story,spacepos)
story = right(story,len(story)-spacepos)
response.write word
next

Response.Write "</span>"
Response.Write story
Response.Write "</p>" & vbcrlf & vbcrlf & "<hr>"
rsForums.MoveNext
next
rsForums.Close
Set rsForums = nothing
 
M

Mike Brind

the said:
I'm trying to enhance a script to do the following things.

1). detect the first four words of a paragraph and stylize them
(already does that)
2). Capitalize and stylize the first letter of each paragraph (already
does that via style sheet)
3). Count the number of paragraphs (or number of "vbcrlf & vbcrfl") so
I can insert a images in specific places (i.e. I want to dynamically
insert image 1 in paragraph 1, image 2 into para 2, etc.)

This third item I can't figure out. I've tried it a few ways but keep
running to problems.

Thanks!!!

The following script was provided by Mike Brind, thanks Mike. It
currently can produce results for the first 2 items I listed above but
not exactly the way I want it to. It places an image into the first
paragraph for each "record" but that's not what I want.

Dim str, i, spacepos, word
for wank = 1 to 7
if rsForums.EOF then exit for
if wank = 1 then
response.write "<img id='picFloat' src='testoboy.jpg'
class='picBorderThin'>"
End if
if wank = 2 then
response.write "<img id='picFloat' src='me.jpg'
class='picBorderThin'>"
End if
Response.Write "<p><span id='firstWords'>"
storyFix = replace(rsForums("T_MESSAGE"),vbcrlf & vbcrlf, "<p>")
story = replace(storyFix,"<p>", "</p>" & vbcrlf & "<p>")
for i = 1 to 4
spacepos = instr(story," " )
word = left(story,spacepos)
story = right(story,len(story)-spacepos)
response.write word
next

Response.Write "</span>"
Response.Write story
Response.Write "</p>" & vbcrlf & vbcrlf & "<hr>"
rsForums.MoveNext
next
rsForums.Close
Set rsForums = nothing

I wouldn't do this like this...

At some stage, each story/article is entered into a database. It's at
that point that I would manipulate it in the way you want. That way,
the operation is only ever performed once for each story, rather than
every time a page is requested.

Anyhoo, you need to break the problem down in the opposite order in
which you have. The first thing you need to do is to break the story
into paragraphs. Whether on input or output, this can be done using
split(). You also need to put you images into an array, so you can get
them by index.

Now that you have an array of paragraphs, and an array of images, it's
easy to loop through from 0 to 6, prepending each paragraph with its
associated image html. Within that loop, you can conduct the operation
to style the first few words. You would create a string containing the
first 7 paragraphs (adding <p> tags as needed). Then, if there are any
paragraphs left, you would need to loop through those to style the
first few words, and append them to your string. Then its ready for
input/output.
 
B

Bob Lehmann

At some stage, each story/article is entered into a database. It's at
that point that I would manipulate it in the way you want. That way,
the operation is only ever performed once for each story,

Good idea.....

Until the customer decides that they want the first 5 words stylized.

Bob Lehmann
 
M

Mike Brind

Even more reason to perform the operation on input. When the customer
changes the brief to have more or less words stylized, I'll look
forward to presenting the budget cost of doing so on existing data :)
 
M

Mike Brind

Nope.

paras = split(mystring,vbcrlf & vbcrlf)

This returns a one-dimensional zero-based array of paragraphs, so the
first paragraph will be held in the element referenced as paras(0), the
second in paras(1) etc.

Response.Write Ubound(paras) + 1 will give you the total number of
paragraphs.
 
T

the other john

I tried this and it seemed to work except now I have a style issue. The
problem is if the letter I want to be affected by p:first-letter isn't
actually at the beginning of the item it won't work and if I want the
first pic to appear at the top it has to be at the beginning of the
item. Ideas?

Thanks!!!

<style>
#picFloat {float:left;}
p:first-letter {color: #8B0000; font-size:
40px;font-family:times;float:left;}
#firstWords
{text-transform:uppercase;font-family:times;font-size:120%;}
</style>
'
'
myStory = rsForums("T_MESSAGE")

para = vbcrlf & vbcrlf

storyArray = Split(myStory, para)
storyArray(0) = "<img id='picFloat' src='testoboy.jpg'
class='picBorderThin'>" & storyArray(0)
storyArray(1) = storyArray(1) & "<img id='picFloat' src='me.jpg'
class='picBorderThin'>"

for each item in storyArray
Response.write "<p>" & item & "</p>"
Next
 
M

Mike Brind

I'm no CSS expert, so you might be better off asking this in a style
sheet group. However, try putting the text in a <p> tag

storyArray(0) = "<img id='picFloat' src='testoboy.jpg'
class='picBorderThin'><p>" & storyArray(0) & "</p>"
 
T

the other john

Cool, this almost has it. But to make it even better is there a way
other than the For Each loop that I can use to access "part" of the
array? If I could just stylize specific parts of the array one way and
the rest just be other, like an if else sort of thing that would put
this thing to bed. The array works "great"....not I just need to
figure out how to work with just "parts" of it. I'm thinking the For
Each loop isn't going to work in this case since it's an all or nothing
sort of thing. I haven't worked with arrays that much and don't know
the possibilities.

Thanks Mike! Learning a lot here!!
 
T

the other john

Tried this and it only delivers one word and appears to exit the loop.
In other words it appears to stylize the first word rather than the
desired first 4. Any ideas?

myStory = rsForums("T_MESSAGE")

para = vbcrlf & vbcrlf

storyArray = Split(myStory, para)

for i = 1 to 4
spacepos = instr(storyArray(0)," " )
word = left(storyArray(0),spacepos)
story = right(storyArray(0),len(storyArray(0))-spacepos)
next

storyArray(0) = "<span id='firstWords'>" & word & "</span>" & story



Thanks again!!!
 
M

Mike Brind

myStory = rsForums("T_MESSAGE")

paras = Split(myStory, vbcrlf & vbcrlf)
para = paras(0)
Response.Write "<span id='firstWords'>"
for i = 1 to 4
spacepos = instr(para," " )
word = left(para,spacepos)
Response.Write word
para= right(para,len(story)-spacepos)
next

Response.Write "</span>" & para

Each time the loop executes, it strips the first word from the
paragraph after writing it to the browser within the <span> tags. The
closing </span tag is written after the loop finishes, with the
remainder of the paragraph after it.
 
T

the other john

for some reason now I'm getting this...odd...don't know why..

Microsoft VBScript runtime error '800a0005'

Invalid procedure call or argument: 'right'

/paraTest.asp, line 36


"right" didn't cause a problem before. To be clear about what I was
trying to do I should have include the entire script. I'm trying to
tweek array items after getting the first 4 words formatted.

Thanks for your help Mike, I'm so close now, this is awesome!!!



myStory = rsForums("T_MESSAGE")

para = vbcrlf & vbcrlf

storyArray = Split(myStory, para)
for i = 1 to 4
spacepos = instr(storyArray(0)," " )
word = left(storyArray(0),spacepos)
story = right(storyArray(0),len(storyArray(0))-spacepos)
next

storyArray(0) = "<span id='firstWords'>" & word & "</span>" & story

storyArray(0) = "<img id='picFloat' src='testoboy.jpg'
class='picBorderThin'><p>" & storyArray(0) & "</p><blockquote>An
importand quote from the story here<blockquote>"

storyArray(1) = storyArray(1) & "<img id='picFloat' src='me.jpg'
class='picBorderThin'>"


for each item in storyArray
Response.write "<p>" & item & "</p>" & vbcrlf
Next
 
M

Mike Brind

It's not going to work because you are not changing the paragraph on
each loop. You change the variable from storyArray to story, but on
the next iteration, it goes back to storyArray again. At that point,
story is storyArray minus the first word, but when you enter the loop
again, storyArray(0) is still the same value as when you started (ie,
the whole paragraph with all words intact). Try replacing the example
you posted earlier with the bit I just posted, See if that works.
 
T

the other john

I'm still getting this error. I'm running the script exactly as you
wrote it. What am I missing?


Microsoft VBScript runtime error '800a0005'

Invalid procedure call or argument: 'right'

/paraTest.asp, line 40
 
T

the other john

oh, I see the problem now. there was still a "story" in there that
needed to be changed to "para". Ok, this worked...but how to I print
the rest of the array? Is there a way to use a for each loop and
skipping the first array item?
 
T

the other john

what's confusing me is how get the paragraph that's stylizing the first
4 words into a variable instead of writing it to the page.
Response.write appears to be whats allowing the loop to go on to the
next word. How do I "not" write to the page and put into a variable
instead so I can prepend it further?

I don't know how I got this far without having a better handle on
control structures, yikes. For example, is it possible to use
conditionals inside of a For Each loop?

For each item in thisArray
If item = whatever then
do this
Else
do somethinge else
End if
Next

I tried this and it didn't work so I assume answer is no but thought
I'd ask just the same.

Thanks!!!!
 
T

the other john

LOL, ok, I found a solution albeit a less than elegant one....

myStory = rsForums("T_MESSAGE")

storyArray = Split(myStory, vbcrlf & vbcrlf)
para = storyArray(0)
Response.Write "<img id='picFloat' src='testoboy.jpg'
class='picBorderThin'><p><span id='firstWords'>"
for i = 1 to 4
spacepos = instr(para," " )
word = left(para,spacepos)
Response.Write word
para= right(para,len(para)-spacepos)
next

Response.Write "</span>" & para & "</p><blockquote>A quote on the side
somewhere</blockquote>" & vbcrlf

storyArray(1) = storyArray(1) & "<img id='picFloat' src='me.jpg'
class='picBorderThin'>"

for paraLoop = LBound(storyArray)+1 to UBound(storyArray)
Response.write "<p>" & storyArray(paraLoop) & "</p>" & vbcrlf
next

Thanks Mike for everything! Any other ideas I appreciate it!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,236
Members
46,822
Latest member
israfaceZa

Latest Threads

Top