[futurebasic] Re: [FB] A little help maybe

Message: < previous - next > : Reply : Subscribe : Cleanse
Home   : June 2014 : Group Archive : Group : All Groups

From: Brian S <fblistserve@...>
Date: Sun, 8 Jun 2014 19:34:12 -0700
On Jun 8, 2014, at 6:57 PM, Brian S <fblistserve@...> wrote:

> 
> On Jun 8, 2014, at 6:42 PM, Brian S <fblistserve@...> wrote:
> 
>> 
>> On Jun 8, 2014, at 4:57 PM, Bill Tomlinson <billtomlinson@...> wrote:
>> 
>>> Dim B$,volrefnum%
>>> Window #1,B$, (1,25)-(600,300)
>>> “line 1” : Open “I”,1, ”TestData.txt”, ,volrefnum
>>> line input #1, B$
>>> print B$
>>> if not eof(1) then goto “line 1”
>>> input b
>>> 
>> '--------------------------
>> include "Util_FileDirectory.incl"
>> 
>> dim as CFURLRef  parentURL
>> dim as Str255 b
>> 
>> // change "SSD1TB" to your hard drive name. The rest is just the path to the file. Don't change "Volumes"
>> fn FD_PathCreateCFURL( @"/Volumes/SSD1TB/Users/brians/Desktop/MyTest/testfile.txt", 0, @parentURL )
>> open "I", 1, parentURL
>> while not eof( 1 )
>> line input #1, b
>> print b
>> wend
> 
> (1) You should close the file when you’re done with it: close #1.
> 
> (2) You could trap any error coming from FD_PathCreateCFURL() by adding an error variable and testing it:
> 
> dim as OSStatus err
> err = fn FD_PathCreateCFURL( @"/Volumes/SSD1TB/Users/brians/Desktop/MyTest/testfile.txt", 0, @parentURL )
> if ( err != _noErr ) then xxxxxxxxxxxxx  // if error, do something
> 
> If you’re just experimenting, the OPEN statement will crash ( actually the runtime code tests for errors and reports them in a dialog - like minus 35 ) if the URL was not successfully created. Testing the 'err' variable is better defensive coding but allowing OPEN to report a problem can work too.

The name 'parentURL' is misleading( I was copying and pasting and forgot to correct the name ). There is no parent URL because we are just hard-coding the full path and converting it to a URL. Feel to change the name to something more appropriate such as simply 'url'. Obviously, a name change has no impact on code operation but less confusion is always better IMO.

Brian