Results 1 to 4 of 4

Thread: [RESOLVED] Why is this variable changing it's value?

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jan 2010
    Location
    San Marcos, TX
    Posts
    177

    Resolved [RESOLVED] Why is this variable changing it's value?

    I have a form that runs some code when it's loaded with the following code:

    vb Code:
    1. If IO.File.Exists(config_file) Then
    2.   ' Get Music, Movies and Shows paths from config_file
    3.   fileMusic_path = IO.File.ReadAllLines(config_file).Where(Function(line) line.ToUpper().StartsWith("[MUSIC_PATH]")).First().Split("="c)(1)
    4.   fileMovies_path = IO.File.ReadAllLines(config_file).Where(Function(line) line.ToUpper().StartsWith("[MOVIES_PATH]")).First().Split("="c)(1)
    5.   fileShows_path = IO.File.ReadAllLines(config_file).Where(Function(line) line.ToUpper().StartsWith("[SHOWS_PATH]")).First().Split("="c)(1)
    6.  
    7.   ' Set path Textboxes to fileX_path variables
    8.   txtMusic_Path.Text = fileMusic_path
    9.   txtMovie_Path.Text = fileMovies_path
    10.   txtShows_Path.Text = fileShows_path
    11.  
    12. Else
    13.   txtMusic_Path.Text = "Browse to your Music storage location..."
    14.   txtMovie_Path.Text = "Browse to your Movies storage location..."
    15.   txtShows_Path.Text = "Browse to your TV Shows storage location..."
    16. 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:
    1. Private Sub btnSaveSettings_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSaveSettings.Click
    2.   Dim reader As String
    3.   reader = My.Computer.FileSystem.ReadAllText(config_file)
    4.   'If InStr(reader, txtMusic_Path.Text) = 0 Then
    5.   'Replace(reader, Music_path, txtMusic_Path.Text)
    6.   MessageBox.Show(reader & Chr(13) & "Change this: " & txtMusic_Path.Text & Chr(13) & "Today this: " & fileMusic_path)
    7.   'End If
    8.   'If InStr(reader, txtMovie_Path.Text) = 0 Then
    9.   'Replace(reader, Movies_path, txtMovie_Path.Text)
    10.   MessageBox.Show(reader & Chr(13) & "Change this: " & txtMovie_Path.Text & Chr(13) & "Today this: " & fileMovies_path)
    11.   'End If
    12.   'If InStr(reader, txtShows_Path.Text) = 0 Then
    13.   'Replace(reader, Shows_path, txtShows_Path.Text)
    14.   MessageBox.Show(reader & Chr(13) & "Change this: " & txtShows_Path.Text & Chr(13) & "Today this: " & fileShows_path)
    15.   'End If
    16. End Sub

    It's as if this code:

    vb Code:
    1. ' Set path Textboxes to fileX_path variables
    2.   txtMusic_Path.Text = fileMusic_path
    3.   txtMovie_Path.Text = fileMovies_path
    4.   txtShows_Path.Text = fileShows_path

    Is changing it.

  2. #2
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    40,106

    Re: Why is this variable changing it's value?

    I'd have to say that this is just a question of the sequence of events. I'd be putting a breakpoint in that first code snippet, then any other code that applies, and stepping through it. I doubt there is enough information shown to say where the problem lies.
    My usual boring signature: Nothing

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Jan 2010
    Location
    San Marcos, TX
    Posts
    177

    Re: Why is this variable changing it's value?

    I figured it out! You're right, the code in question wasn't included. My browse button code was changing it.

    Thanks anyways!

  4. #4
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    40,106

    Re: [RESOLVED] Why is this variable changing it's value?

    That's the best possible answer.
    My usual boring signature: Nothing

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width