CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5

Thread: TEXTAREA

  1. #1
    Join Date
    Feb 2000
    Location
    Ohio
    Posts
    31

    TEXTAREA

    Hello Everyone;
    I am writing an ASP file with TEXTAREA control, what I am trying to do, is to have fixed width for the textarea control and variable height depending on the number of text lines in the control. i.e. I don't want to scroll to see all the text in the TEXTAREA control.


  2. #2
    Join Date
    Jan 2000
    Location
    MO, USA
    Posts
    1,506

    Re: TEXTAREA

    then before you supply the textarea's rows property, yuo can determine this by dividing the length of the text to be entered by the number of cols to be used in the text box and add one, or round up essentially. something like this might work:

    dim icol
    dim sreturn

    'stext is the actual text that is to be placed in the textarea box. i assume you are hardcoding the
    'width of the textarea, for example, lets say 60

    icol = len(stext)/60
    'we need the whole number value, so just take the left of the result up until the decimal
    'since this number is rounded down, we need to increment it by one, so that it simulates
    'a rounding up
    icol = left((icol, instr(1,icol,".")-1) + 1

    sreturn = "<textarea cols=60 rows=" & icol & ">" & stext & "</textarea>"

    response.write sreturn




    hope this helps,

    John

    John Pirkey
    MCSD
    http://www.ShallowWaterSystems.com
    http://www.stlvbug.org
    John Pirkey
    MCSD (VB6)
    http://www.stlvbug.org

  3. #3
    Join Date
    Feb 2000
    Location
    Ohio
    Posts
    31

    Re: TEXTAREA

    This is not going to work, because the text wrap is turned on, so the line could contain 60 charactors of may be 10; since we have to consider the carriage return and long words toward the end of the line


  4. #4
    Join Date
    Jan 2000
    Location
    MO, USA
    Posts
    1,506

    Re: TEXTAREA

    for the carriage returns, do a search in the string for "vbCrLf" and add the number that comes back to the number of rows. for the long words that are to be wrapped - just add a larger number on the end. without parsing each resulting line of text, this is as good as your going to get.


    dim icol
    dim sreturn
    dim icount

    'stext is the actual text that is to be placed in the textarea box. i assume you are hardcoding the
    'width of the textarea, for example, lets say 60

    icol = len(stext)/60
    'we need the whole number value, so just take the left of the result up until the decimal
    'since this number is rounded down, we need to increment it by one, so that it simulates
    'a rounding up
    icol = left((icol, instr(1,icol,".")-1) + 1

    'add the number of carriage returns in the text. and a little extra for long words at end of line
    icount = UBound(split(stext,vbcrlf))
    icol = icol + icount + 10

    sreturn = "<textarea cols=60 rows=" & icol & ">" & stext & "</textarea>"

    response.write sreturn





    that's as far as i'm going with this - and you're welcome.

    John

    John Pirkey
    MCSD
    http://www.ShallowWaterSystems.com
    http://www.stlvbug.org
    John Pirkey
    MCSD (VB6)
    http://www.stlvbug.org

  5. #5
    Join Date
    Feb 2000
    Location
    Ohio
    Posts
    31

    Re: TEXTAREA

    I will try that.
    Thank you very much.


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