Click here to Skip to main content
15,886,812 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I need to pass arguments from function of one form to function of another form

I am doing something like this

C#
public void GenerateGatewayMessagesPlots(string dataLogFile, string numofBuses, string select1, string select2, string select3, string select4)
       {
           List<GatewayMessageDetails> GWmsgDetailsList = new List<GatewayMessageDetails>();

           GWmsgDetailsList =  new GatewayMsgIDs(dataLogFile).ResponseTimeofMsgs(numofBuses, select1, select2, select3, select4);
           PlotGWMsgsData(GWmsgDetailsList);
       }


But I do not want to create new instance of the form GatewayMsgIDs


C#
new GatewayMsgIDs(dataLogFile).ResponseTimeofMsgs(numofBuses, select1, select2, select3, select4);


Is there some way that I can remove new keyword and pass the arguments to the form

Because when I am using new keyword some parameters are by default going to null in the form GatewayMsgIDs

Is there some way that I can fix this???


Thanks
John
Posted
Updated 13-Mar-14 3:26am
v2
Comments
Krunal Rohit 13-Mar-14 10:14am    
Is is a Forms Application ??

-KR

1 solution

The way for 'passing the arguments to the other form' is calling a method of the other form, of course. That is you have to create a public method in the 'receiving form' in order to accept the parameters from the 'sending' one.
 
Share this answer
 
Comments
Member 10408451 13-Mar-14 9:37am    
Hi,
Yes, I am using public method in the receiving form
There is no problem in passing the arguments
But the problem is that the arguments are going to null by using new keyword
as it creates new instance of class
CPallini 13-Mar-14 9:48am    
Why you have to create the new class? cannot you access the existing one?
Member 10408451 13-Mar-14 9:58am    
When I am writing something like below
GatewayMsgIDs(dataLogFile).ResponseTimeofMsgs(numofBuses, select1, select2, select3, select4);
I am getting some error like below
'SCANLA.GatewayMsgIDs' is a 'type' but is used like a 'variable'

when I am using new keyword then there is no error
CPallini 13-Mar-14 10:03am    
It looks you need to accessing an existing instance of the class, but you are not able to see it inside the moethod. Could you please post more code?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900