xsharp.eu • Array Expression or Method in Fillusing
Page 1 of 2

Array Expression or Method in Fillusing

Posted: Mon Aug 12, 2019 10:39 am
by Anonymous
Each Record has 3 contact name fields and associated phone numbers and email addresses - Main, Sales and Rep. I'd like to have a ComboBox filled with the three field values for each record, which changes as the user moves through the records (so the list only ever has a maximum of 3 members). Is this possible? I'm playing around with this code at the moment, and it doesn't work.

Method ContactsList Class DataWindow
Local aRay as Array
aRay := {}
AAdd(aRay, self:server:FIELDGET(#CLCONTACT)) <----CLEMAIL and CLEmail associated
Aadd(aRay, self:server:FieldGet(#SCONTACT)) <---- SEMAIL and SPhone associated
AAdd(aRay, self:server:FIELDGET(#REPCONTACT)) < ------ RepEmail and RepPhone associated
return aRay


What am I doing wrong please. I've used Arrays before, but not in this type of use. Can it be done, and if so how please.

Thanks again.

Array Expression or Method in Fillusing

Posted: Mon Aug 12, 2019 10:54 am
by lumberjack
Hi Jeff,

Code: Select all

Method ContactsList Class DataWindow  
Local aRay as Array
aRay := {}  
AAdd(aRay, {self:server:FIELDGET(#CLCONTACT)) , ;
                     self:server:FieldGet(#SCONTACT) + " - " + ;// <---- SEMAIL and SPhone associated
                     self:server:FIELDGET(#REPCONTACT)}) //    < ------ RepEmail and RepPhone associated
return aRay
What am I doing wrong please. I've used Arrays before, but not in this type of use. Can it be done, and if so how please.
I think the ListBox wants a two dimensional array and uses aRay[1], aRay[2] for value and display fields. Otherwise you will have to use a listview control to emulate the ListBox. You also need to:

Code: Select all

oComboBox:FillUsing(aRay)

Array Expression or Method in Fillusing

Posted: Mon Aug 12, 2019 11:54 am
by BiggyRat
Thanks Johan, maybe I'm doing something wrong? Not unusual for me, as I'm sure you all know...

I changed the code to:

AAdd(aRay, {self:server, self:Server})
AAdd(aRay, {self:Server:FIELDGET(#CLCONTACT), self:Server:FIELDGET(#CLCONTACT)})
AAdd(aRay, {self:Server:FIELDGET(#SCONTACT), self:Server:FIELDGET(#SCONTACT)})
AAdd(aRay, { self:Server:FIELDGET(#REPCONTACT), self:Server:FIELDGET(#REPCONTACT)})

and I get the same error:
ArrayJPG.JPG
ArrayJPG.JPG (23.91 KiB) Viewed 656 times

Array Expression or Method in Fillusing

Posted: Mon Aug 12, 2019 12:22 pm
by lumberjack
Hi Jeff,
BiggyRat wrote:

Code: Select all

AAdd(aRay, {self:server, self:Server}) 
Is this line 4? Does not make sense to have the server in the aRay...
AFAIK you can pass a single or double dimension array into FillUsing, but self:server does not make sense

Array Expression or Method in Fillusing

Posted: Mon Aug 12, 2019 12:30 pm
by BiggyRat
Of course! That has to be it. Thanks very much Johan. I'll give that a try now. I put it there originally to make sure I was on the right server...

Array Expression or Method in Fillusing

Posted: Tue Aug 13, 2019 3:50 am
by lumberjack
Hi Jeff,
Obviously using AAdd() from a purist perspective will have a bit of a speed penalty. You can also just assign the array as follows:

Code: Select all

Method ContactsList Class DataWindow  
Local aRay as Array
aRay := {self:server:FIELDGET(#CLCONTACT) , ;
               self:server:FieldGet(#SCONTACT), ;
               self:server:FIELDGET(#REPCONTACT)}
return aRay
Or if you want the 2 dimensional array:

Code: Select all

aRay := {{self:Server:FIELDGET(#CLCONTACT), self:Server:FIELDGET(#CLCONTACT)}, ;
               {self:Server:FIELDGET(#SCONTACT), self:Server:FIELDGET(#SCONTACT)}, ;
               {self:Server:FIELDGET(#REPCONTACT), self:Server:FIELDGET(#REPCONTACT)}}

Array Expression or Method in Fillusing

Posted: Tue Aug 13, 2019 4:03 am
by BiggyRat
Thanks Johan, unfortunately I still can't get it to work. Using your code, I get this error:
Array Fillusing.JPG
Array Fillusing.JPG (25.26 KiB) Viewed 656 times
I think it's the same error I was getting earlier with my code. What is wrong? All I have done is put a combobox on my form and told it to FillUsing ContactsList. If this helps, I don't know but even though in your example you used Class DataWindow, I tried Class JobInfo - the actual screen the control is on, and self:server returns NULL,,,, How can that be when the Server attached to the JobInfo window IS CLIENTS?

Array Expression or Method in Fillusing

Posted: Tue Aug 13, 2019 4:35 am
by lumberjack
Jeff,
Why is ContactsList part of DataWindow and not JobInfo?
I suggest you change it to METHOD ContactsList() CLASS JobInfo.

Array Expression or Method in Fillusing

Posted: Tue Aug 13, 2019 4:38 am
by BiggyRat
LOL because of your code! :) I've done exactly as you suggested Johan, but same error. I don't get it.

Method ContactsList() Class JobInfo
Local aRay as Array
aRay := {self:server:FIELDGET(#CLCONTACT) , ;
self:server:FIELDGET(#SCONTACT), ;
self:server:FIELDGET(#REPCONTACT)}
return aRay

Array Expression or Method in Fillusing

Posted: Tue Aug 13, 2019 4:40 am
by lumberjack
Jeff,
Also without seeing your JobInfo:Init() code, are you sure you attached the server before you call ContactsList?