So I found this code online (usually I do C# however I'm trying to teach smallbasic to a friend of mine) that basically reads a file:
TextWindow.Write("Enter the name of the new directory: ")
DirectoryName = TextWindow.Read()
files = File.GetFiles(DirectoryName)
TextWindow.WriteLine("This is the content in the file: ")
TextWindow.WriteLine(File.ReadContents(files[1]))
I understand what that all does, but why does it need to be files[1]
instead of just files
?
Removing the index [1]
just makes the line not work, the program still compiles and whatnot.
SB doesn't have a debugger and the resources online aren't very good.
According to the API documents, File.GetFiles
returns an array:
If the operation was successful, this will return the files as an array. Otherwise, it will return "FAILED".
You specify an index because it returns an array and File.ReadContents
expects a single instance.
View the API here: http://smallbasic.com/doc/?id=6