Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ToInt()

Status
Not open for further replies.

chiph

Programmer
Jun 9, 1999
9,878
US

I was reading the September issue of MSDN, and in one of the articles they mention that code will have change from:
[tt][tab]rsLameError("BetaID") = clng(Request.Form("betaid"))[/tt]
to:
[tt][tab]rsLameError("BetaID").Value = Request.Form("betaid").ToString().ToInt()[/tt]

Does anyone have an idea why the ToInt() method is off the ToString method, and why it isn't just off the Form() object?

Chip H.
 
Your first example looks like ASP VBScript.

The second looks like ASP.Net VB.Net code.

In ASP.Net Request.Form(item) returns a NameValueCollection instead of the "array of strings" you got in ASP. In most cases there was only one occurrence of item, so you simply got a string (variant).

Since VB.Net has no variant type you have to do explicit type coercion by invoking the ToString() method, and then further coerce the result by explicitly invoking ToInt() as well.

You can't use
Code:
Request.Form("betaid").ToInt()
because Request.Form doesn't have a ToInt() method.

You use ToInt() because a VB.Net integer is a VB long, of course.

And just to drive me nuts, I can't find anything that claims a string has a ToInt() method either!

Sucks, don't it?

So maybe
Code:
Request.Form("betaid").ToInt()
is perfectly good - have you tried it? Suddenly I don't know 7/8 of what I thought I did!

The bathless hordes of C++ types who have driven Java and now C# and by extension VB.Net development seem to be all about making software development more labor intensive.

What cracks me up is their attempts like this at "elegance" when they have exceptions all over the place. You can still say
Code:
if a = b then
without having to code an explicit call on the Equals() method.

Sometimes I think they are trying to kill off VB.
 
I think it comes down to "that's how they decided it should work". Which is OK, I just didn't recognize that they had done that.

Chip H.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top