Click to See Complete Forum and Search --> : Please help me with this function!!
Decayed
February 24th, 2000, 07:19 PM
i would like to make a function that inserts opening and closing html tags around selected text in a textbox (it wraps the tags around a selected text)
the function would start like
public function wrapTags(tag, additionalstuff, textbox)
'Tag is the HTML tag we want to wrap around selected text
' on the start of the selected text it would add
textbox.seltext = "<" & tag & " " & additionalstuff & ">"
' and on the end of the text it would add
textbox.seltext = "</" & tag & ">"
i would call the function like this:
call wrapTags("HEAD", "bgcolor='black'", "frmMDI.ActiveForm.Text1")
PLEEEEEAAAAASEEEE HELP ME OUT!!
---------------------
~:{Decayed}:~
http://www.q3seek.com
Dhirendra123
February 24th, 2000, 09:04 PM
It seems to me that you already got the logic and code for your requirement.
What kind of help you want?
I would suggest that go ahead and complete the code and test it. You already solved your problem.
Lothar Haensler
February 25th, 2000, 01:30 AM
your code:
textbox.seltext = "<" & tag & " " & additionalstuff & ">"
' and on the end of the text it would add
textbox.seltext = "</" & tag & ">"
in your second line you overwrite the seltext property.
shouldn't it rather look like:
dim strText as string
strText = "<" & tag & " " & additionalstuff & ">"
strText = strText & "</" & tag & ">"
textbox.seltext = strText
Nick A.
February 25th, 2000, 02:15 AM
Lothar's code is probably what you need, but you say you want to wrap HTML tags around the selected part of the textbox. Try this little refinement in Lothar's code (i hope you don't mind Lothar):
dim strText as string
strText = textbox.seltext
strText = "<" & tag & " " & additionalstuff & ">" & strText
strText = strText & "</" & tag & ">"
textbox.seltext = strText
Cakkie
February 25th, 2000, 02:38 AM
I just want to make 1 note, you are using a function, this returns a value, in your code you use call wrapTags("HEAD", "bgcolor='black'", "frmMDI.ActiveForm.Text1"), this returns a value, wich you do not assing to a variable, this will give an error. In your function, you also don't set the value the function returns, my advice is to change your funtion into a sub, so your code would be:
public sub wrapTags(tag, additionalstuff, textbox)
' Tag is the HTML tag we want to wrap around selected text
' on the start of the selected text it would add
textbox.seltext = "<" & tag & " " & additionalstuff & ">"
' and on the end of the text it would add
textbox.seltext = "</" & tag & ">"
end sub
' when calling, omit the braces ()
call wrapTags text1.seltext, "bgcolor='black'", "frmMDI.ActiveForm.Text1"
or.. you can use it as a function, and your code would look like this
public function wrapTags(tag, additionalstuff)
' Tag is the HTML tag we want to wrap around selected text
' on the start of the selected text it would add
' I left textbox out of the function
wrapTags = "<" & tag & " " & additionalstuff & ">"
' and on the end of the text it would add
wrapTags = "</" & tag & ">"
end function
' the call would then be
text1.seltext = wrapTags(text1.seltext, "bgcolor='black')
Tom Cannaerts
slisse@planetinternet.be
The best way to escape a problem, is to solve it.
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.