Jump to content


Check out our Community Blogs

Register and join over 40,000 other developers!


Recent Status Updates

View All Updates

Photo
- - - - -

Save String <List>

String Save timer combobox streamwriter string

  • Please log in to reply
4 replies to this topic

#1 slava

slava

    CC Newcomer

  • Member
  • PipPip
  • 11 posts
  • Programming Language:Delphi/Object Pascal, Lua
  • Learning:C#, Visual Basic .NET

Posted 31 May 2012 - 09:00 AM

How to keep using the String <list> save dialog?

	    private void button1_Click(object sender, EventArgs e)
	    {
		    if (saveConfig.ShowDialog() != DialogResult.OK)
		    {
			    List<string> configlist = new List<string>();
			    configlist.Add('"' + titleTextBox.Text + '"');
			    configlist.Add('"' + autorTextBox.Text + '"');
			    configlist.Add('"' + saveTextBox.Text + '"');
			    configlist.Add('"' + versionTextBox.Text + '"');
			    configlist.Add('"' + consoleComboBox.SelectedText + '"');
			    configlist.Add('"' + widthTextBox.Text + '"');
			    configlist.Add('"' + heightTextBox.Text + '"');
			    configlist.Add('"' + fullscreenComboBox.SelectedText + '"');
			    configlist.Add('"' + vsyncComboBox.SelectedText + '"');
			    configlist.Add('"' + fsaatextBox.Text + '"');
			    configlist.Add('"' + joystickComboBox.SelectedText + '"');
			    configlist.Add('"' + audiocomboBox.SelectedText + '"');
			    configlist.Add('"' + keyboardCombobox.SelectedText + '"');
			    configlist.Add('"' + eventCombobox.SelectedText + '"');
			    configlist.Add('"' + imagecomboBox.SelectedText + '"');
			    configlist.Add('"' + graphicscomboBox.SelectedText + '"');
			    configlist.Add('"' + timercomboBox.SelectedText + '"');
			    configlist.Add('"' + mousecomboBox.SelectedText + '"');
			    configlist.Add('"' + soundcomboBox.SelectedText + '"');
			    configlist.Add('"' + physicscomboBox.SelectedText + '"');
			    StreamWriter writer = new StreamWriter(saveConfig.FileName);
			    foreach (string s in configlist)
			    {
				    writer.WriteLine(configlist);
			    }
			    writer.Close();
		    }
		    else
		    {
			   
		    }
	    }

This code does not create a file when you save in the dialogue...((
  • 0

#2 lespauled

lespauled

    CC Leader

  • Expert Member
  • PipPipPipPipPipPipPip
  • 1360 posts
  • Programming Language:C, C++, C#, JavaScript, PL/SQL, Delphi/Object Pascal, Visual Basic .NET, Pascal, Transact-SQL, Bash

Posted 31 May 2012 - 09:38 AM

Why all the extra quotes?
  • 0
My Blog: http://forum.codecal...699-blog-77241/
"Women and Music: I'm always amazed by other people's choices." - David Lee Roth

#3 gregwarner

gregwarner

    Obi Wan of Programming

  • Expert Member
  • PipPipPipPipPipPipPip
  • 1586 posts
  • Location:Arkansas
  • Programming Language:C, Java, C++, C#, PHP, Transact-SQL

Posted 31 May 2012 - 10:03 AM

            if (saveConfig.ShowDialog() != DialogResult.OK)
            {
                ...
            }
            else
            {
               // ???
            }
        }


You've written nothing in the area above for the 'else' condition. With the way you've written your if statement, that's where execution jumps when the user clicks the 'Ok' button of the dialog. It's not creating the file because you didn't tell it to.
  • 0

ti-99-sig.png
Hofstadter's Law: It always takes longer than you expect, even when you take into account Hofstadter's Law.
– Douglas Hofstadter, Gödel, Escher, Bach: An Eternal Golden Braid


#4 AceInfinity

AceInfinity

    CC Addict

  • Senior Member
  • PipPipPipPipPip
  • 313 posts
  • Programming Language:C, C++, C#, Perl, Visual Basic .NET, Assembly, VBScript, Others

Posted 03 June 2012 - 01:09 PM

As gregwarner pointed out, the error is with your "!=". I think you need to review your list of operators before advancing. What your code says to me is:

"If the user does not press the OK button to save the file, then add items to the list, then try to save, else, if the user presses the OK button, then, do nothing."

And 2 more things:

1) If you wrap each item in quotes, why not just not add them to each item in the List, then when writing to the file, write each item to the file on a new line, with quotes around the string, through the loop? Makes more sense, plus you're not storing 2 extra quotes in each index of the List...

2) If you don't need these quotes, or you continue to use the same format you've been doing, why not use something like String.Concat or String.Join to join and write the elements of the List to the file all at once? String.Join if you want to concat them with a newline char between each element.
  • 0

Microsoft MVP (2012) - .NET Programming | ®Crestron DMC-T Certified Programmer
Posted Image


#5 Correy

Correy

    CC Lurker

  • New Member
  • Pip
  • 3 posts
  • Location:United Kingdom
  • Programming Language:C#, Visual Basic .NET

Posted 08 June 2012 - 11:17 AM

im new to this but i've seen it alot, how would you come about fetching a string and is it used like an array?
  • 0





Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download