PDA

View Full Version : concat a variable with a string



lexluther88
11-10-2006, 09:01 PM
I'm trying to make a message box appear that says

title "Wrong Magic Words" and message "<words> are not the magic words." where <words> is actually what the user typed in. (Hint: You'll need to concatenate a variable with a string.)

I defined what the user typed in as the magic words as the following:

Const strMAGICCODE = "Trick Or Treat"
Dim strMAGICDODE As String
Dim strCODESTORAGE As String
strCODESTORAGE = InputBox("Enter the magic words", "User Validation")
If strMAGICCODE = strCODESTORAGE Then
ToggleButtons True

Else

MsgBox = Concat("strCODESTORAGE" & "Are not the magic words"), vbOKOnly, "Wrong Magic Words"

End If

..I get an error though in the Concat section saying that a sub or function isn't defined..
am I supposed to use strMAGICCODE..or strCODESTORAGE? Or am I supposed to set another variable or maybe a cell to hold the value that the user types in?

please help

jindon
11-10-2006, 10:53 PM
Hi
Just try


MsgBox (strCODESTORAGE & "Are not the magic words", vbOKOnly, "Wrong Magic Words")

johnske
11-10-2006, 10:57 PM
Sub trythis()

Const strMAGICCODE As String = "Trick Or Treat"
Dim strCODESTORAGE As String

strCODESTORAGE = InputBox("Enter the magic words", "User Validation")

If strCODESTORAGE = strMAGICCODE Then
ToggleButtons True
Else
MsgBox (strCODESTORAGE & " Are not the magic words"), vbOKOnly, "Wrong Magic Words"
End If

End Sub

Bob Phillips
11-11-2006, 03:24 AM
...

MsgBox = Concat("strCODESTORAGE" & "Are not the magic words"), vbOKOnly, "Wrong Magic Words"

...


..I get an error though in the Concat section saying that a sub or function isn't defined..
am I supposed to use strMAGICCODE..or strCODESTORAGE? Or am I supposed to set another variable or maybe a cell to hold the value that the user types in?

CONCAT is a (superfluous) worksheet function. In VBA, just use the & operator.

And you don't use =, that again is worksheet stuff.



MsgBox "strCODESTORAGE" & "Are not the magic words", vbOKOnly, "Wrong Magic Words"

lexluther88
11-11-2006, 04:22 PM
Thanks!! For both taking the time to help and for the code working as well. Johnske's code was perfect, it even had the space between what the user typed and "Are not the magic words"
Thanks again.