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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem translating VB code to C# 1

Status
Not open for further replies.

SteveL714

Programmer
Sep 19, 2013
21
US
I'm translating an old VB routine to C#. In VB I had the following code sequence
Code:
Dim SearchView AS New DataView(CurrentSchedule.Tables(0))
SearchView.Sort = "shiftgroup,worker_id"
SearchView.RowFilter = "worker_id <> 0"
Dim keys(1) as Object
...
' Set lookup values for this record.
keys(0) = nThisShiftGroup
keys(1) = nWorkerId

I put the VB code thru an on-line translator and this is what came back
Code:
DataView SearchView = new DataView(CurrentSchedule.Tables[0]);
SearchView.Sort = "shiftgroup,worker_id";
SearchView.RowFilter = "worker_id <> 0";
object[,] keys = null;
...
//  Set lookup values for this record.
keys(0) = nThisShiftGroup;
keys(1) = nWorkerId;

The C# code compiles without error, but when it runs as soon as it executes the "keys(0) = nThisShiftGroup;" line it throws the following error:
Code:
Object reference not set to an instance of an object

What am I not doing?

Steve

 
This:
Code:
object[,] keys = null;
YOu obviously want it two-dimensional, so try this instead:
Code:
object[] keys = new object[2];

Good luck!
MakeItSo

“Knowledge is power. Information is liberating. Education is the premise of progress, in every society, in every family.” (Kofi Annan)
Oppose SOPA, PIPA, ACTA; measures to curb freedom of information under whatever name whatsoever.
 
Which on-line translator were you using?

And which one has anybody else here used and can recommend?
 
Your favourite search engine should list several for you to experiment with. Some are fee based for more than a few lines of code.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top