Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
show input box info in a message box
hi all,
I have a program with an input box requiring the user to type in their name. I then need to insert this name in a message box along with some text that will remain embedded or 'standard'. for instance; THANK YOU (USERNAME) FOR TAKING PART IN THIS SURVEY. I have set up the input box and the msgbox but am at a loss as to how to acheive the above. any help you could provide would be greatly apprecitated. |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
show input box info in a message box
UserName = InputBox (blah blah blah)
MsgBox("Thank You " & username & " for taking part in this survey") Make sure you have a blank before and after the &. I've found that I get errors because there's no blank. HTH, Barb Reinhardt "sevi61" wrote: hi all, I have a program with an input box requiring the user to type in their name. I then need to insert this name in a message box along with some text that will remain embedded or 'standard'. for instance; THANK YOU (USERNAME) FOR TAKING PART IN THIS SURVEY. I have set up the input box and the msgbox but am at a loss as to how to acheive the above. any help you could provide would be greatly apprecitated. |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
show input box info in a message box
UserName = InputBox (blah blah blah)
MsgBox("Thank You " & username & " for taking part in this survey") Make sure you have a blank before and after the &. I've found that I get errors because there's no blank. You only need to provide a space between the variable name and the ampersand (&) following it. The reason has to do with VB being backward compatible, syntax-wise, with older VB's and even the DOS versions of BASIC that preceded it. In the "old days", you could specify a variable's data type by using suffix characters attached to the end of the variable's name. The ampersand character happens to be one of those suffix characters. Placing an ampersand at the end of a variable's name makes the variable a Long data type... the others being percent sign (%) for Integer, exclamation mark (!) for Single, pound sign (#) for Double, dollar sign ($) for String and, although the data type is "newer", the at sign (@) for Currency. Anyway, VB's problem comes from its considering the second ampersand in this string (no space between it and the variable name in front of it)... MsgBox "Thank You "&UserName&" for taking part in this survey" to be the Long data type suffix character meaning there is no concatenation symbol for the variable and the text following it. I know, it should be able to figure out that UserName contains a String value so that it can't be a Long, but it can't. Anyway, you can see this in action by putting in the ampersand that VB is missing. MsgBox "Thank You "&UserName&&" for taking part in this survey" The above string of text will not raise an error when the above MsgBox statement is typed in; instead, the automatic spacing that VB does will take place around the second ampersand once the statement is committed. Now, of course, you will get a type-declaration error when you attempt to actually run this code because UserName is (presumably) Dim'med as a String and the concatenation of a declared Long variable and a String is improper. Anyway, that is the 'why' of the error you mentioned. Rick |
#4
Posted to microsoft.public.excel.programming
|
|||
|
|||
show input box info in a message box
thank you both very much, you have been informative, cleared my query up and
helped immensely. kindest regards "Rick Rothstein (MVP - VB)" wrote: UserName = InputBox (blah blah blah) MsgBox("Thank You " & username & " for taking part in this survey") Make sure you have a blank before and after the &. I've found that I get errors because there's no blank. You only need to provide a space between the variable name and the ampersand (&) following it. The reason has to do with VB being backward compatible, syntax-wise, with older VB's and even the DOS versions of BASIC that preceded it. In the "old days", you could specify a variable's data type by using suffix characters attached to the end of the variable's name. The ampersand character happens to be one of those suffix characters. Placing an ampersand at the end of a variable's name makes the variable a Long data type... the others being percent sign (%) for Integer, exclamation mark (!) for Single, pound sign (#) for Double, dollar sign ($) for String and, although the data type is "newer", the at sign (@) for Currency. Anyway, VB's problem comes from its considering the second ampersand in this string (no space between it and the variable name in front of it)... MsgBox "Thank You "&UserName&" for taking part in this survey" to be the Long data type suffix character meaning there is no concatenation symbol for the variable and the text following it. I know, it should be able to figure out that UserName contains a String value so that it can't be a Long, but it can't. Anyway, you can see this in action by putting in the ampersand that VB is missing. MsgBox "Thank You "&UserName&&" for taking part in this survey" The above string of text will not raise an error when the above MsgBox statement is typed in; instead, the automatic spacing that VB does will take place around the second ampersand once the statement is committed. Now, of course, you will get a type-declaration error when you attempt to actually run this code because UserName is (presumably) Dim'med as a String and the concatenation of a declared Long variable and a String is improper. Anyway, that is the 'why' of the error you mentioned. Rick |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
show the input message of a data validation list on a textbox and set editable | Excel Discussion (Misc queries) | |||
need help w/ macro prompting with info and pasting the info based on user input | Excel Programming | |||
Example of input or msg box requesting TWO pieces of info? | Excel Programming | |||
how do i make one chart that my ees can input info, and have a se. | Excel Worksheet Functions | |||
input message | Excel Programming |