What does " " & mean?

Kryst51

Singin' in the Hou. Rain
Local time
Yesterday, 20:33
Joined
Jun 29, 2009
Messages
1,896
I see this code in a lot of examples I look at, I don't know what it means, so it is hard to query it to find out as symbols are not very queryable.

ex: Debug.Print "Printer name: " & .DeviceName & Printer driver: " & _ .Driver Name

Not knowing keeps me from being able to understand what coding is actually doing.
 
" " & basically separates hard-coded items from variables, and joins them together.

ex: Debug.Print "Printer name: " & .DeviceName & Printer driver: " & _ .Driver Name

Debug.Print "Printer name: " between the quotes is some hard-coded text. whatever is typed in there comes out 'as-is'.

& will connect what came before it to what comes after it - it concatenates the two.

.DeviceName is a property of some object (that object is not included in the example). it does not have to be in quotes.

another quick ex. if you have first and last names in a table and want to join them:

PersonFName & " " & PersonLName

& " " & will put a space between the two values of first name and last name - the space is hard-coded.
 
I see this code in a lot of examples I look at, I don't know what it means, so it is hard to query it to find out as symbols are not very queryable.

ex: Debug.Print "Printer name: " & .DeviceName & "Printer driver: " & _ .Driver Name

Not knowing keeps me from being able to understand what coding is actually doing.

In essence what this code is intended to do is display the name of the current printer and printer driver in the immediate window during debug mode. I also believe that there may be a quote missing in the location that I have indicated.
 
In your example, the quotes are around literal text:

"Printer name: "

the ampersand (&) concatenates that with a value that must be interpreted (a form reference, variable, etc), in this case:

.DeviceName

There is what I assume is a typo in that, as I suspect it should be (I took out the line continuation to simplify):

Debug.Print "Printer name: " & .DeviceName & " Printer driver: " & .Driver Name


which in might actually print out something like

Printer name: LaserJet Printer driver: DriverName
 
Geez, do I type slow or what? :p
 
Geez, do I type slow or what? :p
Go to voice recognition (although if you are in an area where you can't speak openly, it could be a problem :D )
 
i really thought i would come back and find a few responses before mine!
i figure we've covered it. :)
 
Thanks so much! I have used cocatenation in my queries, but didn't recognize it in vba, a senior moment as my granparents would tell me. It was driving me nuts, not understanding.
 

Users who are viewing this thread

Back
Top Bottom