I have a working VB.NET 2005 (.NET2.0) solution that works. When I
translate the code modules, form modules to C# I get all sorts of
build errors, much of which are related to scoping of methods.
I have the following given in a form module:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace SPORTLinkCSC
{
public partial class SPortLink : Form
{
public SPortLink()
{
InitializeComponent();
}
static SPortImplement si = new SPortImplement();
private void btnQuit_Click(object sender, EventArgs e)
{
this.Close();
}
void FormLoad(object sender, EventArgs e)
{
this.txtRcvMsg.Text = "Waiting to receive message";
this.txtSndMsg.Text = "Waiting to send message";
InitBoard();
}
}
}
I also have the following in a code module which contains methods that
I want the form to call:
using System;
using System.Windows.Forms;
using System.Runtime.InteropServices;
using System.Threading;
using System.Diagnostics;
namespace SPORTLinkCSC
{
public class SPortImplement
{
private void InitBoard()
{
Int32 status = 0;
//ulong address = 0;
SPortLink.txtStatusMsg.Text = "Opening BlackTip for
Reading/Writing messages";
}
}
}
When trying to build, I get the errors:
1) An object reference is required for the nonstatic field, method,
or property
2) The name 'InitBoard' does not exist in the current context
The code module and the form module are in seperate files both in the
VB.NET project and in the C# project. Why after converting the code
from language to another does the whole thing fall apart? The two
languages are relatively close and I believe I converted them
properly. I can provide the VB.NET code of these two modules if it
would help.
Any insight or help greatly appreciated.
Al
Morten Wennevik [C# MVP] - 19 Jul 2007 14:32 GMT
Hi Al,
Well,
SPortLink.txtStatusMsg.Text = "Opening BlackTip for Reading/Writing messages";
... won't work because SPortLink does not have a static reference called txtStatusMsg. You may have wanted to do
SPortLink link = new SPortLink();
link.txtStatusMsg.Text = "Opening BlackTip for Reading/Writing messages";
... which won't work either unless txtStatusMsg is public
InitBoard() won't work from SPortLink since it does not have this method. That method is defined in SPortImplement

Signature
Happy coding!
Morten Wennevik [C# MVP]
David Anton - 19 Jul 2007 15:20 GMT
Post the original VB code and I'll convert it for you.

Signature
David Anton
www.tangiblesoftwaresolutions.com
Convert between VB, C#, and C++
Instant C#
Instant VB
Instant C++
C++ to C# Converter
C++ to VB Converter
> I have a working VB.NET 2005 (.NET2.0) solution that works. When I
> translate the code modules, form modules to C# I get all sorts of
[quoted text clipped - 76 lines]
>
> Al
ModelBuilder - 20 Jul 2007 03:30 GMT
I would translate the module to a C# class with all the methods being static.
Private void InitBoard()
then becomes
public static void InitBoard()
and the call becomes
SPortImplement.InitBoard();
> I have a working VB.NET 2005 (.NET2.0) solution that works. When I
> translate the code modules, form modules to C# I get all sorts of
[quoted text clipped - 76 lines]
>
> Al