Struggling
Struggling
Struggling
Struggling
Struggling
Struggling Struggling Struggling Struggling Struggling Struggling Struggling Struggling
Struggling Struggling
Struggling
Go Back  Xtreme Visual Basic Talk > > > Struggling


Reply
 
Thread Tools Display Modes
  #21  
Old 05-10-2011, 03:41 AM
PlausiblyDamp's Avatar
PlausiblyDampStruggling PlausiblyDamp is offline
Ultimate Contributor

Forum Leader
* Expert *
 
Join Date: Nov 2003
Location: Newport, Wales
Posts: 2,058
Default


Quote:
Now what? If you told me the next line, I could work the rest out for myself.
The next line would be to split ioLines based on vbCrLf.
__________________
Intellectuals solve problems; geniuses prevent them.
-- Albert Einstein

Posting Guidelines Forum Rules Use the code tags
Reply With Quote
  #22  
Old 05-10-2011, 08:50 AM
henry0811 henry0811 is offline
Newcomer
 
Join Date: May 2011
Posts: 15
Default

Like this?

StringArray = ioLines.Split("no" & vbLf & "yes")
Reply With Quote
  #23  
Old 05-10-2011, 09:01 AM
henry0811 henry0811 is offline
Newcomer
 
Join Date: May 2011
Posts: 15
Default

So I have this...

Dim ioFile As New StreamReader("C:\Users\Gaming\Desktop\t.txt")
Dim ioLines As String ' Going to hold whole file
Dim StringArray(2) As String 'This is probably wrong?

ioLines = ioFile.ReadToEnd

ioFile.Close()

Going off Gruff's pseudo-code..

StringArray() = ioLines.Split("no" & vbLf & "yes") 'Gives me an error on StringArray()

For Each line In StringArray
If ComboBox9.Text = "Yes" Then
If ioLines = "no" Then ioLines = "yes"
ElseIf ComboBox9.Text = "no" Then
If ioLines = "yes" Then ioLines = "no"
End If
Next line

StringArray = ioLines 'Errors

Dim writer As New StreamWriter("C:\Users\Gaming\Desktop\t.txt")
writer.WriteLine(ioLines) 'Writes tot he file but nothing changes
writer.Close()
Reply With Quote
  #24  
Old 05-10-2011, 09:25 AM
henry0811 henry0811 is offline
Newcomer
 
Join Date: May 2011
Posts: 15
Default

Managed to do it another way, with GetFiles, thanks for the help any guys.
Reply With Quote
  #25  
Old 05-10-2011, 11:15 AM
Gruff's Avatar
GruffStruggling Gruff is offline
Bald Mountain Survivor

Retired Moderator
* Expert *
 
Join Date: Aug 2003
Location: Oregon, USA - deceased
Posts: 6,440
Default

Henry,

It is obvious that you are not reading the suggested material or VB.NET Help where the Split Method is explained. You need to learn to use the help that are provided. If you need someone to explain the wording of the documentation let us know.

Also be aware that since everyone here volunteers their time it is normal that a response may take a while. Sometimes a day or more.
__________________
Burn the land and boil the sea
You can't take the sky from me


~T
Reply With Quote
  #26  
Old 05-10-2011, 12:15 PM
PlausiblyDamp's Avatar
PlausiblyDampStruggling PlausiblyDamp is offline
Ultimate Contributor

Forum Leader
* Expert *
 
Join Date: Nov 2003
Location: Newport, Wales
Posts: 2,058
Default

Quote:
Originally Posted by henry0811 View Post
Managed to do it another way, with GetFiles, thanks for the help any guys.
I can't help but ask - how does GetFiles solve the problem? GetFiles tells you what files are in a folder - as far as I remember it doesn't load a file, change a value in the file based on the contents of a ComboBox and then save the file back again...
__________________
Intellectuals solve problems; geniuses prevent them.
-- Albert Einstein

Posting Guidelines Forum Rules Use the code tags
Reply With Quote
  #27  
Old 05-10-2011, 06:30 PM
Gruff's Avatar
GruffStruggling Gruff is offline
Bald Mountain Survivor

Retired Moderator
* Expert *
 
Join Date: Aug 2003
Location: Oregon, USA - deceased
Posts: 6,440
Default

I hear you. BTW PD. Outside of Educating beginners is there some reason you did not suggest:

System.IO.File.ReadAllLines(<FileName>)
and
System.IO.File.WriteAllLines(<FileName>)

Instead of filestreaming?
__________________
Burn the land and boil the sea
You can't take the sky from me


