Retrieving data from a file
Retrieving data from a file
Retrieving data from a file
Retrieving data from a file
Retrieving data from a file
Retrieving data from a file Retrieving data from a file Retrieving data from a file Retrieving data from a file Retrieving data from a file Retrieving data from a file Retrieving data from a file Retrieving data from a file
Retrieving data from a file Retrieving data from a file
Retrieving data from a file
Go Back  Xtreme Visual Basic Talk > > > Retrieving data from a file


Reply
 
Thread Tools Display Modes
  #21  
Old 08-29-2004, 12:45 PM
MKoslof's Avatar
MKoslofRetrieving data from a file MKoslof is offline
Cum Grano Salis

Retired Moderator
* Guru *
 
Join Date: Jul 2002
Location: Baltimore, Maryland
Posts: 14,636
Default


You are making this MUCH harder on yourself. With your current structure

1) You have to read in each line and split out the controls name and its value
2) Then you have to loop the control collection and find the corresponding control that matches the name. Then, you have to assign the bitwise value based on the string value return.

Instead, if a resource file or embedding this type of information scares you off..you can create registry settings. In this key, you could put it in HKCU/Software/YourApp you would create keys to correspond with all your controls. So something like

KeyName: MyCheckBox1
Value: 0

Then, when the program exits you write to this registry keys. Then, when the program first loads, read these keys. Based on the return value of the registry key, check the boxes true or false. So you need no external text and you don't have to write awkward code that has to read in each line find the corresponding control and evaluate the value. Just assign the checkbox value directly from the registry..nothing else needed.

I HIGHLY recommend doing something like this..your current structure is not good design and you are making life very hard on yourself. There is no reason to do this via a text file
__________________
"Artificial Intelligence is no match for natural stupidity." ~unknown
Reply With Quote
  #22  
Old 08-29-2004, 12:57 PM
Dennis DVR's Avatar
Dennis DVRRetrieving data from a file Dennis DVR is offline
Back in the Game

Forum Leader
* Expert *
 
Join Date: Nov 2003
Location: Manila Philippines
Posts: 3,576
Default

you need to save the check box this way
Code:
datResults.WriteLine(chkMsConFig.Checked)

and retrived the value like this
Code:
chkMsConFig.Checked = myReader.ReadLine()
__________________
Avatar by Lebb

[Posting Guidelines] [Standards & Practices Tutorial] [Participate here effectively]
Our knowledge can only be finite, while our ignorance must necessarily be infinite. Karl Popper
Reply With Quote
  #23  
Old 08-29-2004, 03:02 PM
riehmc riehmc is offline
Regular
 
Join Date: Jul 2004
Posts: 95
Default

This program is going to be used on multiple computers so I need something that is simple like a text file. I don't want to be messing with the registry.

I added the .checked to the save part as you can see below but still get the same error about option strict on disallows implicit conversions from 'string' to 'boolean'. Should I turn option strict off?
Code:
datResults.WriteLine(chkMsConFig)

Code:
datResults.WriteLine(chkMsConFig.Checked)
Reply With Quote
  #24  
Old 08-29-2004, 07:23 PM
riehmc riehmc is offline
Regular
 
Join Date: Jul 2004
Posts: 95
Default

This is how my text file looks now. It saves the checkboxes as true or false. But still get same error in program about string to boolean.
Attached Files
File Type: zip text file.zip (164 Bytes, 7 views)
Reply With Quote
  #25  
Old 08-29-2004, 07:24 PM
Dennis DVR's Avatar
Dennis DVRRetrieving data from a file Dennis DVR is offline
Back in the Game

Forum Leader
* Expert *
 
Join Date: Nov 2003
Location: Manila Philippines
Posts: 3,576
Default

you should explcitly convert it to boolean data since VB.NET does not allow implicit convertion when the Option Strict On sure it will work if you will remove the Option Strict but i would suggest to leave it as is.

so instead of having just
Code:
chkMsConFig.Checked = myReader.ReadLine()
you need to do this
Code:
chkMsConFig.Checked = System.Convert.ToBoolean(myReader.ReadLine())
__________________
Avatar by Lebb

[Posting Guidelines] [Standards & Practices Tutorial] [Participate here effectively]
Our knowledge can only be finite, while our ignorance must necessarily be infinite. Karl Popper
Reply With Quote
  #26  
Old 08-29-2004, 07:28 PM
MikeJ's Avatar
MikeJRetrieving data from a file MikeJ is offline
Retread

Retired Moderator
* Expert *
 
Join Date: Sep 2002
Location: Austin, Texas
Posts: 6,747
Default

Also, True is -1, not 1.
__________________
{ Lex Fori } { Locus Classicus } { Rutilus Scrinium }
Osculare pultem meam!
Reply With Quote
  #27  
Old 08-29-2004, 07:56 PM
MKoslof's Avatar
MKoslofRetrieving data from a file MKoslof is offline
Cum Grano Salis

Retired Moderator
* Guru *
 
Join Date: Jul 2002
Location: Baltimore, Maryland
Posts: 14,636
Default

You need to do something like this:

