ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Test for NULL string? (https://www.excelbanter.com/excel-programming/438491-test-null-string.html)

Robert Crandal

Test for NULL string?
 
I have the following function:

Function Foo (ByVal myData as String)
' Do stuff
End Foo

My question is, do I need to test if the "myData"
parameter is null or invalid?? How can I best
test the parater if it's valid or null or not??
(so i can avoid any errors)

thankx


Mike H

Test for NULL string?
 
Robert,

Maybe this

Function Foo(ByVal myData As String)
If myData = vbNullString Then
Foo = "No string passed to function"
Exit Function
End If
' Do stuff
End Function

Mike
--
Mike

When competing hypotheses are equal, adopt the hypothesis that introduces
the fewest assumptions while still sufficiently answering the question.
Occam''''s razor (Abbrev)


"Robert Crandal" wrote:

I have the following function:

Function Foo (ByVal myData as String)
' Do stuff
End Foo

My question is, do I need to test if the "myData"
parameter is null or invalid?? How can I best
test the parater if it's valid or null or not??
(so i can avoid any errors)

thankx

.


Mike H

Test for NULL string?
 
Robert,

I missed the 'invalid' bit but you don't tell us what 'invalid' means. Maybe
you mean a number?

Function Foo(ByVal myData As String)
If myData = vbNullString Or IsNumeric(myData) Then
Foo = "No string passed to function"
Exit Function
End If
' Do stuff
End Function
--
Mike

When competing hypotheses are equal, adopt the hypothesis that introduces
the fewest assumptions while still sufficiently answering the question.
Occam''''s razor (Abbrev)


"Robert Crandal" wrote:

I have the following function:

Function Foo (ByVal myData as String)
' Do stuff
End Foo

My question is, do I need to test if the "myData"
parameter is null or invalid?? How can I best
test the parater if it's valid or null or not??
(so i can avoid any errors)

thankx

.


Robert Crandal

Test for NULL string?
 
My bad....

I was just looking for instances in which "no string" or a NULL
value is passed to the function. I'm thinking that the
"If myData = vbNullString" will be sufficient enough.

BTW, I'm a long time C++ programmer, so I developed a
habit of doing a lot of NULL error testing. VBA seems to
be more "type safe" when it comes to null strings, so I
kinda get the impression that I don't need to always check
for NULL strings, but I still wanted to know how to do it
anyways.

Thanks for the info.


"Mike H" wrote in message
...
Robert,

I missed the 'invalid' bit but you don't tell us what 'invalid' means.
Maybe
you mean a number?

Function Foo(ByVal myData As String)
If myData = vbNullString Or IsNumeric(myData) Then
Foo = "No string passed to function"
Exit Function
End If
' Do stuff
End Function
--




All times are GMT +1. The time now is 07:26 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com