I have a small application in Win Form, that takes data entered by a user and places it into a comma separated text file.
I want to be able to load that data back into the application when it is started on the next occasion.
The data is taken from 5 text boxes which are generated by the user and the program. So the txt file looks like this:
123, 12345, ABC ABC, 00:00:10, ABC ABC
124, 12345, ABC ABC, 00:00:15, ABC ABC
The values change depending on what is entered by the user - however, only the FIRST entry is required to be unique - the others can and often will be repeats.
So I have used:
	
	
	
	
	
	
	
	
	
		
			
			
			
			
			
		
	
	
	
		
	
	
		
	
To create a list, and then used the following code to decide how to proceed:
	
	
	
	
	
	
	
	
	
		
			
			
			
			
			
		
	
	
	
		
	
	
		
	
Once I have the count, I have then written a number of IF statements that follow this logic:
	
	
	
	
	
	
	
	
	
		
			
			
			
			
			
		
	
	
	
		
	
	
		
	
This works, but it requires me to do this twelve times for twelve sets of text boxes (the last TextBox is HoldS12) - and that means that by the time I get to the last one, I will have an else if statement that is longer than the entire programs code combined.
I am quite new at this and just thought perhaps there was a better way than repeating code over and over again. I mean this works, but I can't imagine it is a good way to do it.
	
		
			
		
		
	
				
			I want to be able to load that data back into the application when it is started on the next occasion.
The data is taken from 5 text boxes which are generated by the user and the program. So the txt file looks like this:
123, 12345, ABC ABC, 00:00:10, ABC ABC
124, 12345, ABC ABC, 00:00:15, ABC ABC
The values change depending on what is entered by the user - however, only the FIRST entry is required to be unique - the others can and often will be repeats.
So I have used:
			
				C#:
			
		
		
		List<string> lines = File.ReadAllLines("../../../txtFile.txt").ToList();
	To create a list, and then used the following code to decide how to proceed:
			
				C#:
			
		
		
		int sizeoflist;
sizeoflist = lines.Count();
	Once I have the count, I have then written a number of IF statements that follow this logic:
			
				C#:
			
		
		
		if (sizeoflist == 1)
            {
                string[] entries = lines[0].Split(',');
                HoldS1.Text = entries[0].ToString();
                HoldC1.Text = entries[1].ToString();
                HoldP1.Text = entries[2].ToString();
                HoldT1.Text = entries[3].ToString();
                desctbox1.Text = entries[4].ToString();
            }
            else if (sizeoflist == 2)
            {
                string[] entries = lines[0].Split(',');
                string[] entries2 = lines[1].Split(',');
                HoldS1.Text = entries[0].ToString();
                HoldC1.Text = entries[1].ToString();
                HoldP1.Text = entries[2].ToString();
                HoldT1.Text = entries[3].ToString();
                desctbox1.Text = entries[4].ToString();
                HoldS2.Text = entries2[0].ToString();
                HoldC2.Text = entries2[1].ToString();
                HoldP2.Text = entries2[2].ToString();
                HoldT2.Text = entries2[3].ToString();
                desctbox2.Text = entries2[4].ToString();
            }
	This works, but it requires me to do this twelve times for twelve sets of text boxes (the last TextBox is HoldS12) - and that means that by the time I get to the last one, I will have an else if statement that is longer than the entire programs code combined.
I am quite new at this and just thought perhaps there was a better way than repeating code over and over again. I mean this works, but I can't imagine it is a good way to do it.