[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

I neeed a VB script to format text in scrolling text box before submiting (URGENT)

Posted on 2004-10-27
14
Medium Priority
?
389 Views
Last Modified: 2008-02-01
I have an HTML form below.
I want to format the text in it before submitting to database. An example witten in  "VB"  is here just to have an idea what I'm trying to do
I need this is "VBScript" only.
A working Code is what I need and will be appreciated


'=========================================================================
' Name:  FormatRemarks
'
' Notes:    This function formats raw text into CRLF dilimited lines(s)
'=========================================================================
Public Function FormatRemarks(ByVal in_strRemarks As String, ByVal in_intLimit As Integer) As String
  'On Error GoTo checkerr
 
  Dim i             As Integer
  Dim strLastChr    As String
  Dim strText()     As String
  Dim intLineCount  As Integer
  Dim intPos        As Integer
  Dim strNewText    As String


  intLineCount = LineCount(in_strRemarks)
 
  ' Determine if the last char is a carriage return/line feed
  If Right(in_strRemarks, 1) = vbLf Then
    If Mid(in_strRemarks, Len(in_strRemarks) - 1, 1) = vbCr Then
      strLastChr = vbCrLf
    Else
      strLastChr = vbLf
    End If
  ElseIf Right(in_strRemarks, 1) = vbCr Then
    strLastChr = vbCr
  End If
 
  ' Redefine the upper bound of the array according to the number of lines
  ReDim strText(1 To intLineCount)
 
  ' Loop thru the remarks and parse it into lines of text
  For i = 1 To intLineCount
    ' Get the position of the carriage return character
    intPos = InStr(1, in_strRemarks, vbCr, vbTextCompare)
   
    Select Case intPos
      Case 0 ' No carriage return char, remarks consist of 1 line of text
        strText(i) = in_strRemarks
        in_strRemarks = ""
      Case 1 ' The line start out with the carriage return character
        strText(i) = ""
      Case Else
        strText(i) = Left(in_strRemarks, intPos - 1)
    End Select
   
    If in_strRemarks <> "" Then
      ' Check if the next character is the line feed character
      If Mid(in_strRemarks, intPos + 1, 1) = vbLf Then
        in_strRemarks = Mid(in_strRemarks, intPos + 2)
      Else
        in_strRemarks = Mid(in_strRemarks, intPos + 1)
      End If
    End If
  Next

Thanks



<html>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>New Page 1</title>
</head>

<body>

<form method="POST" action="save.aspx--">
  <p><textarea rows="2" name="S1" cols="20">Text to format Text to formatText to format Text to format Text to format Text to format Text to format Text to format Text to format Text to format Text to format Text to format Text to format Text to format Text to format</textarea></p>
  <p><input type="button" value="Format" name="B3"><input type="submit" value="Submit" name="B1"><input type="reset" value="Reset" name="B2"></p>
</form>

</body>

</html>
0
Comment
Question by:iyiola
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 3
  • 3
  • +1
14 Comments
 
LVL 23

Expert Comment

by:apresto
ID: 12424429
what exactly do you want the format button to do?
0
 

Author Comment

by:iyiola
ID: 12424601
Hi apresto


When the format button is clicked.  I want to call a function to do the following:

I want the text to "wrap"  or put a page break at 50th characted.

If the text is less than 50 character, then do nothing
If text is very long, eeach line must wrap (page break) at 50th character
Thanks
0
 
LVL 23

Expert Comment

by:apresto
ID: 12424667
this COuLD Work:

If Len(Request.Form("textarea")) >= 50 Then
    response.write "<BR><BR>"
End If

I was looking around and this Len thing did the job for some others?
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 23

Expert Comment

by:apresto
ID: 12424677
If Len(Request.Form("S1")) >= 50 Then
    response.write "<BR><BR>"
End If

forgot to change it, this will need to be in the page that the info is submitted to
0
 

Author Comment

by:iyiola
ID: 12424698
This will not work for me.
I need this to be a function.The onlick event of teh Format button will call the function and format the text
0
 
LVL 19

Expert Comment

by:peh803
ID: 12425610
@iyiola:

I would like to understand your requirements better.  You say that you'd like this data handled before you insert it into your database, right?  Well, consider a 200 character string where every 50th character falls in the middle of a word.  Is this acceptable?  Do you still want to break to a new line at this point exactly, or do you want to go to the closest space?

Also, do you want line breaks for textarea / plain text email display purposes (vbCfLf) or for HTML display purposes (<BR>)?

Thanks,
peh803
0
 
LVL 15

Expert Comment

by:Thogek
ID: 12425634
If you need the formatting to occur before submitting, then it's happening client-side, right?  Any reason why it has to be VBScript, then?  (Especially given that JavaScript is better supported across different browsers.)
0
 
LVL 15

Expert Comment

by:Thogek
ID: 12425658
Question:
What if there are already line-breaks within the textarea?  Do you want to leave those alone, and just restart your line-wrap formatting with eaach new line/paragraph?
0
 

Author Comment

by:iyiola
ID: 12425836
Hi peh803
Yes I would like it handled before inserting into database. I'm more concerned about formating than the database part.
Yes it acceptable to have the characted fall in the middle given teh example of 200 characted string.
It's just the requirement
This is not for email purpose, just readability by users instead of scolling. That's the purpose
Will appreciate your help.
I need this in VBScript. A working code is much appreciated
0
 

Author Comment

by:iyiola
ID: 12425865
Hi Thogek,
Yes I need this in VB Script. If you have a solution in Javascript, it's better than nothing though.
The line-wrap formating function should overide the line -breaks within the textarea
0
 
LVL 15

Accepted Solution

by:
Thogek earned 2000 total points
ID: 12426109
Here's one quick pass:

    <script language="VBScript">
    Function FormatTextArea(ByVal oTextArea)
        Dim strText, strFormatText
        strText = Replace(oTextArea.innerText, vbCrLf, " ")
        strFormatText = ""
        While Len(strText) > 50
            strFormatText = strFormatText & Left(strText, 50) & vbCrLf
            strText = Right(strText, Len(strText) - 50)
        WEnd
        strFormatText = strFormatText & strText
        oTextArea.innerText = strFormatText
    End Function
    </script>

    <form>
    <textarea rows="2" name="S1" cols="60"></textarea><br />
    <input type="button" value="Format" language="VBScript" onclick="FormatTextArea(me.form.S1)" />
    </form>

Noting, of course, that being in VBScript, this will not work in Netscape (or most other non-IE) browsers.
0
 
LVL 19

Expert Comment

by:peh803
ID: 12426151
@iyiola,

it appears that thogek has posted a good solution for you.  I am more than happy to help, however; so please just let me know if you need more help.  Obviously, if thogek's solution works for you, no need to post extraneous stuff.

regards,
peh803
0
 

Author Comment

by:iyiola
ID: 12426279
Thanks for the effort  peh803. I may eb back.
I will accept Thogek answer. It works
Thanks Thogek
0
 
LVL 19

Expert Comment

by:peh803
ID: 12426326
You're welcome iyiola -- I'm glad you got an answer that works for you.

Regards,
peh803
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Hello, all! I just recently started using Microsoft's IIS 7.5 within Windows 7, as I just downloaded and installed the 90 day trial of Windows 7. (Got to love Microsoft for allowing 90 days) The main reason for downloading and testing Windows 7 is t…
This demonstration started out as a follow up to some recently posted questions on the subject of logging in: http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28634665.html and http://www.experts-exchange.com/Programming/…
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…

656 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question