Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Enable/disable buttons according to txt file

Status
Not open for further replies.

leprogrammer

Programmer
Mar 21, 2008
25
0
0
DK
Hello.

I this txt file:
Code:
// Comment
2
0	0	20	177	185	4	// comment 
0	0	20	75	65	4	// hi!!
0	0	20	85	65	4	// asd
0	0	20	95	65	4	// (bbb
end

Where I divide the data into valid and unvalid lines

All the data is saved into an array

The valid data is:
Code:
0	0	20	177	185	4	// comment 
0	0	20	75	65	4	// hi!!
0	0	20	85	65	4	// asd
0	0	20	95	65	4	// (bbb

And the unvalid data is:
Code:
// Comment
2
end


I go through the array using two buttons:
Forward and previous

I have a int variable called currentLineNumber which contains the selected line from the array

When pressing forward the currentLineNumber is increased and decreased when pressing previous


My problem is that I need to enable and disable these two buttons on a certain point

For example if I am on the line
Code:
0	0	20	95	65	4	// (bbb

I want to disable the forward button since there is no valid data after that line

My question is:
How do I enable/disable these buttons when I reach the end of valid data?

Hope you understand otherwise just ask
 
I wouldn't disable the buttons. instead just validate the current line before processing
Code:
if(currentLineNumber != 0)
{
   DisplayDataFor(array[--currentLineNumber]);
}
Code:
if(currentLineNumber != array.length - 1)
{
   DisplayDataFor(array[++currentLineNumber]);
}

Jason Meckley
Programmer
Specialty Bakers, Inc.
 
disabling the button is a useful visual cue to the user that there are no more records in that direction.

if the click event just does nothing what does that mean? are there no more records or is the process not working? how many times do you have to click the button before you realise it's the former?

next question: forms or asp?

mr s. <;)

 
Im using forms with visual C#

I know how to do a if where it checks if the array/text file is in the end, but the problem is that there can be some unvalid data and I dont know how to enable/disable if the data is unvalid

The text file is not the same all the time. The user can change it

So it could look like this:
Code:
// Comment
2
0	0	20	177	185	4	// (If any)
0	0	20	75	65	4	// (If any)
0	0	20	85	65	4	// (If any)
0	0	20	95	65	4	// (If any)
0	0	20	15	65	4	// (If any)
0	0	20	55	65	4	// (If any)
0	0	20	91	65	4	// (If any)
end

Or this:
Code:
// Comment
2
0	0	20	177	185	4	// (If any)
0	0	20	75	65	4	// (If any)
0	0	20	85	65	4	// (If any)
0	0	20	95	65	4	// (If any)
0	0	20	15	65	4	// (If any)
0	0	20	55	65	4	// (If any)
0	0	20	91	65	4	// (If any)
end
// End of this
// Stuff

Or
Code:
2
0	0	20	91	65	4	// (If any)
end
// No this is the end

If we take the last example the only valid data is 0 0 20 91 65 4 // (If any), so I want to disable the forward and previous button since there is no valid data to go to


I thought of an example where I looped the whole array and searched for a valid data, but couldn seem to figure it out


Here is how I read my text file:
Code:
			while ((MonsterSetBaseLine = rds.ReadLine()) != null)
			{

					// If not then add normal
					MonsterSetBaseDataArray.Add(MonsterSetBaseLine);
			 }

			}

You might want to see this video:

You can see there are two buttons (forward and previous) where I go through the text file

So if the data is unvalid I skip it and go to the next valid data

Now if there is no valid data left in the text file I want to disable the forward button


Hope you understand my long post
 
why dont u read check the length of each line you read from a file before copying to an array, using readline.
That way u can always check the lenght of each line and may even choose to read it into an array depending on lenght
 
So you would suggest using the length of the lines in the array?

One thing I must do is save ALL data in the array since I write to my file later on, so the lines have to fit to the array
 
just after reading each line using readline, from the file, you check if the lenght is greater than 1 and then do what u want depending on the lenght.
like:
while (!rd.EndOfStream)
{
string str = rs.readline();
if (trim(str).lenght > 1)
//read into array, write to another file, and anything
else
//to do when line is less than one

hope this helps.
 
Code:
            // Current lines left in the array
            // Adding + 1 so it wont take the current line
            linesLeft = currentLineNumber + 1;

            // Looping through the rest of the lines from my array.Count
            for (int i = linesLeft; i < MonsterSetBaseDataArray.Count; i++)
            {
                // Check if the line is valid
                // CheckIf will return true or false (bool)
                checkIf(Convert.ToString(MonsterSetBaseDataArray[i]));

                // If the data is valid
                if (checkIfStatus == true)
                {
                    // Stop the for
                    break;
                }

            }

Here is what I got so far on my next / forward button

I thought of doing it like this:
If one of the remaining lines in the array is valid, the button will not be disabled, but if there is no valid lines left the button will be disabled.

I just couldn figure out the last part

Any ideas on this?

I know how to disable the button, but I dont know when to do it.

I disable my button like this:
nxtButton.Enabled = false;

Hope you can help, because im beginning to get desperate..
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top