Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 499
  • Last Modified:

storing bold text into Database

I have a notes section in a VB form in which , the user can enter the text and there is a bold button so that user can make part of texts bold which r important . And the entire content is stored in a field "content" in Access database .i want to store the text with the bold parts so that when i reload the notes section the user sees the notes with the parts he had made bold , exactly with the changes he had made .

Now i'm thinking of only one way to store the "Selstart" and "sellength" of the rich edit text box as soon as the user selects a portion of notes and make it bold , like i'll hold 2 more fields in DB called SelStart and SelLength  where i store the nos. of the bold sections , Like if the user first chooses text whose selstart is 5 and length is 20 , then another section he makes bold whose selstart is 30 and lenth is 15 , so i store 5,30,...so on (all the Selstarts ) in "SelStart" field in DB and then 20,15... so on in "SelLength" field in DB , and when i reload the VB notes form , i get these values and then split them and take 5 for first bold sections SelStart and 20 As its lengtyh adn make this bold and then i pick up 30 and its length 15 and make it bold and so on.

Is this the proper way , i mean will it not be clumsya nd leangthy ?? Can anyone tell me is there any easier way of storing a text with few sections bold , italics and all in database .
Thanks
anamika
0
anamika1977
Asked:
anamika1977
  • 2
  • 2
  • 2
  • +1
1 Solution
 
elvinsohCommented:
Why not use Tags in your text -- like HTML.
So you only store :

This word will be <B>BOLD</B> but not the rest.<I> This whole sentence is in Italics.</I> Normal Text again.

Then you can write a function to parse all the text and display it appropriately without the overhead of additional database programming.

And here is the code for Formatting RichText :
(I DO NOT TAKE CREDIT FOR WRITING THIS CODE.)
<Cut and Paste into a Module>




