473,327 Members | 1,892 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,327 software developers and data experts.

VB.NET solution doesn't port to C#.NET

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

Jul 19 '07 #1
3 1618

Hi Al,

Well,

SPortLink.txtStatusMsg.Text = "Opening BlackTip for Reading/Writing messages";

.... won't work because SPortLink does not have a static reference calledtxtStatusMsg. 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

--
Happy coding!
Morten Wennevik [C# MVP]
Jul 19 '07 #2
Post the original VB code and I'll convert it for you.
--
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
"al-s" wrote:
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

Jul 19 '07 #3
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();

"al-s" wrote:
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

Jul 20 '07 #4

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

Similar topics

4
by: Mark Goldin | last post by:
I am trying to implement a printing to file solution of a html page on the server. What I have is a form with a IE control that loads the page I want to print to. I am using execWB command for...
1
by: BJS | last post by:
Sorry for the cross-posting, but based on the number of people I have seen ask for a solution to this problem, I hope by cross-posting this, that it will help a lot of people out of a common...
5
by: EdgarBM | last post by:
Hi, I'm working with .NET Remoting. I have a problem unregistering the server channel when I try to reuse it closing and reopening it in the same application. The second time I try to get an...
3
by: Joca | last post by:
Hi, I have a process system that generate events and send them to a printer port, and in the end a printer writes it as a text line on a paper. I would like to chatch this text line...
52
by: lovecreatesbeauty | last post by:
Why the C standard committee doesn't provide a standard implementation including the C compiler and library when the language standard document is published? C works on the abstract model of low...
2
by: cwahlmeier | last post by:
I wanted to post this for anyone else who has been in -30081 hell like me. Our web servers run on the Windows platform and use DB2 Connect to query our DB2 for z/OS systems. For the last 4 years...
3
by: Lone Wolf | last post by:
I want to thank everybody who tried to help me, and also to post my solution, even though I don’t think it is a very good one. Many of you correctly guessed that there was an “\r” included with...
2
by: Wimpie van Lingen | last post by:
Hey I have some more questions with regards to Remoting in .NET 2. I'm using TCP with the Binary formatter. My solution consists of 4 projects: - Class Library containing the server classes...
3
by: naveen.sabapathy | last post by:
Hi, I am trying to use virtual serial ports to develop/test my serial communication program. Running in to trouble... I am using com0com to create the virtual ports. The virtual ports seem to...
39
by: alex | last post by:
I've converted a latin1 database I have to utf8. The process has been: # mysqldump -u root -p --default-character-set=latin1 -c --insert-ignore --skip-set-charset mydb mydb.sql # iconv -f...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
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...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
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
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
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.