Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Replacing more than one field into a table from an array 1

Status
Not open for further replies.

keepingbusy

Programmer
Apr 9, 2000
1,470
GB

Hi

I use the following to create an array:
Code:
DIMENSION scodes(mrecs)
IF file("scodes.dbf")
  SELECT shortcode FROM scodes ORDER BY shortcode ;
    INTO ARRAY scodes
ENDI
On a form, I have placed a listbox and used the forms builder to allow the user to double click on a selection from the listbox populated by the array which then in turn, stores a value into a field in another table. (That works ok).

My question is, how do I create an array with two fields from the table scodes (the fields are called shortcode and codedesc) which will then store the values into another table on selection from the listbox.

I would be grateful for some guidance not the sollution.

Many thanks
Lee
 

Forgot to mention that this may be a question for the Microsoft: VFP - Forms, Classes and Controls. If this is the case, please let me know and I'll ask it there.

Lee
 
Dimention ARRAY scodes(mrecs,2)
SELECT shortcode,codedesc FROM scodes ORDER BY shortcode ;
INTO ARRAY scodes

wjwjr
 

Hi wjwjr

Thanks for the quick response.

I can see now that the list box is populated with two fields as required. When I double click on the listbox, how do I store the values into another table on selection?

The builder only allows one fields (I think).

Lee
 
Im not sure about that - you might could put nodefault in the double click event of the list box and then below it place the values where they go with something like this:
(not tested)
replace {fieldname1} with this.column1.value
replace {fieldname2} with this.column2.value

Look at the FAQ in VFP General - How to create supercombo
This may work better for you
wjwjr
 

Hi wjwjr

Still cant resolve this issue and I've looked at the FAQ you mentioned but I think this more directed at Textbox, CommandButton and Grids.

My initial problem has been resolved but I'm still not sure how to get the second value from the array into the second field of my table.

If anyone can shed some light, I would be grateful.

Lee
 
Hello Lee;

If I understand you correctly and you want to put the values of 2 columns in a list box into a table, if so try this: (untested)

Put the following in the list box double click event

select <<other table>>
replace field 1 with This.List(This.ListIndex,1),;
field 2 with This.List(This.ListIndex,2)
 

Hi Imaginecorp

Madness! I cant believe it was that easy. Mind you, I've not had much use of listboxes with this set up before.

They say it's easy when you know how.

I placed the following code in the dblclick procedure for the listbox:
Code:
replace shortcode with This.List(This.ListIndex,1)
replace codedesc with This.List(This.ListIndex,2)
My sincerest thanks to you (and those who posted on this thread).

Kind regards

Lee [thumbsup]
 
You're better off doing it with a single REPLACE listing both fields than with two in a row. Faster and, in a multi-user situation, less likely to cause contention.

Also, every REPLACE command should include the IN clause to make sure you're replacing in the work area you think you are:

Code:
replace shortcode with This.List(This.ListIndex,1), ;
        codedesc with This.List(This.ListIndex,2) ;
  IN <YourTable>

Tamar
 
Thanks Lee, Glad I could help.
Though on a personal note, I would use a cursor/table rather than an array as the record source. This way when the user selects a row in the listbox the record pointer is positioned on the record selected and now you can replace the other table using the record source Alias and field name... Similar to a grid. I am sure you can do the same with the Array but its a little more complicated.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top