Public Sub FormatRTF(ByRef txtRTF As RichTextBox)
On Error Resume Next


    Screen.MousePointer = vbHourglass
   
   

   Dim i As Integer
   
   Dim strTags() As Variant
   
   Dim iLength As Integer
   Dim strValue As String
   Dim iStart As Integer
   Dim iEnd As Integer
   Dim strStartTag As String
   Dim strEndTag As String
   Dim iStartTag As Integer
   Dim iEndTag As Integer
   Dim iLenST As Integer
   Dim iCount As Integer
   
   Static iFrame As Integer
   Dim iFCount As Integer
   
   With txtRTF
           
      '-- Look For Font Tags
      strStartTag = "<FONT="
      strEndTag = "</FONT>"
      iStart = InStr(1, .Text, strStartTag)
      iCount = 0
     
      Do While iStart > 0

         iLenST = Len(strStartTag)
         iEndTag = Len(strEndTag)
         
         iStart = InStr(1, .Text, strStartTag)
         
         If iStart = 0 Then Exit Do

         iEnd = InStr(iStart, .Text, strEndTag)

         strValue = Mid(.Text, (iStart + iLenST), InStr((iStart + iLenST), .Text, ">") - (iStart + iLenST))

         iStartTag = Len(strStartTag & strValue & ">")

         iLength = iEnd - iStartTag - iStart
         
         .SelStart = iEnd - 1
         .SelLength = iEndTag
         .SelText = ""
         
         .SelStart = iStart - 1
         .SelLength = iStartTag
         .SelText = ""

         .SelStart = iStart - 1
         .SelLength = iLength
         .SelFontName = strValue
         
         iCount = iCount + 1
         
            If iCount Mod 3 = 0 Then
                iFrame = iFrame + 1
           
                If iFrame > 5 Then iFrame = 1
           
               
                DoEvents
           
            End If
         
         If iCount > 300 Then Exit Do
         
         
         frmMain.ShowProgress frmMain.pbText.Value + 300 / Len(txtRTF.Text)
         
      Loop

      '-- Look For Font Size Tags
      strStartTag = "<SIZE="
      strEndTag = "</SIZE>"
      iStart = InStr(1, .Text, strStartTag)
      iCount = 0
     
      Do While iStart > 0

         iLenST = Len(strStartTag)
         iEndTag = Len(strEndTag)
         
         iStart = InStr(1, .Text, strStartTag)
         
         If iStart = 0 Then Exit Do

         iEnd = InStr(iStart, .Text, strEndTag)

         strValue = Mid(.Text, (iStart + iLenST), InStr((iStart + iLenST), .Text, ">") - (iStart + iLenST))

         iStartTag = Len(strStartTag & strValue & ">")

         iLength = iEnd - iStartTag - iStart
         
         .TextRTF = Replace(.TextRTF, strStartTag & strValue & ">", "", , 1)
         .TextRTF = Replace(.TextRTF, strEndTag, "", , 1)

         .SelStart = iStart - 1
         .SelLength = iLength
         .SelFontSize = CInt(strValue)
         
         iCount = iCount + 1
   
            If iCount Mod 3 = 0 Then
                iFrame = iFrame + 1
           
                If iFrame > 5 Then iFrame = 1
           
               
                DoEvents
           
           
            End If
   
        frmMain.ShowProgress frmMain.pbText.Value + 300 / Len(txtRTF.Text)
   
         If iCount > 300 Then Exit Do
         
         
      Loop
     
      '-- Font Colors
      strStartTag = "<COLOR="
      strEndTag = "</COLOR>"
      iStart = InStr(1, .Text, strStartTag)
      iCount = 0
     
      Do While iStart > 0
     
         iLenST = Len(strStartTag)
         iEndTag = Len(strEndTag)
         
         iStart = InStr(1, .Text, strStartTag)
         
         If iStart = 0 Then Exit Do

         iEnd = InStr(iStart, .Text, strEndTag)

         strValue = Mid(.Text, (iStart + iLenST), InStr((iStart + iLenST), .Text, ">") - (iStart + iLenST))

         iStartTag = Len(strStartTag & strValue & ">")

         iLength = iEnd - iStartTag - iStart
         
         .TextRTF = Replace(.TextRTF, strStartTag & strValue & ">", "", , 1)
         .TextRTF = Replace(.TextRTF, strEndTag, "", , 1)

         .SelStart = iStart - 1
         .SelLength = iLength
         .SelColor = CLng(strValue)
         
         iCount = iCount + 1
         
            If iCount Mod 3 = 0 Then
                iFrame = iFrame + 1
           
                If iFrame > 5 Then iFrame = 1
           
               
    DoEvents
           
            End If

         frmMain.ShowProgress frmMain.pbText.Value + 300 / Len(txtRTF.Text)
         
         
         If iCount > 300 Then Exit Do
         
      Loop
     
      '-- Alignment
      strStartTag = "<ALIGN="
      strEndTag = "</ALIGN>"
      iStart = InStr(1, .Text, strStartTag)
      iCount = 0
     
      Do While iStart > 0
     
         iLenST = Len(strStartTag)
         iEndTag = Len(strEndTag)
         
         iStart = InStr(1, .Text, strStartTag)
         
         If iStart = 0 Then Exit Do

         iEnd = InStr(iStart, .Text, strEndTag)

         strValue = Mid(.Text, (iStart + iLenST), InStr((iStart + iLenST), .Text, ">") - (iStart + iLenST))

         iStartTag = Len(strStartTag & strValue & ">")

         iLength = iEnd - iStartTag - iStart
         
         .TextRTF = Replace(.TextRTF, strStartTag & strValue & ">", "", , 1)
         .TextRTF = Replace(.TextRTF, strEndTag, "", , 1)

         .SelStart = iStart - 1
         .SelLength = iLength
         
         Select Case UCase(strValue)
            Case "LEFT"
               .SelAlignment = rtfLeft
            Case "RIGHT"
               .SelAlignment = rtfRight
            Case "CENTER"
               .SelAlignment = rtfCenter
         End Select
         
         iCount = iCount + 1
         
            If iCount Mod 3 = 0 Then
                iFrame = iFrame + 1
           
                If iFrame > 5 Then iFrame = 1
           
               
            End If

            frmMain.ShowProgress frmMain.pbText.Value + 300 / Len(txtRTF.Text)

         If iCount > 300 Then Exit Do
         
      Loop
     
      '-- All Others
     
      ReDim strTags(4)
      strTags(1) = "B"
      strTags(2) = "U"
      strTags(3) = "I"
      strTags(4) = "STRIKE"
      strTags(5) = "BULLET"
     
      For i = LBound(strTags) To UBound(strTags)
     
         strStartTag = "<" & strTags(i) & ">"
         strEndTag = "</" & strTags(i) & ">"
         iStart = InStr(1, .Text, strStartTag)
         iCount = 0
         
         Do While iStart > 0
   
            iLenST = Len(strStartTag)
            iEndTag = Len(strEndTag)
           
            iStart = InStr(1, .Text, strStartTag)
           
            If iStart = 0 Then Exit Do
   
            iEnd = InStr(iStart, .Text, strEndTag)
   
            iStartTag = Len(strStartTag)
   
            iLength = iEnd - iStartTag - iStart
           
            .TextRTF = Replace(.TextRTF, strStartTag, "", , 1)
            .TextRTF = Replace(.TextRTF, strEndTag, "", , 1)
   
            .SelStart = iStart - 1
            .SelLength = iLength
           
            If i = 1 Then
               .SelBold = True
            ElseIf i = 2 Then
               .SelUnderline = True
            ElseIf i = 3 Then
               .SelItalic = True
            ElseIf i = 4 Then
               .SelStrikeThru = True
            ElseIf i = 5 Then
               .SelBullet = True
            End If
           
            iCount = iCount + 1
           
            If iCount Mod 3 = 0 Then
                iFrame = iFrame + 1
           
                If iFrame > 5 Then iFrame = 1
           
               
            DoEvents
           
            End If

            frmMain.ShowProgress frmMain.pbText.Value + 3000 / Len(txtRTF.Text)

            If iCount > 300 Then Exit Do
           
           
         Loop
           
      Next
       
      .SelStart = 0
       
   End With
   
   
   
    DoEvents

  Screen.MousePointer = 0
 
   
End Sub

Public Function TrimNulls(strString As String) As String
   
   Dim l As Long
   
   l = InStr(1, strString, Chr(0))
   
   If l = 1 Then
      TrimNulls = ""
   ElseIf l > 0 Then
      TrimNulls = Left$(strString, l - 1)
   Else
      TrimNulls = strString
   End If
   
End Function




0
 
MadmarlinCommented:
I dont think it is possible to actually store the text in the DB in Bold.
Although a little trick, I think elvinsoh has the best idea.
The only other way around I can think of is set some form a flag in the db to state whether or not the text is bold, the read that flag when reading the data back into you app.
However this will restrict you to having all of the text in that field either Bold or Not Bold..\

Good Luck Madmarlin
0
 
anamika1977Author Commented:
Hi elvinsoh how can i use html tags in my notes section ?? Sorry i didn't get u what u r saying . Like in my case when my VB form loads it will show the notes which r like "asfafsdgasdgfdhgf" and the user makes a pert of it bold and saves it to DB . Then how can i convert this simple text to text with html tags . Do u want to say that i'll insert tags where its bold and then save to DB and while retrieving i'll take out the tags and show . Can u please explain me how your programs work ???and what r utrying to put
thabka
anamika
0
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.

 
elvinsohCommented:
Ok. Here goes:

You have this text in your RichText :

"The quick brown fox jumps over the lazy dogs."

Now, the user selects "quick brown" and hits [BOLD]

YOU have to get SelStart, SelEnd and Add "<B>" and "</B>" to the text so that it reads :

"The <B>quick brown</B> fox jumps over the lazy dogs."

Run the FORMATRTF() function I've given you above and it'll do the rest.

===========================================================
You can store the string AS IT IS and every time you
dump it into a RichText Box and run FORMATRTF() on it,
you'll get it nicely formatted.

