Results 1 to 11 of 11

Thread: [RESOLVED] Converting Text to a Long Value

  1. #1

    Thread Starter
    Giants World Champs!!!! Mark Gambo's Avatar
    Join Date
    Sep 2003
    Location
    Colorado
    Posts
    2,965

    Resolved [RESOLVED] Converting Text to a Long Value

    I would like to know if it is possible to convert the following strings types into
    a long type:

    vbRed convert to 255
    vbBlue convert 16711680
    vbGreen convert 65280
    vbYellow convert 65535

    I tried but it converts the vbRed value to 118:

    VB Code:
    1. Dim lngTest as Long
    2. lngtest = CLng(Asc("vbRed"))

    Thanks!
    Regards,

    Mark

    Please remember to rate posts! Rate any post you find helpful. Use the link to the left - "Rate this Post". Please use [highlight='vb'] your code goes in here [/highlight] tags when posting code. When a question you asked has been resolved, please go to the top of the original post and click "Thread Tools" then select "Mark Thread Resolved."


  2. #2
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    Re: Converting Text to a Long Value

    VB Code:
    1. Dim lngTest as Long
    2. lngtest = CLng(vbRed)

  3. #3
    eltiT resU motsuC Static's Avatar
    Join Date
    Oct 2000
    Location
    Rochester, NY
    Posts
    9,390

    Re: Converting Text to a Long Value

    this: Asc("vbRed") converts to Ascii code... (Letter to Number) and since it cant do multiple it converts v to 118 (Chr(118) = v)

    but.. u do NOT need to convert those to longs they are already Long Values

    Click on the word vbRed or vbWhite etc.. in the VB IDE then right click & pick definition
    the object browser will appear showing all the ColorConstants in the VB IDE

    so all you need to do is:

    Dim lngTest as Long
    lngtest = vbRed


    (If I am incorrect on this.. please tell me )
    JPnyc rocks!! (Just ask him!)
    If u have your answer please go to the thread tools and click "Mark Thread Resolved"

  4. #4

    Thread Starter
    Giants World Champs!!!! Mark Gambo's Avatar
    Join Date
    Sep 2003
    Location
    Colorado
    Posts
    2,965

    Re: Converting Text to a Long Value

    Thanks for the quick responses!

    Here is my problem I have a string value as follows:


    VB Code:
    1. Dim strText as String
    2. dim lngColor as Long
    3.  
    4. strText = "<Color=vbRed>The quick brown fox</Color=vbRed>"
    5. lngColor = Mid(strText,8, 6)

    I want to be able to parse out the color and then convert it to a long so that I can use it to color text in a Richtextbox.
    Regards,

    Mark

    Please remember to rate posts! Rate any post you find helpful. Use the link to the left - "Rate this Post". Please use [highlight='vb'] your code goes in here [/highlight] tags when posting code. When a question you asked has been resolved, please go to the top of the original post and click "Thread Tools" then select "Mark Thread Resolved."


  5. #5
    eltiT resU motsuC Static's Avatar
    Join Date
    Oct 2000
    Location
    Rochester, NY
    Posts
    9,390

    Re: Converting Text to a Long Value

    like this?

    strtext = "<Color=vbRed>The quick brown fox</Color=vbRed>"
    strtext = Replace(strtext, "vbRed", vbRed)
    JPnyc rocks!! (Just ask him!)
    If u have your answer please go to the thread tools and click "Mark Thread Resolved"

  6. #6
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: Converting Text to a Long Value

    This might do what you want. You can also use the rtb.Find method.
    It assumes that it is going at the top of he rtb.

    VB Code:
    1. Option Explicit
    2.  
    3. Private Sub Form_Load()
    4. Dim strText As String
    5. Dim lngColor As Long
    6.  
    7.   strText = "<Color=vbRed>The quick brown fox</Color=vbRed>"
    8.   lngColor = Mid(strText, 8, 6)
    9.  
    10.   rtb.SelStart = InStr(1, strText, ">") + 1 ' plus wherever you want it
    11.   rtb.SelLen InStr(rtb.SelStart, "<") - rtb.SelStart
    12.   rtb.SelColor lngColor
    13. End Sub

  7. #7

    Thread Starter
    Giants World Champs!!!! Mark Gambo's Avatar
    Join Date
    Sep 2003
    Location
    Colorado
    Posts
    2,965

    Re: Converting Text to a Long Value

    My code is more like this:


    VB Code:
    1. strText strText = "<B><U><FontName="Arial><FontSize=12><Color=vbRed>The quick brown fox" & _
    2.           </Color=vbRed></B></U></FontSize=12></FontName="Arial>"

    But thanks, you just gave me a great idea
    Regards,

    Mark

    Please remember to rate posts! Rate any post you find helpful. Use the link to the left - "Rate this Post". Please use [highlight='vb'] your code goes in here [/highlight] tags when posting code. When a question you asked has been resolved, please go to the top of the original post and click "Thread Tools" then select "Mark Thread Resolved."


  8. #8
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: Converting Text to a Long Value

    Post back if you have any problems. I was torn between two different ways to do it, and ended up writing this was last.

  9. #9

    Thread Starter
    Giants World Champs!!!! Mark Gambo's Avatar
    Join Date
    Sep 2003
    Location
    Colorado
    Posts
    2,965

    Re: Converting Text to a Long Value

    Quote Originally Posted by dglienna
    Post back if you have any problems. I was torn between two different ways to do it, and ended up writing this was last.

    No it is working great now thanks again to the idea!
    Regards,

    Mark

    Please remember to rate posts! Rate any post you find helpful. Use the link to the left - "Rate this Post". Please use [highlight='vb'] your code goes in here [/highlight] tags when posting code. When a question you asked has been resolved, please go to the top of the original post and click "Thread Tools" then select "Mark Thread Resolved."


  10. #10
    Admodistrator |2eM!x's Avatar
    Join Date
    Jan 2005
    Posts
    3,900

    Re: [RESOLVED] Converting Text to a Long Value

    Can we get a small sample mark? For future reference..?

  11. #11

    Thread Starter
    Giants World Champs!!!! Mark Gambo's Avatar
    Join Date
    Sep 2003
    Location
    Colorado
    Posts
    2,965

    Re: [RESOLVED] Converting Text to a Long Value

    Quote Originally Posted by |2eM!x
    Can we get a small sample mark? For future reference..?
    I wanted to write a function that would format text in a RichText Box for a Calender control I was working on and I needed an easy way to indicate the color that I wanted to use other that using the Hex equivalent. I decided to use a collection to hold the values. I am using the String variable (ie. "vbRed") as the key, here is my code:

    VB Code:
    1. Option Explicit
    2. Dim Colors As New Collection
    3.  
    4. Private Sub Command1_Click()
    5.         With RichTextBox1
    6.             .Visible = False 'Hide RTB to Prevents Flickering
    7.             .Text = "" 'Clears previous text and formating
    8.            
    9.             .Text = "<B><U><FontName=Arial><FontSize=12>" & _
    10.                               "<Color=Red>The</U></B> </Color=Red></FontSize=12>" & _
    11.                               "<Color=Blue><B><FontSize=16>quick</FontSize=16> " & _
    12.                               "</Color=Blue><Color=Brown></B><I><FontSize=18> brown" & _
    13.                               "</FontSize=18></I></Color=Brown><Color=Purple> fox" & _
    14.                               "</Color=Purple></Color=Red></B></FontName=Arial>" & _
    15.                               vbNewLine & vbNewLine & vbNewLine & _
    16.                               "<Left><B>Left</B></Left>" & vbNewLine & _
    17.                               "<Center><B>Center</B></Center>" & vbNewLine & _
    18.                               "<Right><B>Right</B></Right>"
    19.            
    20.             Call RichTextBoxFormat(RichTextBox1)
    21.             .Visible = True
    22.         End With
    23. End Sub
    24.  
    25. Private Sub Form_Load()
    26.     With Colors 'Collection for Colors
    27.         .Add vbRed, "Red"
    28.         .Add vbBlue, "Blue"
    29.         .Add vbGreen, "Green"
    30.         .Add vbYellow, "Yellow"
    31.         .Add &H80FF&, "Orange"
    32.         .Add vbWhite, "White"
    33.         .Add vbBlack, "Black"
    34.         .Add &HC0C000, "LtBlue"
    35.         .Add &HFF00FF, "Purple"
    36.         .Add &H404080, "Brown"
    37.     End With
    38. End Sub
    39.  
    40. Private Sub RichTextBoxFormat(RTB As RichTextBox)
    41. Dim lngTag_Start As Long
    42. Dim lngTag_End As Integer
    43. Dim strTag_Start As String
    44. Dim strTag_End As String
    45. Dim strText As String
    46. Dim a As Long
    47.  
    48. For a = 1 To 31
    49.     strTag_Start = "<" & Choose(a, "B", "I", "U", "Center", "Left", _
    50.                                     "Right", "Color=Red", "Color=Blue", _
    51.                                     "Color=Green", "Color=Yellow", _
    52.                                     "Color=Orange", "Color=White", _
    53.                                     "Color=Black", "Color=LtBlue", _
    54.                                     "Color=Purple", "Color=Brown", _
    55.                                     "FontSize=8", "FontSize=10", "FontSize=12", _
    56.                                     "FontSize=14", "FontSize=16", "FontSize=18", _
    57.                                     "FontSize=20", "FontSize=22", "FontSize=24", _
    58.                                     "FontName=Arial", "FontName=Arial Black", _
    59.                                     "FontName=Comic Sans MS", _
    60.                                     "FontName=French Script MT", _
    61.                                     "FontName=Lucida Console", _
    62.                                     "FontName=Old English Text", _
    63.                                     "FontName=New Times Roman", _
    64.                                     "FontName=EAN-13", "FontName=UPCA", _
    65.                                     "FontName=UPCA", "FontName=UPC-E Short", _
    66.                                     "FontName=3 of 9 Barcode") & ">"
    67.                                        
    68.     strTag_End = "</" & Mid(strTag_Start, 2)
    69.    
    70.     lngTag_End = 1
    71.  
    72.     With RTB
    73.         strText = .Text
    74.        
    75.         Do While InStr(lngTag_End, strText, strTag_Start) > 0
    76.             'Loops through the text to find each tag
    77.            
    78.             .SelLength = 0
    79.             lngTag_Start = InStr(lngTag_End, strText, strTag_Start)
    80.             lngTag_End = InStr(lngTag_Start, strText, strTag_End)
    81.             .SelStart = lngTag_Start + Len(strTag_Start) - 1
    82.             .SelLength = ((lngTag_End - lngTag_Start) - Len(strTag_End)) + 1
    83.  
    84.             Select Case strTag_Start 'Formats the text based upon tag
    85.                 Case "<B>"  'Bold Text
    86.                     .SelBold = True
    87.                 Case "<I>"  'Italic Text
    88.                     .SelItalic = True
    89.                 Case "<U>"  'Underline Text
    90.                     .SelUnderline = True
    91.                 Case "<Center>" 'Center Align Text
    92.                     .SelAlignment = rtfCenter
    93.                 Case "<Left>"   'Left Align Text
    94.                     .SelAlignment = rtfLeft
    95.                 Case "<Right>"  'Right Align Text
    96.                     .SelAlignment = rtfRight
    97.                 Case Else
    98.                     If InStr(strTag_Start, "Color") > 0 Then 'Colors Text
    99.                         .SelColor = Colors.Item((Mid(strTag_Start, 8, Len(strTag_Start) - 8)))
    100.                     ElseIf InStr(strTag_Start, "FontSize") > 0 Then 'Font Size
    101.                         .SelFontSize = (Mid(strTag_Start, 11, Len(strTag_Start) - 11))
    102.                     ElseIf InStr(strTag_Start, "FontName") > 0 Then 'Font Name
    103.                         .SelFontName = (Mid(strTag_Start, 11, Len(strTag_Start) - 11))
    104.                     End If
    105.             End Select
    106.        
    107.             lngTag_End = lngTag_End + 1
    108.         Loop    'Check text for additional tags
    109.  
    110.         'Removes the Tags from the RichTextBox
    111.         Do While .Find(strTag_Start, 0) <> -1
    112.             .SelText = ""
    113.         Loop
    114.        
    115.         Do While .Find(strTag_End, 0) <> -1
    116.             .SelText = ""
    117.         Loop
    118.         .SelStart = 1
    119.     End With
    120. Next a
    121. End Sub

    Thanks to all that helped me with this code! Here is a link to my original post regarding RichTextBoxes and Tags.

    A picture of the Calendar Form:

    Last edited by Mark Gambo; Nov 30th, 2005 at 07:53 AM.
    Regards,

    Mark

    Please remember to rate posts! Rate any post you find helpful. Use the link to the left - "Rate this Post". Please use [highlight='vb'] your code goes in here [/highlight] tags when posting code. When a question you asked has been resolved, please go to the top of the original post and click "Thread Tools" then select "Mark Thread Resolved."


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