Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   ASP .Net (http://www.velocityreviews.com/forums/f29-asp-net.html)
-   -   C# to VB.net conversion for "?" conditionals (http://www.velocityreviews.com/forums/t118289-c-to-vb-net-conversion-for-conditionals.html)

.Net Sports 01-26-2006 07:54 PM

C# to VB.net conversion for "?" conditionals
 
I need to convert some C# ?Conditionals over to vb.net (most likely in
vb.net using If..Then statements), but the C#2VBNETconverter by
KamalPatel isn't converting them:

string PurchaseType = (Convert.ToString(drwData["DailyItem"]) ==
"True") ? "ID" : "PID";

XmlNodeList Selections = xdcData.GetElementsByTagName((X == 0) ?
"Highlight" : "Selection");

TIA
NetSports


Peter Macej 01-26-2006 08:05 PM

Re: C# to VB.net conversion for "?" conditionals
 
Take a look at other converters. Free SharpDevelop from
http://www.icsharpcode.net/OpenSource/SD/ can do this. There is also
online version at
http://www.developerfusion.co.uk/uti...sharptovb.aspx.
It seems it handles these statements correctly.

--
Peter Macej
Helixoft - http://www.vbdocman.com
VBdocman - Automatic generator of technical documentation for VB, VB
..NET and ASP .NET code

Fao, Sean 01-26-2006 08:09 PM

Re: C# to VB.net conversion for "?" conditionals
 
..Net Sports wrote:
> I need to convert some C# ?Conditionals over to vb.net (most likely in
> vb.net using If..Then statements), but the C#2VBNETconverter by
> KamalPatel isn't converting them:
>
> string PurchaseType = (Convert.ToString(drwData["DailyItem"]) ==
> "True") ? "ID" : "PID";
>
> XmlNodeList Selections = xdcData.GetElementsByTagName((X == 0) ?
> "Highlight" : "Selection");


It has been a very long time since I've done any VB programming so
please check my work. But that should convert to something like this.

dim PurchaseType As String
dim Selections As XmlNodeList

If drwData["DailyItem"].ToString() = "True" Then
PurchaseType = "ID"
Else
PurchaseType = "PID"
End If



If X = 0 Then
Selections = xdcData.GetElementsByTagName("Highlight")
Else
Selections = xdcData.GetElementsByTagName("Selection")
End If

Hope that helps,

--
Sean

Karl Seguin [MVP] 01-26-2006 08:13 PM

Re: C# to VB.net conversion for "?" conditionals
 
I would recommend Sean's solution as well.

if you really want to single-line it, you can always use the iif function:
http://msdn.microsoft.com/library/de...l/vafctiif.asp

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/


"Fao, Sean" <enceladus311@yahoo.comI-WANT-NO-SPAM> wrote in message
news:ODJq$QrIGHA.3176@TK2MSFTNGP12.phx.gbl...
> .Net Sports wrote:
>> I need to convert some C# ?Conditionals over to vb.net (most likely in
>> vb.net using If..Then statements), but the C#2VBNETconverter by
>> KamalPatel isn't converting them:
>>
>> string PurchaseType = (Convert.ToString(drwData["DailyItem"]) ==
>> "True") ? "ID" : "PID";
>>
>> XmlNodeList Selections = xdcData.GetElementsByTagName((X == 0) ?
>> "Highlight" : "Selection");

>
> It has been a very long time since I've done any VB programming so please
> check my work. But that should convert to something like this.
>
> dim PurchaseType As String
> dim Selections As XmlNodeList
>
> If drwData["DailyItem"].ToString() = "True" Then
> PurchaseType = "ID"
> Else
> PurchaseType = "PID"
> End If
>
>
>
> If X = 0 Then
> Selections = xdcData.GetElementsByTagName("Highlight")
> Else
> Selections = xdcData.GetElementsByTagName("Selection")
> End If
>
> Hope that helps,
>
> --
> Sean




Stoitcho Goutsev \(100\) 01-26-2006 08:20 PM

Re: C# to VB.net conversion for "?" conditionals
 
Hi,

VB has similar function called IIF

<From MSDN>
Public Function IIf( _
ByVal Expression As Boolean, _
ByVal TruePart As Object, _
ByVal FalsePart As Object _
)

Keep in mind that this is a FUNCTION as oposed to C# ?:, which is operator.
What does it mean? This means that TruePart and FalsePart are passed as
parameter to the function and if they are emthods' return values sides are
going to be executed regardless of the value of the Expression. This might
lead to hard-to-discover semantic errors if calculations of the true-part
and/or false-part have side effects.


--
HTH
Stoitcho Goutsev (100)

".Net Sports" <ballz2wall@cox.net> wrote in message
news:1138305286.798041.81730@g43g2000cwa.googlegro ups.com...
>I need to convert some C# ?Conditionals over to vb.net (most likely in
> vb.net using If..Then statements), but the C#2VBNETconverter by
> KamalPatel isn't converting them:
>
> string PurchaseType = (Convert.ToString(drwData["DailyItem"]) ==
> "True") ? "ID" : "PID";
>
> XmlNodeList Selections = xdcData.GetElementsByTagName((X == 0) ?
> "Highlight" : "Selection");
>
> TIA
> NetSports
>




Herfried K. Wagner [MVP] 01-26-2006 11:42 PM

Re: C# to VB.net conversion for "?" conditionals
 
"Karl Seguin [MVP]" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME
net> schrieb:
>I would recommend Sean's solution as well.
>
> if you really want to single-line it, you can always use the iif function:
> http://msdn.microsoft.com/library/de...l/vafctiif.asp


