Jump to content

Welcome to Geeks to Go - Register now for FREE

Need help with your computer or device? Want to learn new tech skills? You're in the right place!
Geeks to Go is a friendly community of tech experts who can solve any problem you have. Just create a free account and post your question. Our volunteers will reply quickly and guide you through the steps. Don't let tech troubles stop you. Join Geeks to Go now and get the support you need!

How it Works Create Account
Photo

Visual Basic Help


  • Please log in to reply

#1
stettybet0

stettybet0

    Trusted Tech

  • Technician
  • 2,579 posts
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

Edited by stettybet0, 01 April 2007 - 04:28 PM.

  • 0

Advertisements


#2
stettybet0

stettybet0

    Trusted Tech

  • Topic Starter
  • Technician
  • 2,579 posts
nvm. figured it out. :whistling:
  • 0

#3
Tigger93

Tigger93

    Trusted Helper

  • Retired Staff
  • 1,870 posts
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.
  • 0

#4
stettybet0

stettybet0

    Trusted Tech

  • Topic Starter
  • Technician
  • 2,579 posts
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

Edited by stettybet0, 01 April 2007 - 09:06 PM.

  • 0






Similar Topics

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

As Featured On:

Microsoft Yahoo BBC MSN PC Magazine Washington Post HP