FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour Creating an array list for a Combobox
Posts: 2706
Joined: Fri Oct 07, 2005 01:50 PM
Creating an array list for a Combobox
Posted: Mon Apr 02, 2012 11:05 PM
To all

I would think this exercise was fairly straight forward but has not turned out that way .. I have a table I want to read an Employee name into an array then use that array with the ITEMS clause to be able to chose my name in a ComboBox.

Unfortunately, when I create the array and use it like ITEMS aTech .. the computer GPFs and I do not know why .. Here is a portion of my code.

Please let me know what I am doing wrong ?

Thanks
Rick Lipkin

Code (fw): Select all Collapse
// create the Tech pull down array

cSql := "Select [First Name], [Last Name], [Service Calls], [Shop Repairs],[Employee Number] "
cSql += "From Employees Order by [First Name]"

oRsEmp := TOleAuto():New( "ADODB.Recordset" )
oRsEmp:CursorType     := 1        // opendkeyset
oRsEmp:CursorLocation := 3        // local cache
oRsEmp:LockType       := 3        // lockoportunistic

TRY
   oRsEmp:Open( cSQL,xCONNECT )
CATCH oErr
   MsgInfo( "Error in Opening EMPLOYEES table" )
*   _CleanUP()
   RETURN(.F.)
END TRY

aTech := {}
aLine := { "Blank" }
AAdd( aTech, aLine )

xBrowse( aTech )

If oRsEmp:eof
Else
   oRsEmp:MoveFirst()
   Do While .not. oRsEmp:eof

      If oRsEmp:Fields("Shop Repairs"):Value  = .t. .or.;
         oRsEmp:Fields("Service Calls"):Value = .t.
      Else
         oRsEmp:MoveNext()
         Loop
      Endif

      If empty( oRsEmp:Fields("First Name"):Value )
         cFname := "Unknown"
      Else
         cFname := alltrim(oRsEmp:Fields("First Name"):Value)
      Endif
      If empty( oRsEmp:Fields("Last Name"):Value )
         cLname := "Unknown"
      Else
         cLname := alltrim(oRsEmp:Fields("Last Name"):Value)
      Endif

      cName := cFname+" "+cLname

      aLine := { cName }
      AAdd( aTech, aLine )

      oRsEmp:MoveNext()

   End Do
Endif

oRsEmp:CLose()

xBrowse( atech ) // array is created corectly

...
...

cTech := space(50)

REDEFINE COMBOBOX oTech  var cTech   ID 127 of oWorkB  ;
               ITEMS aTech
Posts: 811
Joined: Tue May 06, 2008 04:28 AM
Re: Creating an array list for a Combobox
Posted: Tue Apr 03, 2012 12:28 AM
Dear Rick,

i'm not sure if this will work on you but in my case it does.

after redefining the combobox,

Code (fw): Select all Collapse
...
oTech:SetItems( aTech /*{'item1', 'item2', 'item3'}*/, .F. /*to avoid executing bChange on oDlg Init */)
cTech := oTech:aItems[ 1 ]
...
Kind Regards,

Frances



Fivewin for xHarbour v18.07

xHarbour v1.2.3.x

BCC 7.3 + PellesC8 ( Resource Compiler only)

ADS 10.1 / MariaDB

Crystal Reports 8.5/9.23 DE

xMate v1.15
Posts: 368
Joined: Sun May 31, 2009 06:25 PM
Re: Creating an array list for a Combobox
Posted: Tue Apr 03, 2012 01:08 AM
Hi Rick,

The way you create aTech results in an array of arrays { { "Blank" }, {cName1}, {cName2} ...} when it should be {"Blank",cName1,cName2...}

Why don´t you use a where clause in you SQL statment to avoid the next code? Is it not possible with ADO?

Code (fw): Select all Collapse
    If oRsEmp:Fields("Shop Repairs"):Value  = .t. .or.;
         oRsEmp:Fields("Service Calls"):Value = .t.
      Else
         oRsEmp:MoveNext()
         Loop
      Endif
Regards,



André Dutheil

FWH 13.04 + HB 3.2 + MSVS 10
Posts: 2706
Joined: Fri Oct 07, 2005 01:50 PM
Re: Creating an array list for a Combobox
Posted: Tue Apr 03, 2012 01:27 PM
To All

As I often seem to do is make something more difficult than it actually is .. after studing the way I was creating the array .. I realized I was creating multiple elements in a single record instead of only a single element per record.

This code works just fine .. Thanks to everyone who responded to my thread!

Rick Lipkin


Code (fw): Select all Collapse
aTech := {}
AAdd( aTech, "          " )

If oRsEmp:eof
Else
   oRsEmp:MoveFirst()
   Do While .not. oRsEmp:eof

      If oRsEmp:Fields("Shop Repairs"):Value  = .t. .or.;
         oRsEmp:Fields("Service Calls"):Value = .t.
      Else
         oRsEmp:MoveNext()
         Loop
      Endif

      If empty( oRsEmp:Fields("First Name"):Value )
         cFname := "Unknown"
      Else
         cFname := alltrim(oRsEmp:Fields("First Name"):Value)
      Endif
      If empty( oRsEmp:Fields("Last Name"):Value )
         cLname := "Unknown"
      Else
         cLname := alltrim(oRsEmp:Fields("Last Name"):Value)
      Endif

      cName := cFname+" "+cLname

      AAdd( aTech, cName )

      oRsEmp:MoveNext()

   End Do
Endif

oRsEmp:CLose()

..
..

REDEFINE COMBOBOX oTech  var cTech   ID 127 of oWorkB  ;
               ITEMS aTech

Continue the discussion