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. Enable/disable buttons according to txt file

Enable/disable buttons according to txt file

Scheduled Pinned Locked Moved C#
questiondata-structureshelptutorial
4 Posts 2 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.
  • C Offline
    C Offline
    Casper Hansen
    wrote on last edited by
    #1

    Hello. I this txt file:

    // 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:

    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:

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

    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

    C C 2 Replies Last reply
    0
    • C Casper Hansen

      Hello. I this txt file:

      // 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:

      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:

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

      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

      C Offline
      C Offline
      Christian Graus
      wrote on last edited by
      #2

      Casper Hansen wrote:

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

      I guess you decide that, if you have no data to do it off, you have to define your own rules, surely ?

      Christian Graus Please read this if you don't understand the answer I've given you "also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )

      C 1 Reply Last reply
      0
      • C Christian Graus

        Casper Hansen wrote:

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

        I guess you decide that, if you have no data to do it off, you have to define your own rules, surely ?

        Christian Graus Please read this if you don't understand the answer I've given you "also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )

        C Offline
        C Offline
        Casper Hansen
        wrote on last edited by
        #3

        Yeah I know how to do that, 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:

        // 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:

        // 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
        // Shit

        Or

        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:

        		while ((MonsterSetBaseLine = rds.ReadLine()) != null)
        		{
        
        				// If not then add normal
        				MonsterSetBaseDataArray.Add(MonsterSetBaseLine);
        		 }
        
        		}
        

        You might want to see this video: http://youtube.com/watch?v=yLMDBRms-KU 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

        1 Reply Last reply
        0
        • C Casper Hansen

          Hello. I this txt file:

          // 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:

          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:

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

          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

          C Offline
          C Offline
          Casper Hansen
          wrote on last edited by
          #4
                  // 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..

          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