Creating a string

Nevy

Registered User.
Local time
Yesterday, 19:12
Joined
May 31, 2005
Messages
31
Well it's not really specific to VBA, it's more to programming.
Sometimes, I have more trouble with what looks simple...

I want to create a string of the type: "=(A+B+C+D)"

A,B,C and D are optional, meaning the user can select whichever they want using checkboxes.

Here's a simplified version of what I've done. The problem is that at the beginning, I'm stuck with an extra +.

Any ideas on how to do it properly?

Code:
   str = "=("
    If A Then
        str = str + " + A"
    End If
    If B Then
        str = str + " + B"
    End If
    If C Then
        str = str + " + C"
    End If
    If D Then
        str = str + " + D"
    End If
    str = str + " )"

    'An example of an output: =(+A+C) but I want: =(A+C)
 
Code:
str = "=("
    If A Then
        str = str & "A +"
    End If
    If B Then
        str = str & "B +"
    End If
    If C Then
        str = str & "C + "
    End If
    If D Then
        str = str & "D + "
    End If
    str = Left(str, Len(str) - 3) & " )"
 
Code:
str = "=("
    If A Then
        str = str & "A+"
    End If
    If B Then
        str = str & "B+"
    End If
    If C Then
        str = str & "C+"
    End If
    If D Then
        str = str & "D+"
    End If
    str = Left(str, Len(str) - 1) & ")"

:D
 

Users who are viewing this thread

Back
Top Bottom