[Gambas-user] Problem with Exist & Open functions with filename containing spaces

John Rose john.aaron.rose at ...626...
Thu Mar 12 13:11:08 CET 2015


On 12/03/15 11:38, Tobias Boege wrote:
> On Thu, 12 Mar 2015, John Rose wrote:
>> On 12/03/15 10:37, Tobias Boege wrote:
>>> Public Sub Main()
>>>   Dim sPath As String = Temp$("with spaces")
>>>   Dim hFile As Stream
>>>   Dim sLine As String
>>>
>>>   File.Save(sPath, "some string")
>>>
>>>   Debug "Path =";; sPath
>>>   Debug "Exist =";; Exist(sPath)
>>>   Debug "Content ="
>>>   hFile = Open sPath For Input
>>>   For Each sLine In hFile.Lines
>>>     Debug "  "; sLine
>>>   Next
>>>   Close #hFile
>>> End
>> I've tried that program and it didn't display anything in the Console
>> window. I was not able to compile the attached Test app with Debug as
>> when I tried to add the gb.debug component (by clicking its checkbox
>> which did put an x in it) using Project Properties, it did not enable
>> the OK button. When I closed the Project Properties window & reopened
>> it, the checkbox was not marked with an x. So I put in Print statements
>> and it did not even show their results on the Console window when I ran
>> the Test app.
>>
> The attached file was a Gambas script. You could (and should) have run it
> as-is. Your project is a GUI one where you blindly put the code in a Form's
> class file. But my code had a Main() procedure which is already implemented
> in the Form class. You have incorrectly overridden that implementation by
> inserting my Main() procedure (which was made for a script or console
> application).
>
>> BTW I think that the 'File or Directory does not exist'
>> window appears because I have a 'Catch' followed by
>> 'Message.Warning(ERROR.Text)' in the coding of the relevant Sub. Is it
>> possible to show the line number when the Catch 'catches'? I've also
>> tried putting Breakpoints in my app but that didn't help.
> To clarify: what shows the error? A message box or a popup? Because you said
> it was a popup (which I picture as a Balloon or tooltip-like window) and now
> you conjecture your Message.Warning() call may be it. But if it was a popup,
> as I picture it, it cannot be caused by a Message.Warning().
>
> You get the error line with Error.Where. You could also leave the Catch out
> and let the IDE display the error by itself. The IDE is good enough at that.
>
> Regards,
> Tobi
>
A better name for what I called a popup is a dialog window with just an
Ok button. It is caused by the Message command, because when I comment
out the Catch & Message lines in  my app it does not appear. However,
the IDE (by itself) does not display any error then. Using my previously
quoted code, the 'plain out' file does not exist (though it is present
in my home directory).

Using the code below in the attached Test app when using the IDE, when I
click the Run button, a popup appears stating 'File or Directory does
not exist at line 34' which is 'hFile = Open sPath For Input'. 
 Public Sub RunButton_Click()
  Dim sPath As String = User.Home &/ "plain out"
  Dim hFile As Stream
  Dim sLine As String
  Print "sPath='" & sPath & "'"
  Print "*******"
  Debug "Path =";; sPath
  Debug "Exist =";; Exist(sPath)
  Debug "Content ="
  hFile = Open sPath For Input
  For Each sLine In hFile.Lines
    Print sLine
    Debug " "; sLine
  Next
  Close #hFile
End


Therefore, I think that there is either a problem with using Debug->Run
or commands such as 'Opening a filename containing spaces' when using
the IDE. BTW I'm using Gambas 3.6.2 'supplied' by the Gambas Stable
Launchpad Ubuntu ppa.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Test.tar.gz
Type: application/gzip
Size: 9097 bytes
Desc: not available
URL: <http://lists.gambas-basic.org/pipermail/user/attachments/20150312/6f135882/attachment.gz>


More information about the User mailing list