Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Select Case | Excel Discussion (Misc queries) | |||
Case without Select Case error problem | Excel Discussion (Misc queries) | |||
End Select without Select Case, Block If without End If errors | Excel Programming | |||
Select Case | Excel Programming |