By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,197 Members | 1,173 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,197 IT Pros & Developers. It's quick & easy.

How to call a sub procedure in a console application?

P: 21
Hi,
I want to use a sub procedure called upload as follows in a console application.
Expand|Select|Wrap|Line Numbers
  1. namespace uploadreports
  2. {
  3. class program
  4. {
  5. static void Main(string[] args)
  6. {
  7. public void upload(name1,name2
  8. {
  9. //my code
  10. }
  11. upload(name1,name2);
  12. upload(name3,name4);
  13.  
  14. }
  15. }
  16. }

But, if i try to call it in this way, it is giving error under
static void Main(string[] args)
{ saying that } is required. But, the number of open and closed braces are exactly matching in my program
Now, I got a doubt can I use the function or sub program in this way or not?

TIA.
Jan 22 '09 #1
Share this Question
Share on Google+
5 Replies


P: 3
You've nested your upload sub procedure inside your Main() procedure.

It needs to go like this:
Expand|Select|Wrap|Line Numbers
  1. namespace uploadreports
  2. {
  3. public class program
  4. {
  5. public static void Main(string[] args)
  6. {
  7. //Your code
  8. upload(name1,name2);
  9. upload(name3,name4);
  10.  
  11. }
  12. private void upload(object name1, object name2)
  13. {
  14. //your code
  15. }
  16.  
  17. }
  18. }
Jan 22 '09 #2

P: 21
Thanks for your reply.
But, when I try to execute in the way you have mentioned above, it is giving me the following error at the sub procedure.
"An object reference is required for the non static field,method or property uploadreports.program.upload(string,string)"
Any idea how to fix it?
Jan 22 '09 #3

Frinavale
Expert Mod 5K+
P: 9,731
What did you supply to your upload() method?
Jan 22 '09 #4

P: 3
I forgot the static keyword in your subroutine:

Expand|Select|Wrap|Line Numbers
  1. private static void upload(object name1, object name2)
  2. {
  3. //your code
  4. }
  5.  
A static method can only call other static methods in the class, and use other static fields/properties/members in the class.
Jan 22 '09 #5

Plater
Expert 5K+
P: 7,872
I would also suggest going through a few tutorials on Object Oriented Programming(OOP), maybe with a focus in .NET, so you can try out the examples you would find.
Jan 22 '09 #6

Post your reply

Sign in to post your reply or Sign up for a free account.