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

New to Visual Foxpro 1

Status
Not open for further replies.

EHood

Technical User
Aug 12, 2009
3
US
I am new to Visual Foxpro. I did Foxpro for Dos years ago. I have built a form that displays one record from a database. I have added controls to skip to the next record and skip back. I am using the code

skip
screenname.refresh()

If I go into this form from another form I am using for a menu I get the error object screenname is not found if I do a skip.

Also my old method of adding a record was to

append blank
scatter memvar
create variables to 'get'
gather memvar

In the current century how do I add the command to add a record?
 
When you say - "I have built a form that displays one record from a database"

First question - how are you displaying the record's information?

* In a grid on the form?
* In a variety of text boxes on the form?
* Any other manner?

Good Luck
JRB-Bldr
 
IN VFP the current form can be adressed as THISFORM, not by it's name.

Don't scatter to memvars, you should use the controlsource of controls to set them to the fields of the alias, not to variables. Scatter Memvar is bad, in that it creates varaibels named as the field names and field names have precedence over variable names. So it can be confusing what is what. Avoid that, if you need to scatter, scatter with the NAME clause to a varaible, which then will be a record object having all the fields as properties.

That aside, the way to work with data in foxpro is, as said above, using the controlsource of controls, some controls displaying lists, like listbox, combobox or grid also have a row or recordsource for the whole list.

Take a look at these entry level videos about visual foxpro and rather forget what you learned for DOS:


Bye, Olaf.
 
I'm an oldfashion programmer myself.
My favoutite method of adding records is very simular to Foxbase for Dos.

- Create variables and store blank or certain default values.
- Present these variables as bound textboxes etc.
- Create an "Append" Commandbutton
- When clicked:
- Check for data entry error en give a messagebox with a warning. Set focus to that corresponding textbox and "Return"
- If no erros: Append blank en several repl with variable.

I think this is an easy to understand method.
 
This is built in a variety of text boxes on the form.
 
EHood,

First, welcome to the forum ... and to the world of Visual FoxPro. You're going to find a lot that's different from your DOS days, but I'm sure you'll find it rewarding.

Regarding your form that displays one record at a time. You probably have four "VCR" buttons on the form: one each for First, Previous, Next and Last. You will write code in the Click events of each of those buttons.

In each case, your code should navigate to the appropriate record, and then do a Refresh. You obviously already know that. However, instead of saying ScreenName.Refresh, you need THISFORM.Refresh. THISFORM is a reference to the current form object, that is, the one your code is running from. It helps you make your code generic, by avoiding the need to know the actual form's name.

A couple of points on your navigation code. First, don't make any assumptions about which table is currently selected within the Click event (or any other event). You can't know exactly what the user was doing immediately before clicking the button (they might have been in a different form, for instance), so you can't know which table is selected. For that reason, you should do SELECT SomeTableName before your navigation, or, alternatively, do something like SKIP IN SomeTableName.

Second, you need to take account of end of file and beginning of file. In the Click of your Next button, you could do something like this:

SELECT MyTable
SKIP
IF EOF()
SKIP -1
ENDIF
THISFORM.Refresh

Other people have answered your question about Scatter/Gather, so I won't go into any detail, except to say that this construct is still perfectly valid -- I occasionally use it in certain circumstances. But in general, you should aim to use buffering instead. When you're ready, read about buffering in the Help file.

Hope this is of some interest. Be sure to come back when you've got more questions.

Mike


__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro tips, advice, training, consultancy
Custom software for your business
 
As Olaf said, don't use SCATTER/GATHER. In general, in VFP, you don't want to use any variables that need to exist outside of a single method. When you have that need, use a custom property instead.

In this case, though, you don't need to do that either. Instead, using buffering, one of the capabilities that was added in VFP. Basically, it's a built-in replacement for SCATTER/GATHER that lets you bind controls to fields, but still retain their original values in case the user cancels. Look up buffering in the Help file to see how it works.

Tamar
 
WOW thanks for all the great help. The videos set me on the right path and I will now re-design my project.
 
As Mike and Tamar already did, I should not only have pointed out how to bind controls to table fields, but also how to be able to decide to save the entered values or changes and to cancel them. The solution is buffering, and it's a very basic principle you should learn.

Here's an excellent article about how to use buffering and locking, which are somewhat related in the buffermodes VFP offers:


Bye, Olaf.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top