Think you need to re-visit OOPS concepts. In button click event you have created another object sm and you have set sm.abc by running testMethod. and you have never run SMSMdm.testMethod to set SMSMdm.abc, it wil give error also because you have never initialized SMSMdm.abc.
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
SMSManager sm = new SMSManager();
}
public void sampleArray()
{
}
private void button1\_Click(object sender, EventArgs e)
{
sm.testMethod("82083427", "1122887779", "testmessagetxt");
}
}
class SMSManager
{
public string abc="";
public void testMethod(string MPN, string RPN, string text)
{
SMSModem SMSMdm = new SMSModem();
MessageBox.Show("RPN" + RPN);
abc = RPN; //this isnt wrking
int x = myArray.Length / 5;
for (int i = 0; i < x; i++)
{
string a = myArray\[i, 0\];
if (a == MPN)
{
MessageBox.Show("MODEM NUMBER :"+MPN);
SMSModem SMSM = new SMSModem();
SMSM.SendSms();
}
}
}
class SMSModem
{
public bool SendSms()
{
try
{
//this is not required now
//SMSManager MGR = new SMSManager();
//string num = MGR.abc; //This is not retreiving the value!
//I WANT THAT VALUE TO BE CALLED HERE AND ASSIGN IT TO "num"
string num = **sm**.abc;
MessageBox.Show("RECEIRE" +num);
serialPort1.WriteLine("AT+CMGF=1;+CSCA=\\"+6598540020\\";+CMGS=\\"+65" + num + "\\"\\r\\n");
System.Threading.Thread.Sleep(40);
serialPort1.Write("Test message from coded program");
char\[\] arr = new char\[1\];
arr\[0\] = (char)26; //ascii value of Ctrl-Z
serialPort1.Write(arr, 0, 1);
System.Threading.Thread.Sleep(3000);
string data = serialPort1.ReadExisting();
MessageBox.Show(data);
if (data.IndexOf("OK") != -1)
{
return true;
}
else