convert vb.net to csharp

L

L.Peter

Dear Group,
I have the following code for vb.net

***
Dim objFaxServer As New FAXCOMEXLib.FaxServer

Dim collFaxIncomingJobs As FaxIncomingJobs

Dim objFaxIncomingJob As FaxIncomingJob

'Error handling

On Error GoTo Error_Handler

'Connect to the fax server

objFaxServer.Connect("")

'Get the collection of jobs in the incoming queue

collFaxIncomingJobs = objFaxServer.Folders.IncomingQueue.GetJobs()

'Display the number of jobs in the collection

MsgBox("There are " & collFaxIncomingJobs.Count & " jobs in the incoming
queue.")

Dim n As Long

'Get the job

n = InputBox("Input the item number for which you want information.")

objFaxIncomingJob = collFaxIncomingJobs.Item(n)



Exit Sub

Error_Handler:

'Implement error handling at the end of your subroutine. This implementation
is for demonstration purposes

MsgBox("Error number: " & Hex(Err.Number) & ", " & Err.Description)

***

here is what I come up with in CSharp

FAXCOMEXLib.FaxServer objFaxServer = new FAXCOMEXLib.FaxServer();

FaxIncomingJobs colIJs = objFaxServer.Folders.IncomingQueue.GetJobs();

objFaxServer.Connect("");

for (int i=1;i< colIJs.Count ; i++)

{

//csharp won't compile this line saying no definition for Item

FaxIncomingJob oIJ = colIJs.Item(i);

//do some process

}

What I want to do is loop through Jobs and record them to the database, it
seems like my conversion is not correct

Please help

TIA

L.Peter
 
M

Morten Wennevik

I'll give it a try, my VB knowledge is somewhat lacking.
Remember, VB uses () for arrays, and C# []

FAXCOMEXLib.FaxServer objFaxServer = new FAXCOMEXLib.FaxServer();

FaxIncomingJobs collFaxIncomingJobs;

FaxIncomingJob objFaxIncomingJob;

"On Error GoTo Error_Handler" ??? is this valid VB code?
maybe a try catch statement

try
{
objFaxServer.Connect("");

collFaxIncomingJobs = objFaxServer.Folders.IncomingQueue.GetJobs();

MsgBox("There are " + collFaxIncomingJobs.Count + " jobs in the incoming
queue.");

long n;

n = InputBox("Input the item number for which you want information.");

objFaxIncomingJob = collFaxIncomingJobs.Item[n];

return; // the return isn't necessary as the catch block is ignored if
the try block is successfull
}
catch(Exception ex)
{
MsgBox("Error: " + ex.Message); // no error number
}
 
L

L.Peter

Hi Guillermo,
your code works. You make my pc listen :)
Thanks a lot

Regards

L.Peter

Guillermo 'guille' said:
in C# the Item is the indexer, so use this:
objFaxIncomingJob = collFaxIncomingJobs[n];

--
Nos vemos.
Guillermo
--------------
P.S.
Si te parece últil mi sitio:
http://www.elguille.info/lonuevo/lo_nuevo0312.htm#dic30
--------------
Microsoft VB MVP desde 1997
Te invito a mi sitio dedicado al VB y más...
http://www.elguille.info/
http://www.mundoprogramacion.com/
(puede que el correo usado sea anti-spam)


L.Peter said:
Hi Morten Wennevik,
Thank you for your help.
Csharp still choked at the line

objFaxIncomingJob = collFaxIncomingJobs.Item[n];

It's weird as I can compile the code in VB.net but not in c#, i just cannot
find item from FaxIncomingJobs collection.
i include the link here if you need more info
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/fax/faxinta_n_5ga5.asp
Regards

L.Peter
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top