473,587 Members | 2,492 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

convert function to csharp

Hi,

I am attempting to convert this vb function to csharp but I am getting stuck
on the if statement dt.Rows(iLoop)( "FAQCategoryID" )). The compiler says
"method name expected" and underlines dt.Rows[iLoop]. I don't understand.
Thanks for your help.

Function GetSelIndex(Cat ID as String) as Integer
Dim iLoop as Integer

'Loop through each row in the DataSet
Dim dt as DataTable = ddlDataSet.Tabl es("Categories" )
For iLoop = 0 to dt.Rows.Count - 1
If Int32.Parse(Cat ID) = Int32.Parse(dt. Rows(iLoop)("FA QCategoryID"))
then
Return iLoop
End If
Next iLoop
End Function

public int GetSelIndex(str ing CatID)
{
int iLoop;

// Loop through each row in the DataSet
DataTable dt = ddlDataSet.Tabl es["Categories "];
int rowCount = dt.Rows.Count-1;

for (iLoop=0; rowCount <= iLoop; iLoop++)
if (Int32.Parse(Ca tID) = Int32.Parse(dt. Rows[iLoop]("id")))
{
return iLoop;
}
}
Nov 17 '05 #1
5 4097
hi
for (iLoop=0; rowCount <= iLoop; iLoop++)
if (Int32.Parse(Ca tID) = Int32.Parse(dt. Rows[iLoop]["id"]))
{
return iLoop;
}
}

or a better way:
int catID = Int32.Parse(Cat ID);
int index= 0;
foreach( DataRow row in ddlDataSet.Tabl es["Categories "].Rows)
if ( catID == (int)row["CatID"])
return index;
else
index++;
cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation


"Andy Sutorius" <an**@sutorius. com> wrote in message
news:dQ******** ************@tw ister.southeast .rr.com...
Hi,

I am attempting to convert this vb function to csharp but I am getting
stuck
on the if statement dt.Rows(iLoop)( "FAQCategoryID" )). The compiler says
"method name expected" and underlines dt.Rows[iLoop]. I don't understand.
Thanks for your help.

Function GetSelIndex(Cat ID as String) as Integer
Dim iLoop as Integer

'Loop through each row in the DataSet
Dim dt as DataTable = ddlDataSet.Tabl es("Categories" )
For iLoop = 0 to dt.Rows.Count - 1
If Int32.Parse(Cat ID) = Int32.Parse(dt. Rows(iLoop)("FA QCategoryID"))
then
Return iLoop
End If
Next iLoop
End Function

public int GetSelIndex(str ing CatID)
{
int iLoop;

// Loop through each row in the DataSet
DataTable dt = ddlDataSet.Tabl es["Categories "];
int rowCount = dt.Rows.Count-1;

for (iLoop=0; rowCount <= iLoop; iLoop++)
if (Int32.Parse(Ca tID) = Int32.Parse(dt. Rows[iLoop]("id")))
{
return iLoop;
}
}

Nov 17 '05 #2
Hi,

Thank you for the code. I am now using your better way. When I compile I
receive "not all code paths return a value" and the function name,
GetSelIndex, is underlined.

I don't understand what the compiler is saying. Code Path?

Thanks,

Andy
"Ignacio Machin ( .NET/ C# MVP )" <ignacio.mach in AT dot.state.fl.us > wrote
in message news:u9******** ******@TK2MSFTN GP10.phx.gbl...
hi
for (iLoop=0; rowCount <= iLoop; iLoop++)
if (Int32.Parse(Ca tID) = Int32.Parse(dt. Rows[iLoop]["id"]))
{
return iLoop;
}
}

or a better way:
int catID = Int32.Parse(Cat ID);
int index= 0;
foreach( DataRow row in ddlDataSet.Tabl es["Categories "].Rows)
if ( catID == (int)row["CatID"])
return index;
else
index++;
cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation


"Andy Sutorius" <an**@sutorius. com> wrote in message
news:dQ******** ************@tw ister.southeast .rr.com...
Hi,

I am attempting to convert this vb function to csharp but I am getting
stuck
on the if statement dt.Rows(iLoop)( "FAQCategoryID" )). The compiler says
"method name expected" and underlines dt.Rows[iLoop]. I don't understand. Thanks for your help.

Function GetSelIndex(Cat ID as String) as Integer
Dim iLoop as Integer

'Loop through each row in the DataSet
Dim dt as DataTable = ddlDataSet.Tabl es("Categories" )
For iLoop = 0 to dt.Rows.Count - 1
If Int32.Parse(Cat ID) = Int32.Parse(dt. Rows(iLoop)("FA QCategoryID"))
then
Return iLoop
End If
Next iLoop
End Function

