Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 13
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,355
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,202
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 13
Default 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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
show the input message of a data validation list on a textbox and set editable HCS7 Excel Discussion (Misc queries) 3 November 20th 08 11:43 AM
need help w/ macro prompting with info and pasting the info based on user input drgka55 Excel Programming 8 August 28th 06 06:05 PM
Example of input or msg box requesting TWO pieces of info? StargateFan[_3_] Excel Programming 2 March 25th 06 06:06 PM
how do i make one chart that my ees can input info, and have a se. Marina Excel Worksheet Functions 0 April 1st 05 03:25 AM
input message tamersaid Excel Programming 1 June 6th 04 02:06 PM


All times are GMT +1. The time now is 08:23 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"