|
-
Jul 9th, 2003, 12:42 PM
#1
Passing nulls to a function...How?
I have an app that pulls data from a database. The data is then passed to a function that manipulates it and returns it as string. The returns from the database could be just about any date type and Nulls are possible. The problem is the code that calls the function can’t be changed to check for nulls. I have set up the function to accept a string as a parameter. This works for everything except nulls. Short of using a variant as the parameter, is there any other way to deal with these nulls?
-
Jul 9th, 2003, 12:44 PM
#2
Why not check for Null before calling the function, then replace it with ""? If you can't alter the function, I don't see what other choice you have. Of course, you could replace it with something other than an empty string, but you pretty much have to replace it with something.
-
Jul 9th, 2003, 12:49 PM
#3
The data that is being pulled is coming from a compiled dll. I can make it work passing it to a variant and then deal with nulls from there. I was just hoping for something better.
-
Jul 9th, 2003, 12:54 PM
#4
Sorry, I realize that I misread your post. You were clear, and I was confused.
I expect that you're hosed on this. Since a Null is a typeless thing, I doubt that you can use anything but a variant. If it was a number, that would be easier, but I believe it is defined as typeless.
-
Jul 9th, 2003, 02:53 PM
#5
Hyperactive Member
str = rec.Fields("whatever")
If IsNull(str) Then str = ""
-
Jul 9th, 2003, 02:59 PM
#6
Yeah, that was my original idea. However, if you re-read his posts, you will realize that he never gets that option.
-
Jul 9th, 2003, 03:10 PM
#7
The picture isn't missing
StrPtr would return 0 on a null string:
Private Sub Command1_Click()
SomeSub vbNullString
End Sub
Sub SomeSub (b As String)
MsgBox StrPtr(b) 'returns 0
End Sub
Remember, if someone's post was not helpful, you can always rate their post negatively  .
-
Jul 9th, 2003, 06:01 PM
#8
Originally posted by BuggyProgrammer
StrPtr would return 0 on a null string:
Private Sub Command1_Click()
SomeSub vbNullString
End Sub
Sub SomeSub (b As String)
MsgBox StrPtr(b) 'returns 0
End Sub
Unfortunately the db returns Null instead of vbNullString. With the code below you see that you never get out of the call procedure.
VB Code:
Option Explicit
Private Sub Command1_Click()
MsgBox SomeSub(Null)
End Sub
Private Function SomeSub(b As String) As String
MsgBox StrPtr(b) 'returns 0
End Function
-
Jul 9th, 2003, 06:09 PM
#9
Why avoid the variant? It makes it much simpler when having to deal with a source you can't change...
VB Code:
Private Sub Command1_Click()
MsgBox Func(Null)
End Sub
Private Function Func(ByVal v As Variant) As String
Func = v & ""
End Function
Tada, no more Null.
Laugh, and the world laughs with you. Cry, and you just water down your vodka.
Take credit, not responsibility
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|