CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Feb 2000
    Posts
    18

    Please help me with this function!!

    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

  2. #2
    Join Date
    Dec 1999
    Posts
    20

    Re: Please help me with this function!!

    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.


  3. #3
    Join Date
    May 1999
    Posts
    3,332

    Re: Please help me with this function!!

    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


  4. #4
    Join Date
    Dec 1999
    Posts
    128

    Re: Please help me with this function!!

    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




    -------------------------
    Nick A.

  5. #5
    Join Date
    Jan 2000
    Location
    Olen, Belgium
    Posts
    2,477

    Re: Please help me with this function!!

    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
    [email protected]

    The best way to escape a problem, is to solve it.
    Tom Cannaerts
    email: [email protected]
    www.tom.be (dutch site)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured