Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

mmmdreg

macrumors 65816
Original poster
Apr 14, 2002
1,393
0
Sydney, Australia
Hey I can code in VB quite fine but I want to do some stuff with RB. So I was wondering, how do I open and read a text file line-by-line, and can I make custom types (private type foo.. etc etc) as I can in vb. Thanks in advance.
 

Thom_Edwards

macrumors regular
Apr 11, 2003
240
0
mmmdreg said:
Hey I can code in VB quite fine but I want to do some stuff with RB. So I was wondering, how do I open and read a text file line-by-line, and can I make custom types (private type foo.. etc etc) as I can in vb. Thanks in advance.

this is straight out of REALbasic's help. this example reads the whole file at once, but there is a TextInputStream.ReadLine that you can Do While NOT TextInputStream.EOF. Here, the GetOpenFolderItem call opens an Open dialog that returns a FolderItem that only allows text files to be chosen. (FolderItems can be of any file type and folders, too, just not in this case.) You can also explicitly set the FolderItem with f=GetFolderItem("yourfile.txt")


Dim f As FolderItem
Dim t As TextInputStream
f=GetOpenFolderItem("text") //file type defined in File Types dialog
If f <> Nil then
t=f.OpenAsTextFile
t.Encoding=Encodings.MacRoman //specify encoding of input stream
EditField1.text=t.ReadAll
t.Close
End if


and yes, you can make custom types, which REALbasic (as well as other languages) refers to as a class. it's just like any other OOP language--you can subclass an existing class or create one from scratch.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.