Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. 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??

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??

Scheduled Pinned Locked Moved C#
questiongraphicsdata-structurestutorialworkspace
4 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    Aghosh Babu
    wrote on last edited by
    #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\];
    
    S S N 3 Replies Last reply
    0
    • A Aghosh Babu

      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\];
      
      S Offline
      S Offline
      Spunky Coder
      wrote on last edited by
      #2

      [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)

      1 Reply Last reply
      0
      • A Aghosh Babu

        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\];
        
        S Offline
        S Offline
        SeMartens
        wrote on last edited by
        #3

        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.

        1 Reply Last reply
        0
        • A Aghosh Babu

          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\];
          
          N Offline
          N Offline
          Najmal
          wrote on last edited by
          #4

          hiii First Option: Pass The Array to the function... Second Option: Declare The Arryas as "Class" Private Members.....

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups