Read Only Error File Stream

Post

Posted
Rating:
#1 (In Topic #336)
Avatar
Regular
cage is in the usergroup ‘Regular’
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.

Code (gambas)

  1.   hFile = Open Application.Path &/ "Index.dat" For Input
  2.    If Eof(hFile) = True Then
  3.       Return
  4.    Else
  5.       I = 0 'Set i to 0
  6.       While Not Eof(hFile)
  7.  
  8.          Line Input #hFile, ProgName
  9.          Line Input #hFile, SeIcon
  10.          Line Input #hFile, Comd
  11.          Line Input #hFile, LineSpace
  12.          BoxName[I] = ProgName
  13.          BoxCmd[I] = Comd
  14.          DisplayPics(I, SeIcon)
  15.          Inc I  'Index by one
  16.       Wend
  17.       Close #hFile
I get the error on the Line BoxName = ProgName
Online now: No Back to the top

Post

Posted
Rating:
#2
Avatar
Regular
cage is in the usergroup ‘Regular’
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

<COLOR color="#0000FF">Public BoxName[43] As String
Public BoxCmd[43] As String
</COLOR>

New Way 3.14.1

<COLOR color="#0000FF">Public BoxName As New String[43]
Public BoxCmd As New String[43]
</COLOR>


The Later work fine.
Online now: No Back to the top

Post

Posted
Rating:
#3
Avatar
Regular
stevedee is in the usergroup ‘Regular’
As a general point (and this may be irrelevant in this case) arrays are objects, so need to be declared and instantiated.

Code (gambas)

  1. Public iArr1 As New Integer[9] 'declare & instantiate
  2. Public iArr2 As Integer[]     'declare only
  3.  
  4. Public Sub Form_Open()
  5.  
  6.   index = 1
  7.   iArr1 = [1, 2, 3, 4, 5]
  8.   TextArea1.Text = iArr1[index]
  9.  
  10.   iArr2 = New Integer[5]     'instantiate
  11.   iArr2 = [9, 8, 7, 6]
  12.   TextArea2.Text = iArr2[index]
  13.  
  14.  
  15. Public Sub Button1_Click()
  16.  
  17.   index = 2
  18.   iArr2 = New Integer[12]      'instantiate
  19.   iArr2 = [10, 20, 30]
  20.   TextArea3.Text = iArr2[index]
  21.  
  22.  

I'm still running 3.14.0 so would be interested to know if this still works on the latest version.
Online now: No Back to the top

Post

Posted
Rating:
#4
Avatar
Guru
cogier is in the usergroup ‘Guru’
Is this the code as the code shown above has errors?

Code (gambas)

  1.   Dim hFile As File
  2.   Dim ProgName, SeIcon, Comd, LineSpace, BoxName, BoxCmd As String
  3.  
  4.   hFile = Open Application.Path &/ "Index.dat" For Input
  5.   If Eof(hFile) = True Then
  6.     Return
  7.   Else
  8.     I = 0 'Set i to 0
  9.     While Not Eof(hFile)
  10.  
  11.       Line Input #hFile, ProgName
  12.       Line Input #hFile, SeIcon
  13.       Line Input #hFile, Comd
  14.       Line Input #hFile, LineSpace
  15.       BoxName = ProgName
  16.       BoxCmd = Comd
  17.       DisplayPics(I, SeIcon)
  18.       Inc I  'Index by one
  19.     Wend
  20.     Close #hFile
  21.   End If

I don't get an error with this code.
Online now: No Back to the top

Post

Posted
Rating:
#5
Avatar
Regular
cage is in the usergroup ‘Regular’
 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.
Online now: No Back to the top
1 guest and 0 members have just viewed this.