Visual Basic Help - Geeks to Go Forums

Jump to content

Log in Register Register Malware removal guide How it works

Visual Basic Help

#1 stettybet0

  • Group: Technician
  • Posts: 2,579
  • Joined: 15-June 05

Posted 01 April 2007 - 12:49 PM

First off, I am coding with Visual Basic 2005 Express. I don't know if this is the same as other types as Visual Basic, so just putting that out there.

Does anyone know how to convert a ReadOnlyCollection into a regular Collection? And can Collections be stored in arrays?

The reason I'm doing this is that I'm trying to have a textbox which displays a list of saved games. I have the names of the saved games I want saved in "C:\SavedGames\(name-of-game)\Name.txt. So say a person has 3 saved games, A, B, and C. I want to combine "C:\SavedGames\A\Name.txt", "C:\SavedGames\B\Name.txt", and "C:\SavedGames\C\Name.txt" into a string, and display that string in the textbox. So I have the program search for "C:\SavedGames\*" (the directories) and then it saves them as a ReadOnlyCollection(Of String) named directories. What I want to do is take all "C:\SavedGames\(names-of-directories-found)\Name.txt" files and combine them into one string. I hope I'm not being confusing... Here's some code:

Dim directories As ReadOnlyCollection(Of String)
directories = My.Computer.FileSystem.GetDirectories("C:\SavedGames\", True, "*")
Dim files As ReadOnlyCollection(Of String)
files = My.Computer.FileSystem.GetFiles("C:\SavedGames\" & directories, True, "\Name.txt")
Dim filearray() As String
ReDim filearray(files.count)
filearray(0) = String.Concat(files)
Dim filelist As String
filelist = String.Join(vbCrLf, filearray)
TextBox1.Text = filelist


The only error is in the line "files = My.Computer.FileSystem.GetFiles("C:\SavedGames\" & directories, True, "\Name.txt")". It says "Operator '&' is not defined for types 'String' and 'System.Collections.ObjectModel.ReadOnlyCollection(Of String)'."

Please help in any way you can.

Edit: Also, one unrelated question. I know how to make things respond to clicks and double clicks, but is there anyway to make them respond to triple clicks?

Thanks,
Stettybet0

#2 stettybet0

  • Group: Technician
  • Posts: 2,579
  • Joined: 15-June 05

Posted 01 April 2007 - 07:33 PM

nvm. figured it out. :whistling:

#3 Tigger93

  • Group: Retired Staff
  • Posts: 1,870
  • Joined: 07-October 05

Posted 01 April 2007 - 08:04 PM

Just out of curiosity, how'd you manage to do this, if you don't mind sharing? I've been wondering this myself now for a while.

#4 stettybet0

  • Group: Technician
  • Posts: 2,579
  • Joined: 15-June 05

Posted 01 April 2007 - 08:12 PM

Well, I didn't really answer my own question, rather I just found a better way to do what I wanted (read "better way" as "way that worked").

Dim allFileContents As New List(Of String)
For Each path As String In IO.Directory.GetFiles("C:\SavedGames\", "Name.txt", IO.SearchOption.AllDirectories)
	 allFileContents.AddRange(IO.File.ReadAllLines(path))
Next path
ListBox1.DataSource = allFileContents


Share this topic: