Convert C# to vb

  • Thread starter Thread starter Al
  • Start date Start date
A

Al

Can anyone write this code in vb

string highligh(object ytdsales)
{
if (ytdSales.Equals(DBNull.Value)
{
return",<i> No Sales</i>;
}
else
{
if (((int) ytdSales) >1000)
{
return "Good sales"
}
}

basically, I am trying to know how to write functions with
both languages (:
Al
 
I don't have my IDE in front of me, but this should do it:

Function highligh(ByVal ytdasles as Object) As String
If ytdSales.Equals(DbNull.Value) then
return ",<i> No Sales<i>,"
Else If Ctype(ytdSales, Integer) > 1000 then
Return "GoodSales

End If

End Function
 
Hi Al,

Writting blindly:

Private Function highligh(ytdsales As object) As String
If IsDbNull(ytdsales) Then
return ",<i> No Sales</i>"
Else
If CType(ytdsales, Integer) > 1000 Then
return "Good sales"
End If
End If
End Function
 
Hi Al,

Also written here asuming what is wanted
(I am not sure of the IsDBnull in the other samples will do it and therefore
this sample, and I think this is more VB.net than converted C#)

(I do not like that value boxed in that object I never use that)

Private function highligh(byval ytdsales as object) as string
if Not ytdSales Is Nothing
if Cint(ytdSales) > 1000 then
return "Good sales"
Else
return "Low Sales"
Else
return "No sales"
end if
end function

Just another approach than Bill and Miha

Cor
 
Hi Cor,

You are testing against Nothing (null in C#).
But what about DBNull.Value?
 
Hi Miha,

I am not sure of this. But because I have seen that people have a lot of
problems with this I though that it was right to give this example for if it
would give an error there with your example.

When it was an item I just would write
if item<>dbnull.value, that is standard,

Therefore I was not so glad with that object

(I never used your example IsDbValue and did see it only once before)

However if it is a let say a readXML dataset than can it be:
item Is nothing when the node does not exist (I use that, it takes some
extra work before writting the xml set)

item = nothing the node is "" (exist but empty), when I write that in the
vb.language group I get almost direct response from Armin.

But when it is a real database item it can also be
item = dbNull.value and not item Is nothing

Confusing is it not?

Cor.
 
Back
Top