Code:
s = sw.ReadLine bol = CType(s, Boolean) If bol = False Then Me.CheckBox1.Checked = False Else Me.CheckBox1.Checked = True End If

Again, this assumes you have one value on the text file and we then send the value to the check box via a Ctype() declaration. So if you have 10 values and 10 controls, how are you supposed to know what control gets what value? You are going to have to do a lot of extra code and really for no reason I have made several suggestions on how to improve this process..but do what you wish
__________________
"Artificial Intelligence is no match for natural stupidity." ~unknown
Reply With Quote
  #28  
Old 08-29-2004, 11:11 PM
riehmc riehmc is offline
Regular
 
Join Date: Jul 2004
Posts: 95
Default

Ok, I do appreciate all your guys/girls help on this. It has to be close by now. How many years have you all been doing VB?

Still getting an error opening the text file while running the program.

Code:
Private Sub mnuFileOpen_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuFileOpen.Click Dim sFileName As String = Application.StartupPath & ("C:\Documents and Settings\Owner\Desktop\Results.txt") Dim myFileStream As New System.IO.FileStream(sFileName, FileMode.OpenOrCreate, FileAccess.Read, FileShare.Read) 'Create the StreamReader and associate the filestream with it Dim myReader As New System.IO.StreamReader(myFileStream) chkMsconfig.Checked = System.Convert.ToBoolean(myReader.ReadLine()) chkCleanup.Checked = System.Convert.ToBoolean(myReader.ReadLine()) txtHijack.Text = myReader.ReadLine() txtHousecall.Text = myReader.ReadLine() myReader.Close() myFileStream.Close() End Sub Private Sub mnuFileSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuFileSave.Click 'Saves the results to a file Dim datResults As New StreamWriter("C:\Documents and Settings\Owner\Desktop\Results.txt") datResults.WriteLine(chkMsconfig.Checked) datResults.WriteLine(chkCleanup.Checked) datResults.WriteLine(txtHijack.Text) datResults.WriteLine(txtHousecall.Text) datResults.Flush() datResults.Close() End Sub
Reply With Quote
  #29  
Old 08-30-2004, 07:47 AM
Dennis DVR's Avatar
Dennis DVRRetrieving data from a file Dennis DVR is offline
Back in the Game

Forum Leader
* Expert *
 
Join Date: Nov 2003
Location: Manila Philippines
Posts: 3,576
Default

can you explain this
you are opening the "Result.txt" under this directory
Code:
Application.StartupPath & ("C:\Documents and Settings\Owner\Desktop\Results.txt")
and you are saving the "Result.txt" under this directory without the Application.StartupPath
Code:
"C:\Documents and Settings\Owner\Desktop\Results.txt"
__________________
Avatar by Lebb

[Posting Guidelines] [Standards & Practices Tutorial] [Participate here effectively]
Our knowledge can only be finite, while our ignorance must necessarily be infinite. Karl Popper
Reply With Quote
  #30  
Old 08-30-2004, 08:18 AM
MKoslof's Avatar
MKoslofRetrieving data from a file MKoslof is offline
Cum Grano Salis

Retired Moderator
* Guru *
 
Join Date: Jul 2002
Location: Baltimore, Maryland
Posts: 14,636
Default

Cut out all your variables and you don't need a stream, just do:

Code:
Dim sw as StreamReader sw = New StreamReader(Application.StartupPath & "\Results.Txt")
__________________
"Artificial Intelligence is no match for natural stupidity." ~unknown
Reply With Quote
  #31  
Old 08-30-2004, 11:38 PM
riehmc riehmc is offline
Regular
 
Join Date: Jul 2004
Posts: 95
Default

Quote:
Originally Posted by duane
can you explain this
you are opening the "Result.txt" under this directory
Code:
Application.StartupPath & ("C:\Documents and Settings\Owner\Desktop\Results.txt")
and you are saving the "Result.txt" under this directory without the Application.StartupPath
Code:
"C:\Documents and Settings\Owner\Desktop\Results.txt"

are you trying to say I need to write it like this?
Code:
Dim datResults As New StreamWriter = Application.StartupPath & ("C:\Documents and Settings\Owner\Desktop\Results.txt")

It doesn't work
Reply With Quote
  #32  
Old 08-30-2004, 11:44 PM
riehmc riehmc is offline
Regular
 
Join Date: Jul 2004
Posts: 95
Default

Oh okay I got it now

Code:
Dim sFileName As String = ("C:\Documents and Settings\Owner\Desktop\Results.txt") '("C:\Power Tune\Results.txt")

Thanks soooo much, I've been working on this forever. Actually you have, but I appreciate it.
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
Retrieving data from a file
Retrieving data from a file
Retrieving data from a file Retrieving data from a file
Retrieving data from a file
Retrieving data from a file
Retrieving data from a file Retrieving data from a file Retrieving data from a file Retrieving data from a file Retrieving data from a file Retrieving data from a file Retrieving data from a file
Retrieving data from a file
Retrieving data from a file
 
Retrieving data from a file
Retrieving data from a file
 
-->