Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

Hi new to the forum and programming with vb2008, hope u can help. :D

 

I have a text document that stores around 200 commands ,each on its own line with a value of either 0 or 1 after them. This determins if that command is ON or OFF.

 

I need to be able to manipulate the on/off values for 5 specific commands using a check box to say "turn this one on" if box is marked. or vice-versa.

 

ie in the text file

 

test_example1 0

test_example4 1

test_example3 1

test_example2 0

test_example9 0

 

 

The 5 commands are not always on the same line in the text file, and this is the only way I could find to make this work. So is there a way i can get this to look for the text inside the file and change its state with a check box?

 

Thanks in advance if anyone can help.

  • Leaders
Posted

I haven't tested this but its the jist of what you need to do: load the file, find what you need to change, change it, and save the file.

Dim lines As String() = System.IO.File.ReadAllLines(filename)

' Loop through lines
For I As Integer = 0 To Lines.Length - 1
   Dim line As String = lines(i)
  
   'Sparate command and value
   Dim parts As String() = line.Trim().Split(new Char() {" "c}, StringSplitOptions.RemoveEmptyEntries)

   'Somewhat validate data
   If parts.Length = 2 Then
       'Check if its what were looking for
       If parts(0) = nameImLookingfor Then
           'Update value
           lines(i) = nameImLookingFor & " " & newValue.ToString()
           Return ' Stop looking
       End If
   End If
Next I

'When done, use File.WriteAllLines to update file.

[sIGPIC]e[/sIGPIC]

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...