===========================================================
IF you want to get the TEXT back without the tags you put in, it's rather simple. Put the text (with the tags) into
a RichText Box, Run FORMATRTF() and get the RICHTEXT.TEXT

===========================================================

Here is a list of some of the tags the function supports :

<B> Start BOLD Text           </B> End BOLD Text
<I> Start Italics             </I> End Italics
<U> Start Underline           </U> End Underline

<FONT= fontName> will set font face. End with </FONT>.
<SIZE= n> will set font size. End with </FONT>.
<COLOR= hexn> will set font color - hexn is a hexadecimal RGB value. End with </COLOR>
<ALIGN= param> where param = LEFT ; RIGHT ; CENTER
This will set the alignment of your text. End with </ALIGN>


Have fun.
0
 
anamika1977Author Commented:
Hi Elvinsoh what is this frmMain.ShowProgress function u have called inside FormatRTF ???
Can u provide me with that function otherwise i'm not able to use your code
0
 
MoondancerCommented:
ADMINISTRATION WILL BE CONTACTING YOU SHORTLY.  Moderators Computer101, Netminder or Mindphaser will return to finalize these if they are still open in 7 days.  Experts, please post closing recommendations before that time.

Below are your open questions as of today.  Questions which have been inactive for 21 days or longer are considered to be abandoned and for those, your options are:
1. Accept a Comment As Answer (use the button next to the Expert's name).
2. Close the question if the information was not useful to you, but may help others. You must tell the participants why you wish to do this, and allow for Expert response.  This choice will include a refund to you, and will move this question to our PAQ (Previously Asked Question) database.  If you found information outside this question thread, please add it.
3. Ask Community Support to help split points between participating experts, or just comment here with details and we'll respond with the process.
4. Delete the question (if it has no potential value for others).
   --> Post comments for expert of your intention to delete and why
   --> YOU CANNOT DELETE A QUESTION with comments; special handling by a Moderator is required.

For special handling needs, please post a zero point question in the link below and include the URL (question QID/link) that it regards with details.
http://www.experts-exchange.com/jsp/qList.jsp?ta=commspt
 
Please click this link for Help Desk, Guidelines/Member Agreement and the Question/Answer process.  http://www.experts-exchange.com/jsp/cmtyHelpDesk.jsp

Click you Member Profile to view your question history and please keep them updated. If you are a KnowledgePro user, use the Power Search option to find them.  

Questions which are LOCKED with a Proposed Answer but do not help you, should be rejected with comments added.  When you grade the question less than an A, please comment as to why.  This helps all involved, as well as others who may access this item in the future.  PLEASE DO NOT AWARD POINTS TO ME.

To view your open questions, please click the following link(s) and keep them all current with updates.
http://www.experts-exchange.com/questions/Q.20258034.html
http://www.experts-exchange.com/questions/Q.20281103.html
http://www.experts-exchange.com/questions/Q.20291660.html
http://www.experts-exchange.com/questions/Q.20294799.html
http://www.experts-exchange.com/questions/Q.20297870.html
http://www.experts-exchange.com/questions/Q.20298607.html
http://www.experts-exchange.com/questions/Q.20299135.html

To view your locked questions, please click the following link(s) and evaluate the proposed answer.
http://www.experts-exchange.com/questions/Q.20286827.html

*****  E X P E R T S    P L E A S E  ******  Leave your closing recommendations.
If you are interested in the cleanup effort, please click this link
http://www.experts-exchange.com/jsp/qManageQuestion.jsp?ta=commspt&qid=20274643 
POINTS FOR EXPERTS awaiting comments are listed in the link below
http://www.experts-exchange.com/commspt/Q.20277028.html
 
Moderators will finalize this question if in @7 days Asker has not responded.  This will be moved to the PAQ (Previously Asked Questions) at zero points, deleted or awarded.
 
Thanks everyone.
Moondancer
Moderator @ Experts Exchange
0
 
MoondancerCommented:
Zero response from anyone, and finalized.
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

  • 2
  • 2
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now