count amount of string.

radek225

Registered User.
Local time
Today, 11:02
Joined
Apr 4, 2013
Messages
307
In form (datasheet) I have a three columns "RightColors", "LeftColors" and "AmountOfColors"

I want to do something like this:

If I fill 'RightColors' "red;green;blue;", and fill 'LeftColors' "orange;" then in 'AmountOfColors' column should be "4". Sometimes I can fill only 'RighColors' or 'LeftColors;

I think I should add code in after update event. Is this possible to build code which can count colors using ";"? I need loop for this, right?
 
Last edited:
you can use the split function to create an array and then use UBound to determine the number of elements


Code:
Function CountElements(S as String) as Long
Dim Sarr() as String
 
    if s="" then
         CountOfElements=0
    else
        Sarr=split(s,";")
        CountOfElements=unbound(Sarr)
    end if
 
End Function

And then to use

Code:
NoOfColours=CountofElements(RightColours)+CountofElements(LeftColours)

Or you could use

Code:
NoOfColours=CountofElements(RightColours & LeftColours)

I note you have a ; at the end of each string so you may need to modify the function to account for this.
 
Thanks! It's really helpful for me
 

Users who are viewing this thread

Back
Top Bottom