Read Only Error File Stream

Post your Gambas programming questions here.
Post Reply
cage
Posts: 123
Joined: Monday 2nd September 2019 5:47am
Location: Phoenix Arizona

Read Only Error File Stream

Post by cage »

Just got the latest update of Gambas 3.14.1 and a program that has worked for years no longer works. When it tries to read a data file I get the file is a read only file error. I checked the files and they are not read only so I am baffled by this error. Here is a copy of the input portion of the program.
  hFile = Open Application.Path &/ "Index.dat" For Input
   If Eof(hFile) = True Then
      Return
   Else
      I = 0 'Set i to 0
      While Not Eof(hFile)

         Line Input #hFile, ProgName
         Line Input #hFile, SeIcon
         Line Input #hFile, Comd
         Line Input #hFile, LineSpace
         BoxName = ProgName
         BoxCmd = Comd
         DisplayPics(I, SeIcon)
         Inc I  'Index by one
      Wend
      Close #hFile

I get the error on the Line BoxName = ProgName
cage
Posts: 123
Joined: Monday 2nd September 2019 5:47am
Location: Phoenix Arizona

Re: Read Only Error File Stream

Post by cage »

I found the answer after doing some research. Seems the old way is no longer supported and a new way that has been there is now the required way to do arrays.

Old Way 3.14.0

Public BoxName[43] As String
Public BoxCmd[43] As String


New Way 3.14.1

Public BoxName As New String[43]
Public BoxCmd As New String[43]


The Later work fine.
User avatar
stevedee
Posts: 518
Joined: Monday 20th March 2017 6:06pm

Re: Read Only Error File Stream

Post by stevedee »

As a general point (and this may be irrelevant in this case) arrays are objects, so need to be declared and instantiated.
Public iArr1 As New Integer[9] 'declare & instantiate
Public iArr2 As Integer[]     'declare only
Public index As Integer

Public Sub Form_Open()
  
  index = 1
  iArr1 = [1, 2, 3, 4, 5]
  TextArea1.Text = iArr1[index]
  
  iArr2 = New Integer[5]     'instantiate
  iArr2 = [9, 8, 7, 6]
  TextArea2.Text = iArr2[index]

End

Public Sub Button1_Click()

  index = 2
  iArr2 = New Integer[12]      'instantiate
  iArr2 = [10, 20, 30]
  TextArea3.Text = iArr2[index]

End
I'm still running 3.14.0 so would be interested to know if this still works on the latest version.
User avatar
cogier
Site Admin
Posts: 1118
Joined: Wednesday 21st September 2016 2:22pm
Location: Guernsey, Channel Islands

Re: Read Only Error File Stream

Post by cogier »

Is this the code as the code shown above has errors?
  Dim hFile As File
  Dim i As Integer
  Dim ProgName, SeIcon, Comd, LineSpace, BoxName, BoxCmd As String

  hFile = Open Application.Path &/ "Index.dat" For Input
  If Eof(hFile) = True Then
    Return
  Else
    I = 0 'Set i to 0
    While Not Eof(hFile)

      Line Input #hFile, ProgName
      Line Input #hFile, SeIcon
      Line Input #hFile, Comd
      Line Input #hFile, LineSpace
      BoxName = ProgName
      BoxCmd = Comd
      DisplayPics(I, SeIcon)
      Inc I  'Index by one
    Wend
    Close #hFile
  End If


I don't get an error with this code.
cage
Posts: 123
Joined: Monday 2nd September 2019 5:47am
Location: Phoenix Arizona

Re: Read Only Error File Stream

Post by cage »

Yea it's basically the same but was declared as a public array outside of the form open code. It's part of a quick launcher program I wrote years ago back with Gambas 3.10. After I got the updated help file I came to see after searching it what the problem was. However you did give me an idea on how to improve the program, thank you sir. I kind of liked the Gnome full screen program but didn't like that you had no control of the order of the icons. I elected to make a smaller version of the menu that you could setup the icons as you saw fit. Mine has the most important, most used first and lesser but used program last. The icons are displayed with corresponding names below. You click on the icon and the program launches. All icons are displayed in a scroll area so you can scroll through them. It was a choice whether to use a global module to pass variables or use the Public statement.
Post Reply