473,396 Members | 2,036 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

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:)

Jun 22 '06 #1
7 1462
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
au******@gmail.com wrote:
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:)


Jun 22 '06 #2
"Ahmed" <ah*******@gmail.com> schrieb:
If s.Contains("True") Then
yourCheckbox.value = True
Else
yourcheckbox.value = False
End If


.... can be simplified as...

\\\
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/>
Jun 22 '06 #3

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 ?

Jun 23 '06 #4
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
au******@gmail.com wrote:
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 ?


Jun 23 '06 #5
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 += 1

End While

f.Close()
--------------------------------------------------------------------------------

It's like reffered object does not exist anymore :(

Any idea how to fix this ?

Thanks in advance

Jun 24 '06 #6
I found the solution!
should have said

s=f.Readline()

Thanks

Jun 24 '06 #7
Trim will only take the extra spaces if any after and before the word.

I am glad that it worked for you.

Cheers,

Ahmed
au******@gmail.com wrote:
I found the solution!
should have said

s=f.Readline()

Thanks


Jun 24 '06 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: alien2_51 | last post by:
Can some one tell me why the onclick is firing twice for the radion button and checkbox controls...? <%@ Page Language="vb" AutoEventWireup="false" Codebehind="Testing.aspx.vb"...
1
by: Kb | last post by:
Hi all, I have an asp:checkbox on a form, and i added onclick attribute to it. When the checkbox is clicked I want to add its text to a textbox. But I can't get its text. The checkbox is rendered...
4
by: moondaddy | last post by:
There are different times when I will have a group of checkboxes and need to force only one to be checked at a time. I would also like to do this client side and not require a postback. These...
1
by: mschoup | last post by:
I have a simple aspx page(WebForm1.aspx) with a HyperLink, LinkButton, and two CheckBoxes. When I select a CheckBox and then click the LinkButton, the CheckBox retains state. When I select the...
0
by: Keith | last post by:
I have a repeater control that contains a HeaderTemplate and an ItemTemplate. Each item contains a checkbox with an ID of chkReconciled, and the header contains a single checkbox with an ID of...
0
by: Keith | last post by:
I have a repeater control that contains a HeaderTemplate and an ItemTemplate. Each item contains a checkbox with an ID of chkReconciled, and the header contains a single checkbox with an ID of...
16
by: Dwight | last post by:
If a windows form checkbox control is checked, shouldn't the following equal 1 instead of -1 ? DIM Acndt_ind as integer Acndt_ind = CInt(chbAcndt_Ind.Checked) Thanks
3
by: =?Utf-8?B?dmluY2VudHc1Ng==?= | last post by:
I have an ASP.NET 2.0 application. It is pretty basic. What it does is shows a gridview of data from a stored procedure. The user can also select a date filter. The problem is that sometimes an...
6
by: =?Utf-8?B?RGljaw==?= | last post by:
Please can you tell me how to assign a namespace to a resource file in a Visual Basic project? In C# such resources file inherit their namespace based upon the folder hierarchy in which they are...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.