PC Review


Reply
Thread Tools Rate Thread

what the c# equivalent of ...

 
 
=?Utf-8?B?am9zZSBnLiBkZSBqZXN1cyBqciBtY3AsIG1jZGJh
Guest
Posts: n/a
 
      29th Jul 2005
vb.net val function

c=val(a$)+val(b$)

thanks
 
Reply With Quote
 
 
 
 
Fabien Bezagu
Guest
Posts: n/a
 
      29th Jul 2005
This could be :

double c = double.Parse(a) + double.Parse(b)

Fabien

"jose g. de jesus jr mcp, mcdba"
<(E-Mail Removed)> a écrit dans le message
de news: F2EE4208-601C-4A00-A42F-(E-Mail Removed)...
> vb.net val function
>
> c=val(a$)+val(b$)
>
> thanks



 
Reply With Quote
 
Nick Malik [Microsoft]
Guest
Posts: n/a
 
      29th Jul 2005
given VB's tendency to hide errors, the Val() call would return a zero if
the string couldn't be parsed.

Therefore, the equivalent would more likely be:

string a = "233";
string b = "abc";
double conv_a, conv_b;
double.TryParse(a,NumberStyles.Integer,
CultureInfo.CurrentCulture.NumberFormat, conv_a);
double.TryParse(b,NumberStyles.Integer,
CultureInfo.CurrentCulture.NumberFormat, conv_b);
double c = conv_a + conv_b;


--
--- Nick Malik [Microsoft]
MCSD, CFPS, Certified Scrummaster
http://blogs.msdn.com/nickmalik

Disclaimer: Opinions expressed in this forum are my own, and not
representative of my employer.
I do not answer questions on behalf of my employer. I'm just a
programmer helping programmers.
--
"Fabien Bezagu" <fbezagu_at_novacor_dot_fr> wrote in message
news:%(E-Mail Removed)...
> This could be :
>
> double c = double.Parse(a) + double.Parse(b)
>
> Fabien
>
> "jose g. de jesus jr mcp, mcdba"
> <(E-Mail Removed)> a écrit dans le message
> de news: F2EE4208-601C-4A00-A42F-(E-Mail Removed)...
>> vb.net val function
>>
>> c=val(a$)+val(b$)
>>
>> thanks

>
>



 
Reply With Quote
 
