Menu

Array problem

2007-08-02
2013-05-30
  • Stefano Bonomi

    Stefano Bonomi - 2007-08-02

    Trying to compile and run an old program that needs to be modified, with the latest version of GCBasic  (0.9 28/06/2007), results in trouble with array index; the first element of array is static, in other words not modificable.

    For example:

    ' first of all array declaration
    Dim Array(5)
    ' then a value to array elements
    Array$ = "Hello"
    Array(1) = 32              'first element of array to SPACE character
    locate 1,2
    print Array$               'Hello comes on LCD Display without any modification
    Array(2) = 32             
    locate 1,2
    print Array$               'H llo print out on LCD Display. That's OK

    Using GCBasic version from 10/02/2007 this program works as expected.

    Another problem is that it is not possible to initialize an array to NULL.

    For instance, the following piece of code:

    ' first of all array declaration
    Dim Array(5)
    Array$ = ""                 ' Initialize Array
    .
    .
    Array$ = "12345"            ' New values for Array elements
    locate 1,2
    print Array$

    Has unpredicable result, whereby it works perfectly with GCBasic version from 10/02/2007

    Best regards

    Stefano Bonomi

     
    • Hugh Considine

      Hugh Considine - 2007-08-03

      I'm not sure what caused the first error, but I made some alterations to the handling of arrays in July and this seems to have removed the bug.

      The second error was caused by an issue with the SysReadString routine when copying null strings from program memory. It was passing a bad address to some computed goto code. I've fixed this and changed http://gcbasic.sourceforge.net/newfiles/update.zip .

       
    • Stefano Bonomi

      Stefano Bonomi - 2007-08-03

      Unfortunately with this last update LCD doesn't work anymore (in 2 bit mode for sure, don't know in 4 and 8 bit mode).

      Trying the same simple LCD test program with compiler version from 10/02/2007, it works without any problem......

      Greetings

      Stefano Bonomi

       
    • Stefano Bonomi

      Stefano Bonomi - 2007-08-03

      I forgot to mention that with the penultimate version of UPDATE.ZIP LCD was still working in 2 bit mode.

      I mean the bug appeared in the latest version you posted in your answer to this Thread......

      Best regards

      Stefano Bonomi

       
    • Hugh Considine

      Hugh Considine - 2007-08-04

      Sorry, I made a mistake and replaced STATUS.Z with STATUS.C, without realising that incf does not alter C. This caused more problems with the computed goto code used to read strings.

      I've now fixed update.zip. Also, I've put just the fixed gcbasic.exe in another file, http://gcbasic.sourceforge.net/newfiles/gcbasic-exe.zip - this is a little smaller to download (182 K instead of 593 K).

      One strange thing I noticed was that the LCD would work in 4-bit mode if I reset the PIC while it was initialising the LCD.

       
    • Stefano Bonomi

      Stefano Bonomi - 2007-08-04

      First of all many thanks for your time and effort.
      LCD is fixed now, but the problem with initializing Array to null remain

      i.e.

      Dim Example(5)
      Example$=""

      Produces odd results. (Program go crazy)

      Many greetings

      Stefano Bonomi

       
    • Hugh Considine

      Hugh Considine - 2007-08-04

      Thanks for reporting the bugs, and having the patience to wait while I track them down and attempt to fix them!

      I'm not sure what is causing the trouble with the null string. This program compiles fine for me, and runs as expected:

      #include "mytest.h"

      Dim TestArray(5)
      TestArray$ = ""

      Temp = 0
      Do
      Temp += 1
      Cls
      LCDInt Temp
      Wait 250 ms
      Loop

      I've also tried putting in a print after setting the array to a null string, and that works properly too.

      While I'm certain that I included the fixed system.h in update.zip, it's possible that something went wrong. Perhaps you could try http://gcbasic.sourceforge.net/newfiles/system.h ? I've made a few more alterations to it since to (hopefully) handle null strings when added to other strings.

      If that still doesn't work, could you please email me a copy of the program or post it here?

       
    • Stefano Bonomi

      Stefano Bonomi - 2007-08-10

      All ok now.

      Trying the new system.h you provided me, did the trick.

      I think it is better you replace the old one in update.zip too.

      Compiling this simple test with the old system.h produces flashing "Hello World" text on LCD Display, compiling the same with the new version of the library, works as expected.
      ("Hello World" on LCD Display, then after 5 sec delay, only "World" on the second LCD line, and then loop).

      Thanks a lot for your support

      Stefano Bonomi

      #chip 16F690,8 
      #config _INTRC_OSC_NOCLKOUT, _WDT_OFF,_PWRTE_OFF,_MCLRE_OFF,_CP_OFF, _BOR_OFF, _IESO_OFF,_FCMEN_OFF
      #Define LCD_IO 2
      #Define LCD_DB Porta.0 'Required: pin where Data Bit is wired
      #Define LCD_CB Porta.1 'Required: pin where Clock Bit is wired
      ADOFF
      Dim Array1(5)
      Dim Array2(5)
      do
      Array1$ = "Hello"
      Array2$ = "World"
      CLS
      Locate 0,0
      Print Array1$
      locate 1,0
      print Array2$
      wait 5 s
      CLS
      Array1$ = ""
      locate 1,0
      print Array2$
      wait 5 s
      loop
      end

       

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.