472,126 Members | 1,560 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,126 software developers and data experts.

An object reference is required for the nonstatic field, method, or property

I am getting the following error on "rec "

rec = TheFile1.SendCommandFile("RCVFILE " + TheArrayVal,10000000 * 10);

public int SendCommandFile(string theCommand, int timeOut)
{
rc1 = RoboFTPSession.RoboSendCommand(theCommand, timeOut * 10);
finderror(rc1);
return rc1;
}

Jan 30 '06 #1
5 118704
Make the method static or create an instance of the class before calling the
method. Just like the error indicates.

<df********@hotmail.com> wrote in message
news:11**********************@g44g2000cwa.googlegr oups.com...
I am getting the following error on "rec "

rec = TheFile1.SendCommandFile("RCVFILE " + TheArrayVal,10000000 * 10);

public int SendCommandFile(string theCommand, int timeOut)
{
rc1 = RoboFTPSession.RoboSendCommand(theCommand, timeOut * 10);
finderror(rc1);
return rc1;
}

Jan 30 '06 #2
Because SendCommandFile is an instance method, you can't call it using
the class name. You have to make a particular instance of TheFile1 and
then call the method on that instance.

TheFile1 myFile = new TheFile1(... whatever arguments are required
....);
rec = myFile.SendCommandFile("RCVFILE " + TheArrayVal, 10000000 * 10);

Jan 30 '06 #3
I do. here is the code.....
static void Main(string[] args)
{
try
{
Utilities TheFile1 = new Utilities();
TheFile1.StartSession("xxx-FTP", 1, 0, "");
TheFile1.SendCommand("FTPLOGON \"ftp.xxxxxx.com\" /user=xxxx
/pw=xx", 10 * 10);
TheFile1.SendCommand("CD \"C:\\files\\listing\"", 100 * 10);
TheFile1.SendCommand("FTPCD \"test\"", 100 * 10);
TheFile1.SendCommand("FTPLIST \"listing of new_dir.txt\" \"*.*\"",
1000 * 10);
TheFile1.parseFile("C:/files/listing/listing of new_dir.txt");

ArrayList TheArray = TheFile1.FileNameArray;
//string TheArray = TheFile1.FileNameArray.ToString();
for(int i = 0; i< TheArray.Count; i++)
{
rec = TheFile1.SendCommandFile("RCVFILE " + TheArrayVal,10000000 *
10);
}
// TheFile1.SendCommand("RCVFILE \"*.*\" /delete", 10000000 * 10);
TheFile1.SendCommand("RCVFILE \"*.*\"", 10000000 * 10);
TheFile1.SendCommand("STOP", 10 * 10);
TheFile1.SendCommand("FTPLOGOFF", 10 * 10);
TheFile1.EndSession();

TheFile1.viewFileNames();
}
catch(Exception)
{

}
}

Jan 30 '06 #4
Hi,

rec = TheFile1.SendCommandFile("RCVFILE " + TheArrayVal,10000000 *
10);

where is rec declared?
What about TheArrayVal ?

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
Jan 30 '06 #5
On Mon, 30 Jan 2006 14:59:51 -0500, "Ignacio Machin \( .NET/ C# MVP
\)" <ignacio.machin AT dot.state.fl.us> wrote:
Hi,

rec = TheFile1.SendCommandFile("RCVFILE " + TheArrayVal,10000000 *
10);

where is rec declared?
What about TheArrayVal ?


I'll bet it's declared in the class that main is declared in. That's
a classic console app error meaning he didn't declare rec as

private static SomeObject rec;

How do I know this? I screw up and do it all the time.
;o)
Otis Mukinfus
http://www.otismukinfus.com
http://www.tomchilders.com
Jan 31 '06 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by DC | last post: by
1 post views Thread by Bucko | last post: by
2 posts views Thread by simonZ | last post: by
1 post views Thread by =?Utf-8?B?QUEyZTcyRQ==?= | last post: by
4 posts views Thread by cppquester | last post: by
reply views Thread by leo001 | last post: by

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.