473,396 Members | 1,816 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Convert IsMissing, IsNull, VBempty to vb.net

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
4 12287
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: DiggidyMack69 | last post by:
I have a sql resultset called columns. When I convert an integer column to string that is a NULL it converts to zero. How can I get it to convert to null?? String x; x =...
1
by: Michel | last post by:
Hi again all, I have a small issue. Here's an example dataset : F1 F2 F3 1 0.58 Hi 2 0.70 Hello 3 Fail Bye 4 <Null> Hi
2
by: Trev | last post by:
I have two tables, tblMTO and tblIMPORT_MTO. If I import an entire MTO into the import table I want to create a delta from it (i.e. leave only the changed items). I have a view (simplified) ...
4
by: Gerry Abbott | last post by:
Hi All, Im trying to use thie combination but have not had success. Below is the function It tried the following myriskLevel(2,2) myrisklevel(0,0,2) and the ismissing(Three) alwasy...
2
by: jaYPee | last post by:
Anyone know how can I convert this field to ms sql server? IIf(=0 Or IsNull(),"--",) AS FinalGrade, SchYrSemCourseJoin.Final, IIf(=0 Or IsNull(),"--",) AS UnitAlias this is the full sql...
13
by: John A Grandy | last post by:
for a function parameter of a non-reference datatype ... such as date or boolean .... how to determine if the parameter was not specified in the calling code ? in vb6 we would have used the...
4
by: jimm.sander | last post by:
Hello, Problem: Im using isnull() in vbscript to determine if a field returned from a ado object call is in fact null. The problem is when I use isnull in anything other than a response.write()...
4
by: BSB | last post by:
IIf(IsNull()=True And IsNull(!)=True,"UNKNOWN",IIf((!)="CHECK" And (Left(,2)="58" Or Left(,2)="59"),"Residential",IIf((!)="CHECK" And Left(,2)="56","Commercial",IIf(IsNull()=True Or...
5
by: bobh | last post by:
Hi All, I have this query which updates a field based on the result of an IIF statement. The table is on SQLServer and I'm linked to it and it has many records and will take Access a very long...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.