473,802 Members | 1,937 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1492
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("Tru e") Then
yourCheckbox.va lue = True
Else
yourcheckbox.va lue = 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*******@gmai l.com> schrieb:
If s.Contains("Tru e") Then
yourCheckbox.va lue = True
Else
yourcheckbox.va lue = False
End If


.... can be simplified as...

\\\
YourCheckBox.Va lue = s.Contains("Tru e")
///

--
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.check ed=1

if s="Ttrue" then checkbox2.check ed=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.v alue = s.Contains("Tru e")
case 2
yourCheckbox2.v alue = s.Contains("Tru e")
case 3
yourCheckbox3.v alue = s.Contains("Tru e")
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.check ed=1

if s="Ttrue" then checkbox2.check ed=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.Check ed = s.Contains("Tru e")
Case 2
CheckBox2.Check ed = s.Contains("Tru e")
Case 3
CheckBox3.Check ed = s.Contains("Tru e")
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
3872
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" Inherits="CustomerRelations.Testing" %> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <HTML> <HEAD> <title>Testing</title> <!--
1
11724
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 in html separately, followed by the <label for> tag - that's where the text is. But how to access it? Any help is appreciated.
4
10554
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 checkboxes could be just a group of check boxes across the top of a page, or could be part of a datalist or datagrid. How do I make it so when a use clicks on one checkbox that if another checkbox is checked, it becomes unchecked? Also, is it...
1
2620
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 CheckBox and click the HyperLink (NavigateURL set to WebForm1.aspx), the CheckBox lost it's state. I would assume that this is by design (now that I read ASP.NET in a nutshell) where it describes a HyperLink control action as 'navigates from one...
0
2813
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 chkAll. I simply want to have chkAll be checked if every item in the repeater has its checkbox checked. In the code behind page, I can access the checked property of chkReconciled by doing the following: Dim CurrentCheckBox As CheckBox...
0
2287
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 chkAll. I simply want to have chkAll be checked if every item in the repeater has its checkbox checked. In the code behind page, I can access the checked property of chkReconciled by doing the following: Dim CurrentCheckBox As CheckBox...
16
2222
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
1546
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 error is thrown about getting the data. If I go in and make a change to the .cs file, the application runs fine. The change I make is like insert a space somewhere just to make the file recompile and it works again. What causes this? It...
6
5447
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 stored but in Visual Basic all such resources appear in the project's default namespace. This is fine when there are just a few resources but becomes cumbersome when there are lots.
0
10538
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10305
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10063
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9115
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7598
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6838
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5622
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4270
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3792
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.