Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Call a procedure from another procedure on a different form in C#

Posted on 2013-06-27
14
322 Views
Last Modified: 2013-07-10
Hey guys!!

I am trying to call a public procedure 'postMessageToSystem()' on frmPOSLoad from a procedure on frmViewRX and I can't seem to find a straightforward answer.

Help please!!!  :-)

Jerry
0
Comment
Question by:JDL129
  • 9
  • 5
14 Comments
 
LVL 40

Expert Comment

by:Kyle Abrahams
ID: 39281771
You would have to instantaite the form:

eg:

Form v = new frmViewRX();
v.postMessageToSystem();

If you're having a bunch of common functions it's better to create a seperate class (possibly even static) and do something like:

ApplicationHelper.postMessageToSystem();

static class ApplicationHelper
{
   public ApplicationHelper()
{
}
  public static postMessageToSystem()

{
   // code goes here.
}
}
0
 

Author Comment

by:JDL129
ID: 39281898
ged325!!!  Thanks for the post!!

I am a newbie in C#.  Could you possibly expound a little.  I tried both methods and could get neither to work.  I place the first part of the answer on frmViewRX but the error I received was that it couldn't find postMessageToSystem which is on frmPOSLoad.

I also tried the second part but that was a disaster.  I added a new class but didn't know exactly where to put the code.

Thanks again,
Jerry
0
 

Author Comment

by:JDL129
ID: 39282086
ged325!!  I went back and tried adding the class again and I'm down to one error on then
public static postMessageToSystem:


          Method must have a turn type.

Thanks for the post!!!!
Jerry
0
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 

Author Comment

by:JDL129
ID: 39282112
ged325!!  Actually all I want to do is run the code in the class.

thanks,
Jerry
0
 
LVL 40

Expert Comment

by:Kyle Abrahams
ID: 39282181
forgot the void . . . was typing it off the top of my head.

Change void if you need to return something.


  public static void postMessageToSystem()
{
}
0
 

Author Comment

by:JDL129
ID: 39282703
ged325!!!  My but you overestimate me!!!!

Can you give me the bite sized instructions as to how to run a procedure on a different form instead of the chunks you guru's use?  :-)

Surely there is an easy way to do this:
I am trying to call a public procedure 'postMessageToSystem()' on frmPOSLoad from a procedure on frmViewRX.

Thanks,

Jerry
0
 
LVL 40

Accepted Solution

by:
Kyle Abrahams earned 200 total points
ID: 39282796
in your frmViewRX:


Form f = new frmPOSLoad();
   f.postMessageToSystem();
0
 

Author Comment

by:JDL129
ID: 39283292
ged325!!  Thanks for the post!!

I put the code in as instructed but I get this error:

Error      98      'System.Windows.Forms.Form' does not contain a definition for 'postMessageToSystem' and no extension method 'postMessageToSystem' accepting a first argument of type 'System.Windows.Forms.Form' could be found (are you missing a using directive or an assembly reference?)      C:\POSiTrackRx\POSiTrackC\frmViewRX.cs      2282      15      POSiTrackC


Thanks,

Jerry
0
 
LVL 40

Expert Comment

by:Kyle Abrahams
ID: 39284368
cna you post the entire source of
frmPOSLoad and the procedure in question?
0
 

Author Comment

by:JDL129
ID: 39284583
Sorry but I finally just copied the frmPOSLoad code to frmViewRX.  Why did I get the error?  I can't believe it's this hard!  In vb6 and vb.net it is much easier.

Thanks anyway,

Jerry
0
 
LVL 40

Expert Comment

by:Kyle Abrahams
ID: 39294598
VB .Net and C# should be the same, not sure why oyu're getting the error without seeing the relevant code.
0
 

Author Comment

by:JDL129
ID: 39295480
ged325!!  

The called procedure is 2 or 3 pages long and doesn't return a value.

I'm not sure why it would matter what was in the procedure.  All I want to do is to execute the procedure from a different form and then return the execution to the originating form.

Thanks for the post!!

Jerry
0
 

Author Comment

by:JDL129
ID: 39298831
ged325!!

Are we done?

Thanks for the try!!

Jerry
0
 

Author Closing Comment

by:JDL129
ID: 39314963
Thanks!!  I appreciate the time invested!!
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
C# guarantee sql connection close 6 50
How can my static class become undefined?? 8 62
C# Gridview 1 45
Call Controller Action Method from ASPX 2 22
Article by: Najam
Having new technologies does not mean they will completely replace old components.  Recently I had to create WCF that will be called by VB6 component.  Here I will describe what steps one should follow while doing so, please feel free to post any qu…
We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

807 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question