public int GetSelIndex(str ing CatID)
{
int iLoop;

// Loop through each row in the DataSet
DataTable dt = ddlDataSet.Tabl es["Categories "];
int rowCount = dt.Rows.Count-1;

for (iLoop=0; rowCount <= iLoop; iLoop++)
if (Int32.Parse(Ca tID) = Int32.Parse(dt. Rows[iLoop]("id")))
{
return iLoop;
}
}


Nov 17 '05 #3

"Andy Sutorius" <an**@sutorius. com> wrote in message
news:Ht******** ************@tw ister.southeast .rr.com...
Hi,

Thank you for the code. I am now using your better way. When I compile I
receive "not all code paths return a value" and the function name,
GetSelIndex, is underlined.

I don't understand what the compiler is saying. Code Path?
Code paths are all the possible paths of execution through your code, that
is each possible combination of conditions. You must return or throw an
exception at the end of those paths(return really *IS* the end of those
paths). In your case , while in your foreach loop you are only returning if
a condition is met, therefore it is possible for the loop to end without
returning. And thus possible for execution to reach the end of the method
without returning.

Just add an appropriate return statement in at the end of your method.

Something like:

public int GetSelIndex(str ing CatID)
{
int iLoop;

// Loop through each row in the DataSet
DataTable dt = ddlDataSet.Tabl es["Categories "];
int rowCount = dt.Rows.Count-1;

int catID = Int32.Parse(Cat ID);
int index= 0;
foreach( DataRow row in ddlDataSet.Tabl es["Categories "].Rows)
{
if ( catID == (int)row["CatID"])
return index;
else
index++;
}

return -1; //note the return here, before it was possible to reach the end
of the method without returning.
}
Thanks,

Andy
"Ignacio Machin ( .NET/ C# MVP )" <ignacio.mach in AT dot.state.fl.us >
wrote
in message news:u9******** ******@TK2MSFTN GP10.phx.gbl...
hi
for (iLoop=0; rowCount <= iLoop; iLoop++)
if (Int32.Parse(Ca tID) = Int32.Parse(dt. Rows[iLoop]["id"]))
{
return iLoop;
}
}

or a better way:
int catID = Int32.Parse(Cat ID);
int index= 0;
foreach( DataRow row in ddlDataSet.Tabl es["Categories "].Rows)
if ( catID == (int)row["CatID"])
return index;
else
index++;
cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation


"Andy Sutorius" <an**@sutorius. com> wrote in message
news:dQ******** ************@tw ister.southeast .rr.com...
> Hi,
>
> I am attempting to convert this vb function to csharp but I am getting
> stuck
> on the if statement dt.Rows(iLoop)( "FAQCategoryID" )). The compiler says
> "method name expected" and underlines dt.Rows[iLoop]. I don't understand. > Thanks for your help.
>
> Function GetSelIndex(Cat ID as String) as Integer
> Dim iLoop as Integer
>
> 'Loop through each row in the DataSet
> Dim dt as DataTable = ddlDataSet.Tabl es("Categories" )
> For iLoop = 0 to dt.Rows.Count - 1
> If Int32.Parse(Cat ID) = Int32.Parse(dt. Rows(iLoop)("FA QCategoryID"))
> then
> Return iLoop
> End If
> Next iLoop
> End Function
>
> public int GetSelIndex(str ing CatID)
> {
> int iLoop;
>
> // Loop through each row in the DataSet
> DataTable dt = ddlDataSet.Tabl es["Categories "];
> int rowCount = dt.Rows.Count-1;
>
> for (iLoop=0; rowCount <= iLoop; iLoop++)
> if (Int32.Parse(Ca tID) = Int32.Parse(dt. Rows[iLoop]("id")))
> {
> return iLoop;
> }
> }
>
>



Nov 17 '05 #4
Andy,

When we bring back first your VBNet code to something more reasonable.

\\\
Private Function GetSelIndex(Byv alue CatID as String) as Integer
Dim dt as DataTable = ddlDataSet.Tabl es("Categories" )
For i as Integer = 0 to dt.Rows.Count - 1
If CatID = dt.Rows(i)("FAQ CategoryID").To String)
Return i
End If
End Function
///
\\\
private integer GetSelIndex(str ing CatID){
DataTable dt = ddlDataSet.Tabl es["Categories "];
for (int i = 0;i> dt.Rows.Count;i ++){
if (CatID == dt.Rows(i)["FAQCategor yID"].ToString)){
return i;}}
}
///

Not so much difference in my opinion.

