Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 204
Default What Variable-type should I use

A simple question - I think. I often use a variable to contain the response
from a MessageBox, I always declare it as a variant - is that necessary? In
help, the responses are always integers between 0 and 64, can I use an
Integer (or even a Byte) variable type, or are there some surprise responses
in certain circumstances. I want to be sure that this will not generate an
error.

This is how I'd normally do it...

Dim Again As Variant

' Check that the user wants to start again
Again = MsgBox(" Do you want to start again?", vbQuestion + vbYesNo)


Is there a better way

M

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 449
Default What Variable-type should I use

Most of "those things" are Long. A byte would sometimes be too small.
Integers are internally translated to Long, so don't use them.

Best wishes Harald

"Michelle" wrote in message
...
A simple question - I think. I often use a variable to contain the response
from a MessageBox, I always declare it as a variant - is that necessary?
In help, the responses are always integers between 0 and 64, can I use an
Integer (or even a Byte) variable type, or are there some surprise
responses in certain circumstances. I want to be sure that this will not
generate an error.

This is how I'd normally do it...

Dim Again As Variant

' Check that the user wants to start again
Again = MsgBox(" Do you want to start again?", vbQuestion +
vbYesNo)


Is there a better way

M


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 75
Default What Variable-type should I use

A MsgBox will always return a Long result. What's more you can use some
constants to check the user's response. For example

If MsgBox("Please choose Yes Or No",vbQuestion+vbYesNo)=vbYes Then
'User chose Yes
Else
'User chose No
End If

--
Alan Moseley IT Consultancy
http://www.amitc.co.uk

If I have solved your problem, please click Yes below. Thanks.


"Michelle" wrote:

A simple question - I think. I often use a variable to contain the response
from a MessageBox, I always declare it as a variant - is that necessary? In
help, the responses are always integers between 0 and 64, can I use an
Integer (or even a Byte) variable type, or are there some surprise responses
in certain circumstances. I want to be sure that this will not generate an
error.

This is how I'd normally do it...

Dim Again As Variant

' Check that the user wants to start again
Again = MsgBox(" Do you want to start again?", vbQuestion + vbYesNo)


Is there a better way

M

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default What Variable-type should I use

The best way is to declare the result variable as a VbMsgBox type.
That's the way VBA sees it internally and you get intellisense support
to boot.

Dim Res As VbMsgBoxResult
Res = MsgBox("Question", vbYesNo)
If Res = vbYes Then
' do something
Else
' do something else
End If

Cordially,
Chip Pearson
Microsoft Most Valuable Professional
Excel Product Group, 1998 - 2009
Pearson Software Consulting, LLC
www.cpearson.com
(email on web site)



On Wed, 4 Feb 2009 12:16:50 -0000, "Michelle"
wrote:

A simple question - I think. I often use a variable to contain the response
from a MessageBox, I always declare it as a variant - is that necessary? In
help, the responses are always integers between 0 and 64, can I use an
Integer (or even a Byte) variable type, or are there some surprise responses
in certain circumstances. I want to be sure that this will not generate an
error.

This is how I'd normally do it...

Dim Again As Variant

' Check that the user wants to start again
Again = MsgBox(" Do you want to start again?", vbQuestion + vbYesNo)


Is there a better way

M

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
change variable type [email protected] Excel Programming 1 December 24th 08 04:34 PM
Variable type Alan Beban[_2_] Excel Programming 2 September 17th 07 06:13 PM
Type of variable J@Y Excel Programming 3 August 14th 07 04:14 PM
Variable type Confusion D Zandveld Excel Programming 2 March 5th 07 09:07 AM
type variable as argument of a sub Koos Excel Programming 1 October 23rd 03 11:41 AM


All times are GMT +1. The time now is 06:20 PM.

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

About Us

"It's about Microsoft Excel"