how to Call values from An ARRAY like method. I have some configuration inside an array list. how can i call those values and declare??
-
I have an array list of serial port configuration. i want to call these configuration later in the program. So how can i call the configuration from array ?
using System;
using System.Collections.Generic;
using System.Collections;
using System.Text;
using System.IO;
using System.Windows.Forms;
using System.IO.Ports;
using System.Threading;
using System.ComponentModel;
using System.Data;
using System.Drawing;/// <summary>
/// Summary description for Class1
/// </summary>
public class Class1
{
public Class1()
{
}public ArrayList SerialPortContainer = new ArrayList(); private string config\_file = "C:/achu/config.txt"; private string PhoneNumber; private string ServiceCentre; public bool test() { try { //SerialPort serialPort1 = new SerialPort(); string line; //string file = "C:/achu/config.txt"; TextReader tr = new StreamReader(config\_file); System.IO.StreamReader objReader; objReader = new System.IO.StreamReader(config\_file); int NumberOfLines = 0; while ((line = tr.ReadLine()) != null) { NumberOfLines++; } string\[\] ListLines = new string\[NumberOfLines\]; for (int i = 0; i < NumberOfLines; i++) { ListLines\[i\] = objReader.ReadLine(); //MessageBox.Show(Convert.ToString(ListLines\[i\])); string\[\] values = ListLines\[i\].Split(new char\[\] { '$', '#' }); string\[\] PortSplit = values\[0\].Split(new char\[\] { ':', '#' }); string PortName = PortSplit\[1\]; //\*\*\*\*\*\*\*\*Reading Baud Rate\*\*\*\*\*\*\*\*\* string\[\] BaudSplit = values\[1\].Split(new char\[\] { ':', '#' }); //string BaudRateValue = BaudSplit\[1\]; int BaudRate = Convert.ToInt32(BaudSplit\[1\]); //\*\*\*\*\*\*READING DATA BITS\*\*\*\*\*\*\*\*\*\* string\[\] BitsSplit = values\[2\].Split(new char\[\] { ':', '#' }); int DataBits = Convert.ToInt32(BitsSplit\[1\]); //\*\*\*\*\*\*\*\*READING SIM PHONE NUMBER\*\*\*\*\*\*\*\* string\[\] NumberSplit = values\[3\].Split(new char\[\] { ':', '#' }); PhoneNumber = NumberSplit\[1\];
-
I have an array list of serial port configuration. i want to call these configuration later in the program. So how can i call the configuration from array ?
using System;
using System.Collections.Generic;
using System.Collections;
using System.Text;
using System.IO;
using System.Windows.Forms;
using System.IO.Ports;
using System.Threading;
using System.ComponentModel;
using System.Data;
using System.Drawing;/// <summary>
/// Summary description for Class1
/// </summary>
public class Class1
{
public Class1()
{
}public ArrayList SerialPortContainer = new ArrayList(); private string config\_file = "C:/achu/config.txt"; private string PhoneNumber; private string ServiceCentre; public bool test() { try { //SerialPort serialPort1 = new SerialPort(); string line; //string file = "C:/achu/config.txt"; TextReader tr = new StreamReader(config\_file); System.IO.StreamReader objReader; objReader = new System.IO.StreamReader(config\_file); int NumberOfLines = 0; while ((line = tr.ReadLine()) != null) { NumberOfLines++; } string\[\] ListLines = new string\[NumberOfLines\]; for (int i = 0; i < NumberOfLines; i++) { ListLines\[i\] = objReader.ReadLine(); //MessageBox.Show(Convert.ToString(ListLines\[i\])); string\[\] values = ListLines\[i\].Split(new char\[\] { '$', '#' }); string\[\] PortSplit = values\[0\].Split(new char\[\] { ':', '#' }); string PortName = PortSplit\[1\]; //\*\*\*\*\*\*\*\*Reading Baud Rate\*\*\*\*\*\*\*\*\* string\[\] BaudSplit = values\[1\].Split(new char\[\] { ':', '#' }); //string BaudRateValue = BaudSplit\[1\]; int BaudRate = Convert.ToInt32(BaudSplit\[1\]); //\*\*\*\*\*\*READING DATA BITS\*\*\*\*\*\*\*\*\*\* string\[\] BitsSplit = values\[2\].Split(new char\[\] { ':', '#' }); int DataBits = Convert.ToInt32(BitsSplit\[1\]); //\*\*\*\*\*\*\*\*READING SIM PHONE NUMBER\*\*\*\*\*\*\*\* string\[\] NumberSplit = values\[3\].Split(new char\[\] { ':', '#' }); PhoneNumber = NumberSplit\[1\];
[Cannot understand the question clearly]...hmmm..Ok if you want to access those array values in the ATTest() method,declare those array variables as global variables i mean at class level not inside the method Test().
"Don't worry if it doesn't work right. If everything did, you'd be out of a job." (Mosher's Law of Software Engineering)
-
I have an array list of serial port configuration. i want to call these configuration later in the program. So how can i call the configuration from array ?
using System;
using System.Collections.Generic;
using System.Collections;
using System.Text;
using System.IO;
using System.Windows.Forms;
using System.IO.Ports;
using System.Threading;
using System.ComponentModel;
using System.Data;
using System.Drawing;/// <summary>
/// Summary description for Class1
/// </summary>
public class Class1
{
public Class1()
{
}public ArrayList SerialPortContainer = new ArrayList(); private string config\_file = "C:/achu/config.txt"; private string PhoneNumber; private string ServiceCentre; public bool test() { try { //SerialPort serialPort1 = new SerialPort(); string line; //string file = "C:/achu/config.txt"; TextReader tr = new StreamReader(config\_file); System.IO.StreamReader objReader; objReader = new System.IO.StreamReader(config\_file); int NumberOfLines = 0; while ((line = tr.ReadLine()) != null) { NumberOfLines++; } string\[\] ListLines = new string\[NumberOfLines\]; for (int i = 0; i < NumberOfLines; i++) { ListLines\[i\] = objReader.ReadLine(); //MessageBox.Show(Convert.ToString(ListLines\[i\])); string\[\] values = ListLines\[i\].Split(new char\[\] { '$', '#' }); string\[\] PortSplit = values\[0\].Split(new char\[\] { ':', '#' }); string PortName = PortSplit\[1\]; //\*\*\*\*\*\*\*\*Reading Baud Rate\*\*\*\*\*\*\*\*\* string\[\] BaudSplit = values\[1\].Split(new char\[\] { ':', '#' }); //string BaudRateValue = BaudSplit\[1\]; int BaudRate = Convert.ToInt32(BaudSplit\[1\]); //\*\*\*\*\*\*READING DATA BITS\*\*\*\*\*\*\*\*\*\* string\[\] BitsSplit = values\[2\].Split(new char\[\] { ':', '#' }); int DataBits = Convert.ToInt32(BitsSplit\[1\]); //\*\*\*\*\*\*\*\*READING SIM PHONE NUMBER\*\*\*\*\*\*\*\* string\[\] NumberSplit = values\[3\].Split(new char\[\] { ':', '#' }); PhoneNumber = NumberSplit\[1\];
Using a field in the class, like myConfigArray? If you have to use it in another class think about using static fields that are public. Regards Sebastian
It's not a bug, it's a feature! Check out my CodeProject article Permission-by-aspect. Me in Softwareland.
-
I have an array list of serial port configuration. i want to call these configuration later in the program. So how can i call the configuration from array ?
using System;
using System.Collections.Generic;
using System.Collections;
using System.Text;
using System.IO;
using System.Windows.Forms;
using System.IO.Ports;
using System.Threading;
using System.ComponentModel;
using System.Data;
using System.Drawing;/// <summary>
/// Summary description for Class1
/// </summary>
public class Class1
{
public Class1()
{
}public ArrayList SerialPortContainer = new ArrayList(); private string config\_file = "C:/achu/config.txt"; private string PhoneNumber; private string ServiceCentre; public bool test() { try { //SerialPort serialPort1 = new SerialPort(); string line; //string file = "C:/achu/config.txt"; TextReader tr = new StreamReader(config\_file); System.IO.StreamReader objReader; objReader = new System.IO.StreamReader(config\_file); int NumberOfLines = 0; while ((line = tr.ReadLine()) != null) { NumberOfLines++; } string\[\] ListLines = new string\[NumberOfLines\]; for (int i = 0; i < NumberOfLines; i++) { ListLines\[i\] = objReader.ReadLine(); //MessageBox.Show(Convert.ToString(ListLines\[i\])); string\[\] values = ListLines\[i\].Split(new char\[\] { '$', '#' }); string\[\] PortSplit = values\[0\].Split(new char\[\] { ':', '#' }); string PortName = PortSplit\[1\]; //\*\*\*\*\*\*\*\*Reading Baud Rate\*\*\*\*\*\*\*\*\* string\[\] BaudSplit = values\[1\].Split(new char\[\] { ':', '#' }); //string BaudRateValue = BaudSplit\[1\]; int BaudRate = Convert.ToInt32(BaudSplit\[1\]); //\*\*\*\*\*\*READING DATA BITS\*\*\*\*\*\*\*\*\*\* string\[\] BitsSplit = values\[2\].Split(new char\[\] { ':', '#' }); int DataBits = Convert.ToInt32(BitsSplit\[1\]); //\*\*\*\*\*\*\*\*READING SIM PHONE NUMBER\*\*\*\*\*\*\*\* string\[\] NumberSplit = values\[3\].Split(new char\[\] { ':', '#' }); PhoneNumber = NumberSplit\[1\];