Page 1 of 1

Multiple array is giving me problems (SOLVED)

Posted: Mon Dec 14, 2020 9:34 am
by Marc Venken
It should be easy, but .....

The code reads the XML, and is giving me a correct Xbrowse with the data

Writing it to dbf is a problem. Tried also with FW_arraytodbf
What do I miss here ??

Is there somewhere a post on multiply arrays explanations ? I have find some...


I get this error

Application
===========
Path and name: C:\Programmas\fotoselect\TEST.EXE (32 bits)
Size: 5,078,016 bytes
Compiler version: Harbour 3.2.0dev (r2008190002)
FiveWin version: FWH 20.08
C compiler version: Borland/Embarcadero C++ 7.0 (32-bit)
Windows version: 6.2, Build 9200

Time from start: 0 hours 2 mins 41 secs
Error occurred at: 14/12/2020, 10:28:42
Error description: Error DBFCDX/1020 Data type error: HEXCODE
Args:
[ 1] = U

Stack Calls
===========
Called from: .\TEST1.PRG => XMLREADER( 12166 )
Called from: .\TEST1.PRG => (b)BUILDMENU( 5745 )
Called from: .\source\classes\MENU.PRG => TMENU:COMMAND( 1556 )
Called from: .\source\classes\WINDOW.PRG => TWINDOW:COMMAND( 1141 )
Called from: .\source\classes\MDIFRAME.PRG => TMDIFRAME:COMMAND( 272 )
Called from: => TMDIFRAME:HANDLEEVENT( 0 )
Called from: .\source\classes\WINDOW.PRG => _FWH( 3559 )
Called from: => WINRUN( 0 )
Called from: .\source\classes\WINDOW.PRG => TMDIFRAME:ACTIVATE( 1097 )
Called from: .\TEST1.PRG => MAIN( 71 )

System
======

Code: Select all

function Xmlreader()
   local aMail:={},nTel:= 1, i
   local hFile    := FOpen( "c:\programmas\fotoselect\kleuren.xml"  )
   Local oXmlDoc  := TXmlDocument():New( hFile )
   Local oXmlIter := TXmlIterator():New( oXmlDoc:oRoot ), oTagActual
   //FW_XmlView( hFile )

   nTel = 1
   while .T.
      oTagActual = oXmlIter:Next()
      If oTagActual != nil
         //if oTagActual:cName = "item"
         //   aadd(aMail,oTagActual:cData)
         //endif
         if oTagActual:cName = "colorHex"
           cHex = oTagActual:cData
           do while .t.
             oTagActual = oXmlIter:Next()
             If oTagActual != nil
               if oTagActual:cName = "dutch"
                  cdd = oTagActual:cData //+ " : "+cHex
                  aadd(aMail ,{cdd,cHex} )
                  nTel++
                  exit
               endif
             endif
           enddo
         endif
      Else
         Exit
      Endif
   End
   aStruct := {}
   AADD(aStruct, { "kleuren", "C", 70, 0 }) // Id
   AADD(aStruct, { "hexcode", "C", 10, 0 }) // Id

  DbCreate( "shopcolor.dbf", aStruct)
  use shopcolor NEW

  xbrowser(aMail)

  for i = 1 to len(aMail)
     ckleur = amail[i,1]
     cHex = aMail[i,2]
     shopcolor->(dbappend())
     shopcolor->kleuren = cKleur
     shopcolor->hexcode = Chex
  next

   xbrowser("shopcolor")

   FClose( hFile )
   close all

return nil

 

Re: Multiple array is giving me problems

Posted: Mon Dec 14, 2020 10:10 am
by Antonio Linares
Marc,

fields assignment must use ":="

shopcolor->kleuren := cKleur
shopcolor->hexcode := Chex

Re: Multiple array is giving me problems

Posted: Mon Dec 14, 2020 11:14 am
by Enrico Maria Giordano
Antonio Linares wrote:Marc,

fields assignment must use ":="

shopcolor->kleuren := cKleur
shopcolor->hexcode := Chex
It's not true. In that context, the two operators = and := are equivalent.

EMG

Re: Multiple array is giving me problems

Posted: Mon Dec 14, 2020 11:47 am
by Marc Venken
I'm almost positive that the array is the problem

aMail and his 2 dimensions

Re: Multiple array is giving me problems

Posted: Mon Dec 14, 2020 12:03 pm
by Antonio Linares
Enrico Maria Giordano wrote:
Antonio Linares wrote:Marc,

fields assignment must use ":="

shopcolor->kleuren := cKleur
shopcolor->hexcode := Chex
It's not true. In that context, the two operators = and := are equivalent.

EMG
Enrico,

It works because the alias is specified. Remove the alias and it will fail.

Re: Multiple array is giving me problems

Posted: Mon Dec 14, 2020 12:06 pm
by Marc Venken
Antonio Linares wrote:Marc,

fields assignment must use ":="

shopcolor->kleuren := cKleur
shopcolor->hexcode := Chex
Same error...

Re: Multiple array is giving me problems

Posted: Mon Dec 14, 2020 12:09 pm
by Antonio Linares
Marc,

It fails because the field "hexcode" is type char and you are assigning it a nil value:

aadd( aMail ,{ cdd, If( cHex == nil, "", cHex ) } )

Re: Multiple array is giving me problems

Posted: Mon Dec 14, 2020 12:13 pm
by Marc Venken
Antonio Linares wrote:Marc,

It fails because the field "hexcode" is type char and you are assigning it a nil value:

aadd( aMail ,{ cdd, If( cHex == nil, "", cHex ) } )
Indeed... This solved my problem and i think other problems I had before also. Never thinking of a NIL value..

Thank You !!

Re: Multiple array is giving me problems

Posted: Mon Dec 14, 2020 1:39 pm
by Enrico Maria Giordano
Antonio Linares wrote:Enrico,

It works because the alias is specified. Remove the alias and it will fail.
No, without the alias it won't work (= or := is the same) because it's referring to a MEMVAR variable and not to the DBF field.

EMG

Re: Multiple array is giving me problems (SOLVED)

Posted: Mon Dec 14, 2020 3:34 pm
by Antonio Linares
Enrico,

? fieldname

shows the field contents if exists

Re: Multiple array is giving me problems (SOLVED)

Posted: Mon Dec 14, 2020 3:47 pm
by Enrico Maria Giordano
Yes, but please try this sample. It doesn't write the value to the field.

Code: Select all

#include "Fivewin.ch"


FUNCTION MAIN()

    USE CUSTOMER

    ? last

    last := "TEST"

    ? last

    RETURN NIL
EMG

Re: Multiple array is giving me problems (SOLVED)

Posted: Mon Dec 14, 2020 5:14 pm
by Antonio Linares
Dear Enrico,

You are right