~T
Reply With Quote
  #28  
Old 05-10-2011, 07:27 PM
PlausiblyDamp's Avatar
PlausiblyDampStruggling PlausiblyDamp is offline
Ultimate Contributor

Forum Leader
* Expert *
 
Join Date: Nov 2003
Location: Newport, Wales
Posts: 2,058
Default

Nothing more than force of habit and a failure to search msdn properly - I had a suspicion there was a method to do that but I just assumed it was part of the StreamReader class (after all that is where all the other string based methods are).
__________________
Intellectuals solve problems; geniuses prevent them.
-- Albert Einstein

Posting Guidelines Forum Rules Use the code tags
Reply With Quote
  #29  
Old 05-11-2011, 10:22 AM
Gruff's Avatar
GruffStruggling Gruff is offline
Bald Mountain Survivor

Retired Moderator
* Expert *
 
Join Date: Aug 2003
Location: Oregon, USA - deceased
Posts: 6,440
Default

There is also readallbytes() and readalltext()
I find the name spaces in the IO section disorganized. 'Directory' is Separate from 'Path'. 'File' has read writes. FileInfo is not in Directory, Etc...
__________________
Burn the land and boil the sea
You can't take the sky from me


~T
Reply With Quote
  #30  
Old 05-11-2011, 11:12 AM
AtmaWeapon's Avatar
AtmaWeaponStruggling AtmaWeapon is offline
Fabulous Florist

Forum Leader
* Guru *
 
Join Date: Feb 2004
Location: Austin, TX
Posts: 9,500
Default

Quote:
Originally Posted by Gruff View Post
There is also readallbytes() and readalltext()
I find the name spaces in the IO section disorganized. 'Directory' is Separate from 'Path'. 'File' has read writes. FileInfo is not in Directory, Etc...
I think there's some disorganization, but the goal of many of those changes was to put common actions in a place where newbies would find them.

Which rolls off the tongue better when you want to write many lines to a file?
Code:
File.WriteAllLines(fileName, lines)

' OR

Using writer As New StreamWriter(fileName)
    For Each line As String In lines
        writer.WriteLine(line)
    Next
End Using
That's why you've got read/writes on File. It's a heck of a lot easier to File.ReadAllText() than call the StreamReader constructor, ReadToEnd(), then make sure you Close() even if an exception is thrown.

I am curious about your ideas for better alternatives though. Here's the points I'm confused by:
Quote:
'Directory' is separate from 'Path'
A Directory is a filesystem object that contains other filesystem objects. A Path is a string that represents the location of a filesystem object. Two different concepts. If Directory had all of Path's methods, wouldn't it be confusing to write code like this:
Code:
Dim fileName As String = "wizards.txt"
Dim appData As String = Environment.GetFolderPath(<appdata>)
Dim filePath As String = Directory.Combine(appData, fileName)
How does combining a directory result in a file path? I suppose it could be called "CombinePath()", but in OOP when you find yourself naming methods like that you're finding evidence of the need for a new class. If you have to say, "This method isn't for directories but for paths" then it shouldn't be in a class for directories.

Quote:
FileInfo is not in Directory
Directory and File are classes that have only static members, so there's no way for Directory to return File objects since you cannot create instances. These shared classes always expect to receive a string that represents the path to the object they will represent. DirectoryInfo and FileInfo are the instance counterparts to these and will return each other. FileInfo.Directory returns a DirectoryInfo, DirectoryInfo.GetFiles() returns FileInfo objects, etc.

I don't like this design and wish MS had picked one or the other. I'm pretty sure they did it so you wouldn't have to create a new object to do a quick check to see if something exists:
Code:
If Not Directory.Exists(path) Then
    Directory.Create(path)
End If

' vs.

Dim dir As New DirectoryInfo(path)
If Not dir.Exists Then
    dir.Create()
End If
But it turns out in common usage it's just not that big of a deal. This stuff was designed pre-.NET 1.0 though, so they hadn't learned what hurt in the framework yet. We're stuck with it forever.

Either way I think the OP split. Odds are he went to some other forum and got a copypasta answer. That only works so far.
__________________
.NET Resources
My FAQ threads | Tutor's Corner | Code Library
I would bet money 2/3 of .NET questions are already answered in one of these three places.
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
Struggling
Struggling
Struggling Struggling
Struggling
Struggling
Struggling Struggling Struggling Struggling Struggling Struggling Struggling
Struggling
Struggling
 
Struggling
Struggling
 
-->