Nicholas Paldino [.NET/C# MVP]
Guest
Posts: n/a
 
      29th Jul 2005
Actually, I would think that the best choice would be to actually use
the Val function in VB, by adding a reference to Microsoft.VisualBasic.dll
and then use the static Val method on the Conversion class in the
Microsoft.VisualBasic namespace?

Hope this helps.

--
- Nicholas Paldino [.NET/C# MVP]
- (E-Mail Removed)

"Nick Malik [Microsoft]" <(E-Mail Removed)> wrote in message
news:V9KdnSN4SKpiq3ffRVn-(E-Mail Removed)...
> given VB's tendency to hide errors, the Val() call would return a zero if
> the string couldn't be parsed.
>
> Therefore, the equivalent would more likely be:
>
> string a = "233";
> string b = "abc";
> double conv_a, conv_b;
> double.TryParse(a,NumberStyles.Integer,
> CultureInfo.CurrentCulture.NumberFormat, conv_a);
> double.TryParse(b,NumberStyles.Integer,
> CultureInfo.CurrentCulture.NumberFormat, conv_b);
> double c = conv_a + conv_b;
>
>
> --
> --- Nick Malik [Microsoft]
> MCSD, CFPS, Certified Scrummaster
> http://blogs.msdn.com/nickmalik
>
> Disclaimer: Opinions expressed in this forum are my own, and not
> representative of my employer.
> I do not answer questions on behalf of my employer. I'm just a
> programmer helping programmers.
> --
> "Fabien Bezagu" <fbezagu_at_novacor_dot_fr> wrote in message
> news:%(E-Mail Removed)...
>> This could be :
>>
>> double c = double.Parse(a) + double.Parse(b)
>>
>> Fabien
>>
>> "jose g. de jesus jr mcp, mcdba"
>> <(E-Mail Removed)> a écrit dans le
>> message de news: F2EE4208-601C-4A00-A42F-(E-Mail Removed)...
>>> vb.net val function
>>>
>>> c=val(a$)+val(b$)
>>>
>>> thanks

>>
>>

>
>



 
Reply With Quote
 
Paul E Collins
Guest
Posts: n/a
 
      29th Jul 2005
"Nicholas Paldino [.NET/C# MVP]" <(E-Mail Removed)>
wrote:

> Actually, I would think that the best choice would be
> to actually use the Val function in VB, by adding a
> reference to Microsoft.VisualBasic.dll and then use
> the static Val method on the Conversion class in the
> Microsoft.VisualBasic namespace?


Since C# is supposed to be a complete language in its own right, I'd
advise against using the contents of this namespace unless you're in a
big hurry to port some old code. Yeah, I know this is a matter of
debate, but IMHO when you include the VisualBasic namespace you might
as well be flagging your code with ObsoleteAttribute.

P.


 
Reply With Quote
 
Bob Grommes
Guest
Posts: n/a
 
      31st Jul 2005
But as another poster pointed out, many VB backward-compatibility functions
have subtle (and sometimes evil) behaviors that are designed for VB6
compatibility, and if the code expressly or unconsciously relies on these
behaviors, then using straightforward CLR code may get the job done but
without the VB6 side effects and therefore without the exact same execution
path.

I don't know how much of a newbie the OP was but really the simplest answer
is:

string a = "123";
int c = Convert.ToInt32(a);

.... or the equivalent ToDouble() or whatever. But you have to ask yourself
what happens with boundary conditions such as an empty, null or non-integer
string with the original Val() function, and then if the behavior is
different you have to decide whether it matters, or whether you want to use
more standard or robust methods of dealing with those boundary conditions.

One of VB.NET's dirty secrets is that in an effort to ease the VB6 to VB.NET
transition, developers have been encouraged to use Val() and CInt() and
CType() and so forth, rather than write standard .NET API calls. And it
creates issues such as what we're now discussing when you want to port code,
and sometimes creates issues in mixed-language projects. Since I never did
much VB6 and learned C# as my first and primary .NET language, when I get
involved in a VB.NET project I tend to write VB.NET versions of how
something would be done in C#. This produces somewhat different code than
most VB coders tend to write. Not wildly so, but more CLR oriented than VB6
oriented. My VB.NET code could get by without VisualBasic.dll.

By contrast someone who started with, say, QuickBasic and has stayed with
the language ever since understandably tends to want to write code the way
they always have, out of affection and nostalgia. And that's arguably fine
if you really want to stay exclusively in a parochial VB-centric
environment. But I think it cuts your flexibility down.

--Bob

"Paul E Collins" <(E-Mail Removed)> wrote in message
news:dce7lj$csv$(E-Mail Removed)...
> "Nicholas Paldino [.NET/C# MVP]" <(E-Mail Removed)> wrote:
>
>> Actually, I would think that the best choice would be
>> to actually use the Val function in VB, by adding a
>> reference to Microsoft.VisualBasic.dll and then use
>> the static Val method on the Conversion class in the
>> Microsoft.VisualBasic namespace?

>
> Since C# is supposed to be a complete language in its own right, I'd
> advise against using the contents of this namespace unless you're in a big
> hurry to port some old code. Yeah, I know this is a matter of debate, but
> IMHO when you include the VisualBasic namespace you might as well be
> flagging your code with ObsoleteAttribute.
>
> P.



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Equivalent for VB6 Mazant, K. Microsoft Dot NET 2 9th Dec 2007 05:55 AM
vba equivalent John Microsoft VB .NET 7 3rd Dec 2007 05:57 PM
Equivalent Of VAL davidm Microsoft Excel Programming 4 27th Jul 2005 06:22 PM
Equivalent of GetPrivateProfileString equivalent in C#? Germic Microsoft C# .NET 1 24th Jan 2005 09:22 AM
C#'s equivalent of the stl Boogie El Aceitoso Microsoft C# .NET 3 6th Apr 2004 02:25 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 10:35 AM.