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 biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Q about set carry 2

Status
Not open for further replies.

Nifrabar

Programmer
Mar 16, 2003
1,343
NL
Hi!
Set carry to field1,field2 works from commandprompt
But trying to implement this in a dataform with using a buffered view fails.
What are the basics for this?
-Bart
 
How many ways are there to append records into a view?

Set Carry doesnt work with either way I try to do it

CLOSE ALL

SET SAFETY off
CREATE DATABASE mydbc1

SET DATABASE TO mydbc1
CREATE TABLE table1 (NAme C(10), zip c(10)) && Adds table to mydbc1
USE table1

APPEND BLANK
REPLACE name WITH [one]
REPLACE zip WITH [111111]
APPEND BLANK
REPLACE name WITH [two]
REPLACE zip WITH [222222]
APPEND BLANK
REPLACE name WITH [three]
REPLACE zip WITH [111111]

SET FILTER TO TRIM(zip)=[111111]
CREATE VIEW zip

CLOSE ALL
CLEAR ALL
SET VIEW TO zip
SET CARRY TO zip
INSERT INTO table1 (NAME) values("FOUR")
CLOSE DATABASES
USE table1
BROWSE && SET CARRY DOES NOT WORK WITH INSERT INTO - SQL
MESSAGEBOX("did not work with insert into command")

SET CARRY TO ZIP
APPEND BLANK
REPLACE NAME WITH [FIVE]
BROWSE && DOESNT CARRY WITH APPEND BLANK
MESSAGEBOX("did not work with append blank command")

APPEND
SCATTER TO aNewRec && Create a new array from the table
&& Fill the array
aNewRec[1]="SIX"

APPEND FROM ARRAY aNewRec
BROWSE && DOESNT WORK THIS WAY EITHER
MESSAGEBOX("did not work with append from array command")
 
Also take a look at ChrisChamberlins comment in
thread #1252-882045
 
Thanks so far,
It seems I have to do as in the pre-windows time.
Copying the current field-values in vars and storing their content in a newly created records....
-Bart
 
Copying the current field-values in vars and storing their content in a newly created records

Take a look at SCATTER NAME if you take this approach. It copies the current record to an object so you've only got to declare a single variable rather than having to have one variable per field.

Geoff Franklin
 
Geoff,
I agree with you that it costs just one var.
But in the other hand it takes some more effort to retrieve the contents from this 'array'.
-Bart
 
But in the other hand it takes some more effort to retrieve the contents from this 'array'.

The Name clause gives us an object not an array. If I'm using the Customer table I can say:
Code:
Local loCust
Scatter name loCust
With loCust
  Insert into customer (cust_id, Company, Contact) ;
    values ("New", .company, .contact)
endwith
Lots less work than having to declare all the memvars to accept the scattered fields and less risky that having to remember which fields went to which members of an array.

Geoff Franklin
 
Geoff,
Thanks, didnot know it's that easy.
Star worth!!
But pls. explain that "New"-value
-Bart
 
You can even simplify the code a little more in VFP 9. It permits you to INSERT INTO Table FROM NAME object. The only thing you have to watch out for is the primary key field. If you've set that up as an auto-incrementing integer, use code like this:

Code:
LOCAL loCust
SCATTER NAME loCust
REMOVEPROPERTY(loCust, "CustID")
INSERT INTO Customer FROM NAME loCust

Tamar
 
Tamar,
Your code does copy all fieldsvalues into th enewrecord though?
I was in fact looking for the 'set carry to field1, field2'
But nevertheless a good point to strip that 'read-only field-value'.

-Bart
 
But pls. explain that "New"-value

As Tamar says, the CustID field is the primary key of the table. If I put the existing value from loCust.CustID into a new record then I'd get an error because of the duplication. I just stuffed "New" in there because there aren't any customers with "New" as an ID code.

Geoff Franklin
 
Geoff,
OK I understand. But for me it was a bit confusing because for primairy key I use to have integers.
-Bart
 
If you only want some fields, try it like this:

Code:
LOCAL loCust
SCATTER NAME loCust FIELDS Company, Contact
INSERT INTO Customer FROM NAME loCust

Tamar
 
Tamar,
Exactly the code I looked for.
Never realised the power of Scatter this way!
-Bart
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top