[Gambas-user] Object array code gives weird results

Jose J. Rodriguez joe1962 at ...626...
Fri May 19 01:12:19 CEST 2006


The weirdest things happen to me in Gambas, lol. This is in 1.9.29
(patched). From the info and examples I've managed to search out, this
seems correct and it does work (to a point). I have the following
module and a Form1 with a TextView1 component. There are 2 classes
(see at the bottom). The funny thing is that the line:

 Form1.TextView1.Text &= "<br>" & PartInfo[pcounter - 1].Device

works perfectly in the main parsing loop:

/dev/hda1
/dev/hda2
/dev/hda4
/dev/hda5
/dev/hda6
/dev/hda7

 but the later loop:

   FOR n = 0 TO PartInfo.Max
      Form1.TextView1.Text &= "<br>" & PartInfo[n].Device
   NEXT

just gives this:

/dev/hda7
/dev/hda7
/dev/hda7
/dev/hda7
/dev/hda7
/dev/hda7


Here's the code, as you will see, only the device is being parsed so
far, the rest is filler data until someone helps me figure out what is
wrong ;).

Regards,
Joe1962



' Gambas module file

   'Drive and partition declarations:
   PUBLIC DiskInfo AS NEW Object[]
   PUBLIC PartInfo AS NEW Object[]


PUBLIC SUB Main()
   Form1.Show
   DrivePartInfo
END


PUBLIC SUB DrivePartInfo()
   DIM sTemp AS String

   'Get available drives and partitions:
   EXEC ["fdisk", "-l"] TO sTemp
   Parse_fdisk(sTemp)

END


PUBLIC SUB Parse_fdisk(sTemp AS String)
   DIM vDI AS NEW CDiskInfo
   DIM vPI AS NEW CPartInfo
   DIM arrTemp1 AS NEW String[]
   DIM arrTemp2 AS NEW String[]
   DIM pos AS Long
   DIM n AS Long
   DIM pcounter AS Long

   arrTemp1 = Split(sTemp, Chr$(10))

   FOR n = 0 TO arrTemp1.Max
      pos = InStr(arrTemp1[n], "/dev/")
      IF pos = 1 'Parse a partition.
         arrTemp2 = Split(arrTemp1[n], Space$(1), "", TRUE)
         INC pcounter
         vPI.Device = arrTemp2[0]
         vPI.Bootable = FALSE
         vPI.StartBlock = 0
         vPI.EndBlock = 1024
         vPI.Blocks = 25
         vPI.ID = "06"
         PartInfo.Push(vPI)
         Form1.TextView1.Text &= "<br>" & PartInfo[pcounter - 1].Device
      END IF
   NEXT

   FOR n = 0 TO PartInfo.Max
      Form1.TextView1.Text &= "<br>" & PartInfo[n].Device
   NEXT

END



CDiskInfo.class:
' Gambas class file
PUBLIC Device AS String
PUBLIC Bytes AS Long



CPartInfo.class:
' Gambas class file
PUBLIC Device AS String
PUBLIC Bootable AS Boolean
PUBLIC StartBlock AS Long
PUBLIC EndBlock AS Long
PUBLIC Blocks AS Long
PUBLIC ID AS String




More information about the User mailing list