Results 1 to 2 of 2

Thread: [RESOLVED] Extract R,G and B value from a string in format "R,G,B"

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2012
    Posts
    290

    Resolved [RESOLVED] Extract R,G and B value from a string in format "R,G,B"

    I've a string of this format:
    R,G,B where R/G/B are integer

    I want to get each value without the "," symbol.
    Example: 134,45,31
    134
    45
    31

    R/G/B are integer values that can vary from 0 to 255.

    I'm usind the Mid function but I don't get to break it in its 3 components.

    I'm trying:
    Code:
    Dim Line as String
    Dim R as Byte, G as Byte, B as Byte
    Dim ValueComplete as Boolean
    Dim FirstSymbol as String, SecondSymbol as String
    Dim I as Integer
    
    ValueComplete = False
    Line = "134,45,31"
    
    For I = 1 to Len(Line)
       If(Mid(Line), I, 1) <> "," And ValueComplete = False Then 
            R = R & (Mid(Line), I, 1)
       Else
            ValueComplete = True
       End if
    Next I
    The code it's incomplete and I've tried different ways.
    Someone knows how to correctly write it?

  2. #2
    PowerPoster
    Join Date
    Aug 2010
    Location
    Canada
    Posts
    2,451

    Re: Extract R,G and B value from a string in format "R,G,B"

    You can use the Split function on the "," character to get a zero-based array with one colour value per element. e.g.

    Code:
       Dim la_Rgb() as String
    
       la_Rgb = Split("134,45,31", ",")
       ' Now Red = la_Rgb(0), Green = la_Rgb(1), Blue = la_Rgb(2)

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