473,325 Members | 2,712 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,325 software developers and data experts.

UBound conversion from vb.net to c#

I'm having trouble converting this FOR loop from VB.NET to C#:

Here's the VB.NET code:

Dim localCart As Object
localCart = Session("cart")

For i = 0 To UBound(localCart, 2)
If CStr(localCart(CARTID, i)) <> "" Then
orderTotal = orderTotal + (CDbl(localCart(CARTPPRICE, i)) *
CDbl(localCart(CARTPQUANTITY, i)))
'do something
End If
Next

I used a VB.NET to C# converter called Instrant C# and this is what I
got:
object localCart;
localCart = Session["cart"];
int tempFor1 = localCart.GetUpperBound(1);
for (i = 0; i <= tempFor1; i++)
{
if (System.Convert.ToString(localCart(CARTID, i)) != "")
{
orderTotal = orderTotal +
(System.Convert.ToDouble(localCart(CARTPPRICE, i)) *
System.Convert.ToDouble(localCart(CARTPQUANTITY, i)));
//do something
}
}

And here's the error message:
Compiler Error Message: CS0117: 'object' does not contain a
definition for 'GetUpperBound'

Any solutions please!

*** Sent via Developersdex http://www.developersdex.com ***
Feb 2 '06 #1
2 12357
This is by design - we don't try to resolve the type inference issues that
the VB compiler addresses when variables are declared as 'Object'. In
general, more manual adjustments will be required when Option Strict is not
set in the original VB code.
--
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

"sunshine" wrote:
I'm having trouble converting this FOR loop from VB.NET to C#:

Here's the VB.NET code:

Dim localCart As Object
localCart = Session("cart")

For i = 0 To UBound(localCart, 2)
If CStr(localCart(CARTID, i)) <> "" Then
orderTotal = orderTotal + (CDbl(localCart(CARTPPRICE, i)) *
CDbl(localCart(CARTPQUANTITY, i)))
'do something
End If
Next

I used a VB.NET to C# converter called Instrant C# and this is what I
got:
object localCart;
localCart = Session["cart"];
int tempFor1 = localCart.GetUpperBound(1);
for (i = 0; i <= tempFor1; i++)
{
if (System.Convert.ToString(localCart(CARTID, i)) != "")
{
orderTotal = orderTotal +
(System.Convert.ToDouble(localCart(CARTPPRICE, i)) *
System.Convert.ToDouble(localCart(CARTPQUANTITY, i)));
//do something
}
}

And here's the error message:
Compiler Error Message: CS0117: 'object' does not contain a
definition for 'GetUpperBound'

Any solutions please!

*** Sent via Developersdex http://www.developersdex.com ***

Feb 3 '06 #2
Hi sunshine,
from looking at your example the Session("cart") is storing 2D array of
doubles. I am not a VB.Net guru but UBound seems to be automatically casting
the localCart object variable to a System.Array type.

However C# is less forgiving and you normally need to be more explicit
that when using Vb.Net (which is why a lot of people like it). In the C#
conversion you are trying to access the GetUpperBound method on a variable
which is of type object, and object dos not have this method, you will need
to first cast the object to a 2D array of doubles like:

object localCart;
localCart = Session["cart"];
int tempFor1 = localCart.GetUpperBound(1);

should be:
double[,] localCart = (double[,])Session["Cart"];
int tempFor1 = localCart.GetUpperBound(1);
Hope that helps
Mark Dawson
http://www.markdawson.org


"sunshine" wrote:
I'm having trouble converting this FOR loop from VB.NET to C#:

Here's the VB.NET code:

Dim localCart As Object
localCart = Session("cart")

For i = 0 To UBound(localCart, 2)
If CStr(localCart(CARTID, i)) <> "" Then
orderTotal = orderTotal + (CDbl(localCart(CARTPPRICE, i)) *
CDbl(localCart(CARTPQUANTITY, i)))
'do something
End If
Next

I used a VB.NET to C# converter called Instrant C# and this is what I
got:
object localCart;
localCart = Session["cart"];
int tempFor1 = localCart.GetUpperBound(1);
for (i = 0; i <= tempFor1; i++)
{
if (System.Convert.ToString(localCart(CARTID, i)) != "")
{
orderTotal = orderTotal +
(System.Convert.ToDouble(localCart(CARTPPRICE, i)) *
System.Convert.ToDouble(localCart(CARTPQUANTITY, i)));
//do something
}
}

And here's the error message:
Compiler Error Message: CS0117: 'object' does not contain a
definition for 'GetUpperBound'

Any solutions please!

*** Sent via Developersdex http://www.developersdex.com ***

Feb 3 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Jason | last post by:
I have a number of arrays that are populated with database values. I need to determine which array has the highest ubound out of all the arrays. The array size will always change based on the...
4
by: Benny Alexander | last post by:
Dear All, I have a problem, which needs your ideas. We have a excel document, which is been updated regularly. After everyday updating, we export as HTML file and upload it. As a ASP...
3
by: Andi Twine | last post by:
Hi all, I really hope someone here can help ! I have designed and built an ASP.NET web service with Visual Studio .NET. The web service outputs some dummy XML data when its called with some...
4
by: Cindy Meister -WordMVP- | last post by:
Hi all Generally, it seems Option Strict ON is recommended practice? How, then, does one reconcile -- Option Strict On Public MyArray(6) Single 'Some Code here
3
by: Brad Markisohn | last post by:
I've been brute forcing a conversion of binary data in a byte array into ASCII encrypted hex (2 chars = 1 byte). Is there a formatting scheme that will allow me to do this? Here's a snipet of the...
2
by: Starbuck | last post by:
Hi All In one of my converted (VB6 to VB.Net) apps I have managed to remove all instances of - Imports Microsoft.VisualBasic - except for one form which raises errors in regard to LBound and...
4
by: JR | last post by:
I may have posted a blank post accidentally. Sorry I am coming over to VB.NET from C++/C# and am confused about the UBound function. Example code: Dim i As Integer Dim myarray(6) As...
1
by: Ron | last post by:
Hello all, I had my code working using a number userid, then I chganged it to string and thought I did everything right, well now this function does not work. Anyone know what I am doing...
2
by: Ty | last post by:
The top block is the original code (I have already tried automatic convertors but they error everytime.) and the second block is what I have done. At the end will be the line that has me stumped. ...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.