Results 1 to 4 of 4

Thread: [RESOLVED] 3 label 9 condition?

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Mar 2005
    Posts
    2,942

    Resolved [RESOLVED] 3 label 9 condition?

    How to...

    i have 3 label and i want to combine all possible combinations wath is the right way?

    the condition is:

    1&#176 all label have caption =blank or empty
    2&#176 labe1 caption is filled label2 caption is filled label3 caption is no blank
    3&#176 label1 caption is balnk label2 caption ecc...
    ...
    9&#176...

    i think the combination are 9 (3*3) or not?

    case selcet? or...
    Last edited by luca90; Apr 21st, 2009 at 02:42 PM.

  2. #2
    PowerPoster
    Join Date
    Oct 2002
    Location
    British Columbia
    Posts
    9,758

    Re: 3 label 9 condition?

    If each Caption is to be separated by a single space this statement is all you need.

    str = Trim$(Trim$(Trim$(Label1.Caption) & " " & Trim$(Label2.Caption)) & " " & Trim$(Label3.Caption))

  3. #3
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649

    Re: 3 label 9 condition?

    No you have 8 combinations. A label is either empty or not so it only have two states and you have 3 labels which gives 2^3 = 8 combinations.

    If you don't care what the text in the labels read but only want to check if the Caption is empty or not you can convert these states into numbers from 0 to 7.
    0 = All three labels are blank
    1 = Label1 contains text, the others are empty.
    2 = Label2 contains text, the others are empty.
    3 = Label1 and Label2 contains text while Label3 is empty.
    4 = Label3 contains text, the others are empty.
    5 = Label3 and Label1 contains text while Label2 is empty.
    6 = Label3 and Label2 contains text while Label1 is empty.
    7 = All labels contains text.

    You can easily get these numbers by saying that Label1 have the value 1 if it contains text, Label2 have the value 2, while Label3 have the value 4 (binary). If a label doesn't contain text it has the value 0.
    Code:
    Dim value As Integer
    value = IIf(Label1.Caption <> "", 1, 0)
    value = value + IIf(Label2.Caption <> "", 2, 0)
    value = value + IIf(Label3.Caption <> "", 4, 0)
    Using the code above "value" will be something between 0 and 7. Now use a Select Case and do whatever.

  4. #4
    PowerPoster Spoo's Avatar
    Join Date
    Nov 2008
    Location
    Right Coast
    Posts
    2,656

    Re: 3 label 9 condition?

    Joacim

    Very nicely presented (the cases 0 - 7)

    Spoo

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