I have a form that runs some code when it's loaded with the following code:
vb Code:
If IO.File.Exists(config_file) Then ' Get Music, Movies and Shows paths from config_file fileMusic_path = IO.File.ReadAllLines(config_file).Where(Function(line) line.ToUpper().StartsWith("[MUSIC_PATH]")).First().Split("="c)(1) fileMovies_path = IO.File.ReadAllLines(config_file).Where(Function(line) line.ToUpper().StartsWith("[MOVIES_PATH]")).First().Split("="c)(1) fileShows_path = IO.File.ReadAllLines(config_file).Where(Function(line) line.ToUpper().StartsWith("[SHOWS_PATH]")).First().Split("="c)(1) ' Set path Textboxes to fileX_path variables txtMusic_Path.Text = fileMusic_path txtMovie_Path.Text = fileMovies_path txtShows_Path.Text = fileShows_path Else txtMusic_Path.Text = "Browse to your Music storage location..." txtMovie_Path.Text = "Browse to your Movies storage location..." txtShows_Path.Text = "Browse to your TV Shows storage location..." End If
The form has three textboxes that contain what is read from config_file. It also has three corresponding browse buttons to browse for new directories, which changes the value of the textboxes. Then there is a Save Settings button that when clicked is suppose to eventually take the value of the textbox and replace the text in config_file with the value of the textbox currently. Basically this is updating the file with the newly browsed directory. Currently for debugging I have a message box appear with the Replace value and the Replace With values, but the Replace value is being changed to the Replace With value so it would just replace something with itself as the values are the same and I don't know why the Replace value is changing. Please help!
Here's the Save Settings button code:
vb Code:
Private Sub btnSaveSettings_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSaveSettings.Click Dim reader As String reader = My.Computer.FileSystem.ReadAllText(config_file) 'If InStr(reader, txtMusic_Path.Text) = 0 Then 'Replace(reader, Music_path, txtMusic_Path.Text) MessageBox.Show(reader & Chr(13) & "Change this: " & txtMusic_Path.Text & Chr(13) & "Today this: " & fileMusic_path) 'End If 'If InStr(reader, txtMovie_Path.Text) = 0 Then 'Replace(reader, Movies_path, txtMovie_Path.Text) MessageBox.Show(reader & Chr(13) & "Change this: " & txtMovie_Path.Text & Chr(13) & "Today this: " & fileMovies_path) 'End If 'If InStr(reader, txtShows_Path.Text) = 0 Then 'Replace(reader, Shows_path, txtShows_Path.Text) MessageBox.Show(reader & Chr(13) & "Change this: " & txtShows_Path.Text & Chr(13) & "Today this: " & fileShows_path) 'End If End Sub
It's as if this code:
vb Code:
' Set path Textboxes to fileX_path variables txtMusic_Path.Text = fileMusic_path txtMovie_Path.Text = fileMovies_path txtShows_Path.Text = fileShows_path
Is changing it.


Reply With Quote