Cor
Nov 17 '05 #5
Our VB to C# converter (Instant C#) produces the following - note that:
1. Although in your example you could safely ignore it, in general you have
to account for the fact that the ending condition of a VB for loop is checked
only once while the ending condition of a C# for loop is checked every
iteration.
2. You need to return a value for every code path in C# - usually C#
developers will just add the default statement at the end of the function
when they get this warning (VB does this for you behind the scenes).

public int GetSelIndex(str ing CatID)
{
int iLoop = 0;

//Loop through each row in the DataSet
DataTable dt = ddlDataSet.Tabl es["Categories "];
int tempFor1 = dt.Rows.Count;
for (iLoop = 0; iLoop < tempFor1; iLoop++)
{
if (Int32.Parse(Ca tID) ==
Int32.Parse(dt. Rows[iLoop]["FAQCategor yID"]))
{
return iLoop;
}
}
//INSTANT C# NOTE: Inserted the following 'return' since all code paths
must return a value in C#:
return 0;
}
David Anton
www.tangiblesoftwaresolutions.com
Home of the Instant C# VB.NET to C# converter and the Instant VB C# to
VB.NET converter

"Andy Sutorius" wrote:
Hi,

I am attempting to convert this vb function to csharp but I am getting stuck
on the if statement dt.Rows(iLoop)( "FAQCategoryID" )). The compiler says
"method name expected" and underlines dt.Rows[iLoop]. I don't understand.
Thanks for your help.

Function GetSelIndex(Cat ID as String) as Integer
Dim iLoop as Integer

'Loop through each row in the DataSet
Dim dt as DataTable = ddlDataSet.Tabl es("Categories" )
For iLoop = 0 to dt.Rows.Count - 1
If Int32.Parse(Cat ID) = Int32.Parse(dt. Rows(iLoop)("FA QCategoryID"))
then
Return iLoop
End If
Next iLoop
End Function

public int GetSelIndex(str ing CatID)
{
int iLoop;

// Loop through each row in the DataSet
DataTable dt = ddlDataSet.Tabl es["Categories "];
int rowCount = dt.Rows.Count-1;

for (iLoop=0; rowCount <= iLoop; iLoop++)
if (Int32.Parse(Ca tID) = Int32.Parse(dt. Rows[iLoop]("id")))
{
return iLoop;
}
}

Nov 17 '05 #6

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

Similar topics

3
7745
by: hunterb | last post by:
I have a file which has no BOM and contains mostly single byte chars. There are numerous double byte chars (Japanese) which appear throughout. I need to take the resulting Unicode and store it in a DB and display it onscreen. No matter which way I open the file, convert it to Unicode/leave it as is or what ever, I see all single bytes ok, but...
11
21912
by: Ken Varn | last post by:
I want to be able to determine my current line, file, and function in my C# application. I know that C++ has the __LINE__, __FUNCTION__, and __FILE___ macros for getting this, but I cannot find a C# equivalent. Any ideas? -- ----------------------------------- Ken Varn Senior Software Engineer Diebold Inc. varnk@diebold.com
1
2554
by: Tamir Khason | last post by:
Somebody knows how to convert Bounds to Point ??? Thnx
3
18182
by: Mike | last post by:
Hi, Does anyone know of reliable programs that convert C# to Java and viceversa? Thanks Mike
2
2845
by: Remi Caron | last post by:
Hi, I took over an Visual Object project (Visual Clipper) in that language there is a function to: Convert a string containing a 32-bit binary date to a date data type. That function is called bin2Date and there also is a Date2bin function of course in cannot find how to do this in csharp. The string looks like this "!$%\0" and should...
1
1986
by: dongxm | last post by:
Is there a function can convert "abc" to "\u0097\u0098\u0099" in dotnet(c#)
5
260044
by: moondaddy | last post by:
How do I get the string representation of an int? for example int var1 = 2; string var2 = var1.ToString; I'm wanting var2 to be "2" I get the compile error: Error 1 Cannot convert method group 'ToString' to non-delegate type
1
1733
by: Robert Dufour | last post by:
I am trying to sort the membership list of the membership provider for ASP.NET the code has retrieved the list and now we need to sort it by a parameter if it was passed. So in C# the code is. Comparison<MembershipUserWrappercomparer = null; switch (sortDataBase) {
18
43021
by: MrVS | last post by:
Hi, I have a C++ CLR class method that takes System::Byte *b as parameter argument. I want the CSharp caller pass a byte * to this function. But in the CSharp prorgram, I only managed to create a byte array (byte). Can anyone tell me how to convert byte array to byte pointer in CSharp? Please show me an simple example about how to do it....
0
7920
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7849
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8347
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7973
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
6626
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
5394
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3844
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3879
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2358
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.