Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
J@Y J@Y is offline
external usenet poster
 
Posts: 127
Default Select Case with Nothing

I am trying to test multiple variables to see if they have been assigned
nothing.

I tried:

Select Case Nothing

but seems you can't use Nothing like you use True/False.
How would I about this problem?
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 857
Default Select Case with Nothing

I'm not exactly sure if this is what you're looking for but take a look at
the code below.


Sub test()
Dim a As Object
Dim b As Object

Set a = New Collection
'Set b = New Collection

Select Case True
Case IsNothing(a)
MsgBox "a is nothing"
Case IsNothing(b)
MsgBox "b is nothing"
Case Else
MsgBox "No uninitialized objects!"
End Select

End Sub

Public Function IsNothing(o As Object) As Boolean
IsNothing = o Is Nothing
End Function





--
Hope that helps.

Vergel Adriano


"J@Y" wrote:

I am trying to test multiple variables to see if they have been assigned
nothing.

I tried:

Select Case Nothing

but seems you can't use Nothing like you use True/False.
How would I about this problem?

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,202
Default Select Case with Nothing

I am trying to test multiple variables to see if they have been assigned
nothing.

I tried:

Select Case Nothing

but seems you can't use Nothing like you use True/False.
How would I about this problem?


What is the data type of the variables you are trying to check? If they are
a numeric data type, VB automatically assigns 0 (in the appropriate data
type) to them at their creation, so you can't test whether a value has been
assigned to them or not. If they are Strings, then they start life as a
NullString and you can test for this using

If YourStringVariable = vbNullString Then...

If the are Variants, you can test if anything has been assigned to it using
the IsEmpty function, like this

If IsEmpty(YourVariantVariable) Then...

Rick

  #4   Report Post  
Posted to microsoft.public.excel.programming
J@Y J@Y is offline
external usenet poster
 
Posts: 127
Default Select Case with Nothing

My variables are range variables.
I set them using something like:

Set DataRange = Range("a1", "c1")

I know they can be assigned nothing because I can use

If Not DataRange Is Nothing Then

to test each individual variable


"Rick Rothstein (MVP - VB)" wrote:

I am trying to test multiple variables to see if they have been assigned
nothing.

I tried:

Select Case Nothing

but seems you can't use Nothing like you use True/False.
How would I about this problem?


What is the data type of the variables you are trying to check? If they are
a numeric data type, VB automatically assigns 0 (in the appropriate data
type) to them at their creation, so you can't test whether a value has been
assigned to them or not. If they are Strings, then they start life as a
NullString and you can test for this using

If YourStringVariable = vbNullString Then...

If the are Variants, you can test if anything has been assigned to it using
the IsEmpty function, like this

If IsEmpty(YourVariantVariable) Then...

Rick


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,202
Default Select Case with Nothing

Okay, so if I understand you correctly, you are trying to test whether
DataRange is pointing to a range or not. And, for some reason, you want to
use a Select Case instead of the If-Then test you already know how to do. I
don't think you can do it that way. Well, I guess you could do this...

Select Case True
Case DataRange Is Nothing
......
Case Else
......
End Select

but, personally, I hate using True that way... when you do, the Case
statements are really nothing more than If-Then-Else blocks, so you might as
well use If-Then-Else.

Rick



"J@Y" wrote in message
...
My variables are range variables.
I set them using something like:

Set DataRange = Range("a1", "c1")

I know they can be assigned nothing because I can use

If Not DataRange Is Nothing Then

to test each individual variable


"Rick Rothstein (MVP - VB)" wrote:

I am trying to test multiple variables to see if they have been assigned
nothing.

I tried:

Select Case Nothing

but seems you can't use Nothing like you use True/False.
How would I about this problem?


What is the data type of the variables you are trying to check? If they
are
a numeric data type, VB automatically assigns 0 (in the appropriate data
type) to them at their creation, so you can't test whether a value has
been
assigned to them or not. If they are Strings, then they start life as a
NullString and you can test for this using

If YourStringVariable = vbNullString Then...

If the are Variants, you can test if anything has been assigned to it
using
the IsEmpty function, like this

If IsEmpty(YourVariantVariable) Then...

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
Select Case jlclyde Excel Discussion (Misc queries) 5 January 6th 09 09:05 PM
Case without Select Case error problem Ayo Excel Discussion (Misc queries) 2 May 16th 08 03:48 PM
End Select without Select Case, Block If without End If errors Atreides Excel Programming 12 November 17th 06 05:10 PM
Select Case Marcotte A[_3_] Excel Programming 5 June 10th 04 04:05 PM


All times are GMT +1. The time now is 12:57 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"