By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,101 Members | 1,463 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,101 IT Pros & Developers. It's quick & easy.

Convert IsMissing, IsNull, VBempty to vb.net

P: n/a
I now converting vb6 code to vb.net code

Let me descrip my problem first

i got a Function e.g.

Public Function Method1(Byval ar as object, Optional ByVal strWHFrom As
String, Optional ByVal strWHTo As String) as string
........
If IsMissing(strWHFrom) And IsMissing(strWHTo) Then
strSql = "............"
ElseIf IsMissing(strWHFrom) And Not IsMissing(strWHTo) Then
strSql = "............"
ElseIf Not IsMissing(strWHFrom ) And IsMissing(strWHTo) Then
strSql = "............."
Else
If IsNull(strWHFrom ) And IsNull(strWHTo) Then
strSql = "................"
ElseIf Len(strWHFrom )=0 And len(strWHTo)=0 Then
strSql = "..............."
Else
If Trim$(strWHFrom ) = Trim$(strWHTo) Then
strSql = "............."
Else
strSql = "............."
End If
End If
End If
End Funciton

This function work well in vb6

But How I going to code this with vb.net, vb.net seem like cant
differentciate the parameter got pass in or not. and also how to
convert the IsNull

Is it mean that I must put some SPEACIAL default value to the Optional
Parameter to detect that particular parameter got pass in or not?

Thank you

Mar 30 '06 #1
Share this Question
Share on Google+
4 Replies


P: n/a
The function is now IsDBNull

For optional parameters AFAIK a default value is now required (making
IsMissing not needed any more).
--
Patrice

<br******@gmail.com> a écrit dans le message de news:
11**********************@i39g2000cwa.googlegroups. com...
I now converting vb6 code to vb.net code

Let me descrip my problem first

i got a Function e.g.

Public Function Method1(Byval ar as object, Optional ByVal strWHFrom As
String, Optional ByVal strWHTo As String) as string
.......
If IsMissing(strWHFrom) And IsMissing(strWHTo) Then
strSql = "............"
ElseIf IsMissing(strWHFrom) And Not IsMissing(strWHTo) Then
strSql = "............"
ElseIf Not IsMissing(strWHFrom ) And IsMissing(strWHTo) Then
strSql = "............."
Else
If IsNull(strWHFrom ) And IsNull(strWHTo) Then
strSql = "................"
ElseIf Len(strWHFrom )=0 And len(strWHTo)=0 Then
strSql = "..............."
Else
If Trim$(strWHFrom ) = Trim$(strWHTo) Then
strSql = "............."
Else
strSql = "............."
End If
End If
End If
End Funciton

This function work well in vb6

But How I going to code this with vb.net, vb.net seem like cant
differentciate the parameter got pass in or not. and also how to
convert the IsNull

Is it mean that I must put some SPEACIAL default value to the Optional
Parameter to detect that particular parameter got pass in or not?

Thank you

Mar 30 '06 #2

P: n/a
You could record it as (note the default values for the optional
parameters):

Public Function Method1(Byval ar as object, Optional ByVal strWHFrom As
String = String.Empty, Optional ByVal strWHTo As String = String.Empty) As
String
....
If strWHFrom Is String.Empty AndAlso strWHTo Is String.Empty Then
strSql = "............"
ElseIf strWHFrom Is String.Empty Then
strSql = "............"
ElseIf strWHTo Is String.Empty Then
strSql = "............."
Else
If strWHFrom.Trim = strWHTo.Trim Then
strSql = "............."
Else
strSql = "............."
End If
End Function

or you could create overloaded methods instead:

Public Function Method1(Byval ar as object) As String

Return Method1(ar, String.Empty, String.Empty)

End Function

Public Function Method1(Byval ar as object, ByVal strWHFrom As String) As
String

Return Method1(ar, strWHFrom, String.Empty)

End Function

Public Function Method1(Byval ar as object, ByVal strWHFrom As String,
ByVal strWHTo As String) As String
....
If strWHFrom Is String.Empty AndAlso strWHTo Is String.Empty Then
strSql = "............"
ElseIf strWHFrom Is String.Empty Then
strSql = "............"
ElseIf strWHTo Is String.Empty Then
strSql = "............."
Else
If strWHFrom.Trim = strWHTo.Trim Then
strSql = "............."
Else
strSql = "............."
End If
End Function
<br******@gmail.com> wrote in message
news:11**********************@i39g2000cwa.googlegr oups.com...
I now converting vb6 code to vb.net code

Let me descrip my problem first

i got a Function e.g.

Public Function Method1(Byval ar as object, Optional ByVal strWHFrom As
String, Optional ByVal strWHTo As String) as string
.......
If IsMissing(strWHFrom) And IsMissing(strWHTo) Then
strSql = "............"
ElseIf IsMissing(strWHFrom) And Not IsMissing(strWHTo) Then
strSql = "............"
ElseIf Not IsMissing(strWHFrom ) And IsMissing(strWHTo) Then
strSql = "............."
Else
If IsNull(strWHFrom ) And IsNull(strWHTo) Then
strSql = "................"
ElseIf Len(strWHFrom )=0 And len(strWHTo)=0 Then
strSql = "..............."
Else
If Trim$(strWHFrom ) = Trim$(strWHTo) Then
strSql = "............."
Else
strSql = "............."
End If
End If
End If
End Funciton

This function work well in vb6

But How I going to code this with vb.net, vb.net seem like cant
differentciate the parameter got pass in or not. and also how to
convert the IsNull

Is it mean that I must put some SPEACIAL default value to the Optional
Parameter to detect that particular parameter got pass in or not?

Thank you

Mar 30 '06 #3

P: n/a
Stephany,

Thanks for reply

For my case, it is not a good way to solve this problem by using the
overloaded method, cause I will have more that 2 optional parameter.

At first I am so happy that you provided a solution of i never think
before
Public Function Method1(Byval ar as object, Optional ByVal strWHFrom
As
String = String.Empty, Optional ByVal strWHTo As String =
String.Empty) As
String

But, after i tried, I found that an optional variable MUST assign with
a constant value, and the String.Empty make the program fail. Too
bad.....cause if this can work, this can be a very good solution

Anyway, if really dont have any better solution for this case, I think
I have to follow Patrice way(set a special default value to detact)

Thank you

Mar 31 '06 #4

P: n/a
Sorry, I keep forgetting that String.Empty is not actually a constant.

Use:

Public Function Method1(Byval ar as object, Optional ByVal strWHFrom As
String = "", Optional ByVal strWHTo As String = "") As String

instead.

<br******@gmail.com> wrote in message
news:11********************@u72g2000cwu.googlegrou ps.com...
Stephany,

Thanks for reply

For my case, it is not a good way to solve this problem by using the
overloaded method, cause I will have more that 2 optional parameter.

At first I am so happy that you provided a solution of i never think
before
Public Function Method1(Byval ar as object, Optional ByVal strWHFrom
As
String = String.Empty, Optional ByVal strWHTo As String =
String.Empty) As
String

But, after i tried, I found that an optional variable MUST assign with
a constant value, and the String.Empty make the program fail. Too
bad.....cause if this can work, this can be a very good solution

Anyway, if really dont have any better solution for this case, I think
I have to follow Patrice way(set a special default value to detact)

Thank you

Mar 31 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.