C# how to make the stored file to cap at 100 items? -


I am trying to create a small program that takes input from the user and stores it on file, but I cap that file on 100 elements:

Suppose that the user adds 100 names and the next name the user adds will show that "the list is complete"

here I The code that is so far:

  public form 1 () {InitializeComponent (); } Private string SongName, ArtistName; Public Zero Registry () {List & lt; Name & gt; Music list = new list & lt; Name & gt; (); // Create a list of MusicList.Add (new name (SongName = txtSongName.Text, ArtistName = txtArtistName.Text)); // Add new element in NameClass // Check if input is correct (txtSongName.TextLength & lt; 1 || txtArtistName.TextLength & lt; 1) {Info Info = new info (); Info.Show (); } Else // If the input will be stored in the correct data {// Create a file to store a data. StreamWriter FileSaving = New StreamWriter ("MusicList" is true); {String sName = MusicList [i] .songName for (Int i = 0; I & lt; MusicList.Count; i ++) // To create a new variable to maintain the name string, aName = MusicList [i] .artistName; // Create a new variable to save the file. Write (name + "by"); // Save the file to add SongName FileSaving.WriteLine (aName); // Add ArtistName to save file} FileSaving.Close (); }} Private Zero btnEnter_Click (Object Sender, EventArgs e) {Registry (); // Set the text box to empty so that the user txtArtistName.Text = ""; TxtSongName.Text = ""; } Private Zero btnClose_Click (Object Sender, EventArgs e) {Application.Exit (); }    

  as the area of ​​the class private const int MAX_STORED_SONGS = 100; // (Int i = 0; i & lt; MusicList.Count & i & lt; MAX_STORED_SONGS; i ++) // ... for later loop (MusicList.Count> MAX_STORED_SONGS) error message label .txt = "The list is complete, only 100 items added"   

I'm not sure what your list picker looks like, but you probably have more than 100 using them using some javascript / verification The client side wants to stop selecting the item before submitting the page.

What's not clear about your code, it seems that the user submits a single song, then you create a new empty vocabulary, add a single item, but you loop through it As if there are more than one item, you should start by reading the file to decide how many songs in it, so that you can determine when 100 songs are there.

Comments

Popular posts from this blog

excel vba - How to delete Solver(SOLVER.XLAM) code -

github - Teamcity & Git - PR merge builds - anyway to get HEAD commit hash? -

ios - Replace text in UITextView run slowly -