ACK, but note that all parameters are evaluated in the 'IIf' function.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>


=?Utf-8?B?RGF2aWQgQW50b24=?= 01-27-2006 12:26 AM

RE: C# to VB.net conversion for "?" conditionals
 
(You get what you pay for with free converters)

Our Instant VB demo edition gives:

Dim PurchaseType As String
If (Convert.ToString(drwData("DailyItem")) = "True") Then
PurchaseType = "ID"
Else
PurchaseType = "PID"
End If

Dim Selections As XmlNodeList
If (X = 0) Then
Selections = xdcData.GetElementsByTagName("Highlight")
Else
Selections = xdcData.GetElementsByTagName("Selection")
End If

--
David Anton
www.tangiblesoftwaresolutions.com
Instant C#: VB to C# converter
Instant VB: C# to VB converter
Instant C++: C# to C++ converter & VB to C++ converter
Instant J#: VB to J# converter



".Net Sports" wrote:

> I need to convert some C# ?Conditionals over to vb.net (most likely in
> vb.net using If..Then statements), but the C#2VBNETconverter by
> KamalPatel isn't converting them:
>
> string PurchaseType = (Convert.ToString(drwData["DailyItem"]) ==
> "True") ? "ID" : "PID";
>
> XmlNodeList Selections = xdcData.GetElementsByTagName((X == 0) ?
> "Highlight" : "Selection");
>
> TIA
> NetSports
>
>


=?Utf-8?B?RGF2aWQgQW50b24=?= 01-27-2006 12:30 AM

Re: C# to VB.net conversion for "?" conditionals
 
Note that replacing "?" with IIf (which is what the free converters do) is
not correct.
The correct conversion is if/else.
--
David Anton
www.tangiblesoftwaresolutions.com
Instant C#: VB to C# converter
Instant VB: C# to VB converter
Instant C++: C# to C++ converter & VB to C++ converter
Instant J#: VB to J# converter



"Peter Macej" wrote:

> Take a look at other converters. Free SharpDevelop from
> http://www.icsharpcode.net/OpenSource/SD/ can do this. There is also
> online version at
> http://www.developerfusion.co.uk/uti...sharptovb.aspx.
> It seems it handles these statements correctly.
>
> --
> Peter Macej
> Helixoft - http://www.vbdocman.com
> VBdocman - Automatic generator of technical documentation for VB, VB
> ..NET and ASP .NET code
>


Jay B. Harlow [MVP - Outlook] 01-27-2006 02:49 AM

Re: C# to VB.net conversion for "?" conditionals
 
Karl,
For VS 2005 code I would recommend my generic IIf over the VB.IIf as the
generic IIf is type safe.

http://www.tsbradley.net/Cookbook/Ge...enericIIf.aspx

As Herfried points out, my generic IIf & VB.IIf are both functions all
parameters are evaluated, meaning there may be subtle side effects, if you
are simply passing constants for the truePart & falsePart parameters, then
the fact IIf is a function wouldn't matter... If the parameters are function
calls then this may matter...


--
Hope this helps
Jay [MVP - Outlook]
..NET Application Architect, Enthusiast, & Evangelist
T.S. Bradley - http://www.tsbradley.net


"Karl Seguin [MVP]" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME
net> wrote in message news:%23mnCFVrIGHA.3056@TK2MSFTNGP09.phx.gbl...
|I would recommend Sean's solution as well.
|
| if you really want to single-line it, you can always use the iif function:
|
http://msdn.microsoft.com/library/de...l/vafctiif.asp
|
| Karl
|
| --
| MY ASP.Net tutorials
| http://www.openmymind.net/
|
|
| "Fao, Sean" <enceladus311@yahoo.comI-WANT-NO-SPAM> wrote in message
| news:ODJq$QrIGHA.3176@TK2MSFTNGP12.phx.gbl...
| > .Net Sports wrote:
| >> I need to convert some C# ?Conditionals over to vb.net (most likely in
| >> vb.net using If..Then statements), but the C#2VBNETconverter by
| >> KamalPatel isn't converting them:
| >>
| >> string PurchaseType = (Convert.ToString(drwData["DailyItem"]) ==
| >> "True") ? "ID" : "PID";
| >>
| >> XmlNodeList Selections = xdcData.GetElementsByTagName((X == 0) ?
| >> "Highlight" : "Selection");
| >
| > It has been a very long time since I've done any VB programming so
please
| > check my work. But that should convert to something like this.
| >
| > dim PurchaseType As String
| > dim Selections As XmlNodeList
| >
| > If drwData["DailyItem"].ToString() = "True" Then
| > PurchaseType = "ID"
| > Else
| > PurchaseType = "PID"
| > End If
| >
| >
| >
| > If X = 0 Then
| > Selections = xdcData.GetElementsByTagName("Highlight")
| > Else
| > Selections = xdcData.GetElementsByTagName("Selection")
| > End If
| >
| > Hope that helps,
| >
| > --
| > Sean
|
|



Cor Ligthert [MVP] 01-27-2006 06:44 AM

Re: C# to VB.net conversion for "?" conditionals
 
Karl,

> if you really want to single-line it, you can always use the iif function:
> http://msdn.microsoft.com/library/de...l/vafctiif.asp
>

Why to obfuscate it to prevent maintenance?

I go for the solution from Sean

:-)

Cor




All times are GMT. The time now is 11:34 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.