|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
How to assign a state to checkbox in Visual Basic.net ?Hi,
I have textfile with True or Flase in it and I need to read this file so that the value is assigned to a checkbox on the form. How can I do that ? Thanks:) Hi,
Assuming that theTrue or False is at the first line of the text file: Dim f As StreamReader Dim s As String f = File.OpenText("C:\yourFilePath\Filename.txt") s = f.ReadLine.Trim If s.Contains("True") Then yourCheckbox.value = True Else yourcheckbox.value = False End If Of course your need to do more validation and exception handeling, to make sure the file exists. Ahmed auror***@gmail.com wrote: Show quoteHide quote > Hi, > > I have textfile with True or Flase in it and I need to read this file > so that the value is assigned to a checkbox on the form. > > How can I do that ? > > Thanks:) "Ahmed" <ahmed1***@gmail.com> schrieb: .... can be simplified as...> If s.Contains("True") Then > yourCheckbox.value = True > Else > yourcheckbox.value = False > End If \\\ YourCheckBox.Value = s.Contains("True") /// -- M S Herfried K. Wagner M V P <URL:http://dotnet.mvps.org/> V B <URL:http://classicvb.org/petition/> Thank you. That works for one checkbox only. But when I say:
While s <> nothing if s="Ttrue" then checkbox1.checked=1 if s="Ttrue" then checkbox2.checked=1 etc End while Then it hangs. How can I do this with more than one checkbox ? Well, it hangs because the program is looping for ever. Why do you need
the while s<> nothing? Do you have only one True in the file? I am assuming your file is formated as such: True True False True .. .. .. Dim f As StreamReader Dim s As String dim counter as integer = 1 f = File.OpenText("C:\yourFilePath\Filename.txt") s = f.ReadLine.Trim While Not s Is nothing select case counter case 1 yourCheckbox1.value = s.Contains("True") case 2 yourCheckbox2.value = s.Contains("True") case 3 yourCheckbox3.value = s.Contains("True") end select s = f.ReadLine.Trim counter +=1 end while I didn't test the code. I hope that help. Ahmed auror***@gmail.com wrote: Show quoteHide quote > Thank you. That works for one checkbox only. But when I say: > > While s <> nothing > > if s="Ttrue" then checkbox1.checked=1 > > if s="Ttrue" then checkbox2.checked=1 > > etc > > End while > > Then it hangs. > > How can I do this with more than one checkbox ? Yea, this time it works as it should
Only now it throws Null Refference Exeption ------------------------------------------------------------------------------------------------------------------------- ...................................... While Not s Is Nothing Select Case counter Case 1 CheckBox1.Checked = s.Contains("True") Case 2 CheckBox2.Checked = s.Contains("True") Case 3 CheckBox3.Checked = s.Contains("True") Case Else s = "1" End Select s = f.ReadLine.Trim - < Hier is null refference exeption > counter += 1End While f.Close() -------------------------------------------------------------------------------- It's like reffered object does not exist anymore :( Any idea how to fix this ? Thanks in advance Trim will only take the extra spaces if any after and before the word.
I am glad that it worked for you. Cheers, Ahmed auror***@gmail.com wrote: Show quoteHide quote > I found the solution! > should have said > > s=f.Readline() > > Thanks
putting a line on my form
simple graphics question Newbie Q: Serialization and Me datetext Help converting C# code to VB Reference to a control, by its name in a String Executing a stored procedure that uses linked server from vb.NET Visual Studio 2005 Pro Dragging a control How to convert windows from VS.2003 to VS2005 |
|||||||||||||||||||||||