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

Variables

Status
Not open for further replies.

T17Rax

Technical User
Jun 11, 2015
39
GB
I'm learning variables which I think I'm getting the aspect of. I've attempted to write a prg which will change records accordingly and so far it's working.

However, the issue I'm looking at here is there is a field that has two or three different records. For example,

Field Classno contains class numbers, TEACH and VISIT.
Field Freema contains £2.15 for class numbers, £3.00 for TEACH and £5.00 for VISIT.

Now, all the class numbers have £2.15 in the freema field following the program's code but I'm struggling to understand how you would change the Freema records for the TEACH and VISIT records. I can only think of declaring variables again but as far as I can understand and from everything I've read so far, Variables are declared for the 1st record in the field.

Also, the Freema field is numeric, which for the time being is simple to use (So in actual fact, the records don't contain the British pound symbol).

Code:
cd\cashless
SET EXCLUSIVE OFF 
SET SAFETY OFF 

USE classs.dbf 
STORE Freema TO laFrees
UPDATE id SET Freema = laFrees WHERE Freem = "Y" AND Classno <> "TEACH"

The other alternatives I can think of is to use the tables again in different areas/alias names and point to the specific record number? But there, I'd be unsure how to declare the record as a variable.
 
You are clearly getting confused here. What you are trying to achieve has got nothing to do with variables. It is a simple global update of a table.

If I've understood it right, you want to set the Freema field to £3.00 where Classno = "TEACH", and to £5.00 where Clasno = "VISIT". Is that correct?

If so, one way to do it would be like this:

[tt]UPDATE MyTable SET Freema = 3 WHERE ALLTRIM(Classno) = "TEACH"
UPDATE MyTable SET Freema = 5 WHERE ALLTRIM(Classno) = "VISIT"[/tt]

That's not the most efficient way of doing it. It would be better to combine the two commands, perhaps using ICASE() or IIF(). But I've done it with two separate commands because I think it will be easier for you to understand the concept. Start there, and you can build up on it as you progress.

In any case, you certainly don't need to worry about different work areas or aliases. That won't help solve this particular problem.

If I've misunderstood the requirement, perhaps you could clarify what you are trying to achieve.

Mike


__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Regarding your comment about the pound symbol:

If the field in question is numeric, you can display it with a pound symbol (or any other currency symbol) like this:

[tt]? TRANSFORM(Freema, "@$")[/tt]

If it is a field of type currency, it's a bit simpler:

[tt]? TRANSFORM(Freema)[/tt]

The actual symbol is determined by SET CURRENCY.

This doesn't affect how the value is stored (and you are right that you shouldn't actually store the symbol). It just affects how it is displayed.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Thanks Mike.

I spologise if I was unclear in describing what I was trying to achieve.

The table Classs.dbf includes two fields, Classs and Freema. In the field Classs, the classes TEACH and Visit records are stored in there.
In Freema, the amount is £2.15 for those that are in a class, £3.00 for "TEACH" and £5.00 visitors.

The table id.dbf includes two fields, Classno and Freema. In the Field Classno, again the classes, TEACH and Visit records are stored in there.
In Freema, the amount will differ, depending on what "class" (as such) is in Classno.

The value of Freema from the table Classs will reflect on how much a user is supplied with, in the table ID.dbf. If the user is a TEACH, then the user shall get £3.00. If the user is in a class, the user will get whatever the class is valued at, depending on the table classs.dbf.
This is where I came up with the thought of using a variable to store the record from classs.dbf, and update id.dbf, by replacing the records accordingly.

So, in essence id.dbf will use Classs.dbf to update itself following the program by using whatever values Classs.dbf has. I was half-way there haha.

Is this any clearer? I apologise if it wasn't before.

Thanks again.

Anthony.
 
Anthony,

Thanks for clarification. However, this can still be achieved with a single UPDATE command. As before, variables don't come into it.

In summary, you can do it with a command of this general form:

Code:
UPDATE SomeTable ;
   SET Field1 = Expression1, Field2 = Expression2, ....
   FROM SomeOther
   WHERE <a field in SomeTable = a field in SomeOtherTable

I'm about to go into a meeting. If you haven't got it sorted by the time it finishes, I'll try to give you the actual code you need. (But I expect someone else here will do that before I do.) In the meantime, you might like to read the VFP Help topic entitled "UPDATE - SQL Command".

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
OK. Meeting over.

Off the top of my head, I think this is what you need:

Code:
UPDATE ID SET freema = classes.freema FROM Classes WHERE classes.class = id.class

I'm not completely sure if that exactly meets your requirements, but it should be at least part way there.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Hi again Mike,

I've altered the line of code where needed to match the table fields but the result is perfect. It literally is my program all in one line lol.

There's been times where I've tried to run statements with FOR and WHILE (and AND sometimes!) and it's never worked. Not sure where I'm going wrong there but I generally thought that the statement was too long and struggled to understand the execution and so I never bothered with it again.

If you don't mind me asking, do you know of any good sources where I could find help on learning VFP? I know forums are good and useful, the help in FoxPro itself is good to an extent but sometimes it can be hard to understand. I'd very much like to buy a book or something where I can read over things again and again and again and again...

Thanks Mike.

Anthony.
 
Glad my solution was helpful, Anthony.

Regarding books, etc, I wish I could help. The fact is that there is no half-way decent VFP book aimed at newcomers to the language. I wish it was otherwise. I've been asked a hundred times over the years to recommend a good VFP learning resource, but I'm at a loss.

I believe there are some on-line videos available somewhere, but I've no experience of these. I'd also question whether watching someone explain a concept on the screen can ever work as well as having the text in front of you, for you to work through at your own pace. But maybe that's just my personal temperament.

I used to run VFP training courses, and for a while they were very successful, but the demand has fallen away considerably in the last few years, and it is no longer economical to do so. There might still be people doing VFP training, but it will always be an expensive option compared to self-study.

One other possibility might be to look for a book that gives a general introduction to the concepts of programming: not for any particular language, rather the basic ideas. That would help you make a start - not least with things like variables. But, again, I'm afraid I can't suggest any particular title.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Anthony-are you new to programming, or just new to Visual FoxPro? The recommendations are different for the two groups.

Tamar
 
Morning all,

I've looked at Hentezwerke's stuff and it is pretty hard to understand, as useful as they would be (so i've been told!).

Library's are a good option that I may try. Ebay, not so good. I've looked before and they lack synopsis of what the book contains.
I don't want to be buying a book that I'm not going to benefit from.
The last book I read on FoxPro was VFP 5. As helpful as it was for commands in interactive mode (using the command window), it didn't really focus on anything other than generating reports using the gui method. Always helpful to know, but not what I'm after, just yet.

Tamar, I'm new to both programming and FoxPro. I've never written a program before and the closest thing to databases was filling out a table in MS access a good ten years ago. I'd like to learn as much as I possibly could about FoxPro as it could benefit my career!
 
I don't see the point in looking in a library or on eBay. As I said earlier, the book you want doesn't exist. Looking on eBay won't alter that fact.

You say you are new to programming (please don't take this the wrong way, but that fact was fairly obvious from your questions). It is for that reason I suggested you look for a general introduction to programming - rather than to any particular language. The basic ideas of programming - variables, expressions, data types, looping, branching, etc - are universal across all programming languages. It would do you no harm to get a good grasp of those before you delve into Foxpro.

Also, you mentioned that learing Foxpro would benefit your career. You know your own career plans better than I do, but are you aware that the number of firms using Foxpro is going down fairly quickly, and that most jobs in the field now are for people to maintain old systems rather than develop new ones?

But, in any case, good luck with your learning, and be sure to use this forum when you have specific questions.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Yeah I've seen that FoxPro is obsolete now.

Mike Lewis said:
The basic ideas of programming - variables, expressions, data types, looping, branching, etc - are universal across all programming languages. It would do you no harm to get a good grasp of those before you delve into Foxpro.
I'll have a look around about the basics.

Thank you.
 
I didn't say Foxpro is obsolete. Far from it. There are still many firms using it, and many developers working with it. But the numbers are definitely dwindling. Most of the available work is in maintaining old systems rather than developing new ones. And I know from the experience of my own business that far fewer people are being trained in it than was the case just a few years ago. Nevertheless, the product will be around for a good few years to come.

Whether it is a good career choice for you is something you will have to decide for yourself. Just be aware of what the market wants when you make your choices.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Hello!

I'm a little late to the party but here is how I got into it.

I'm quite new to VFP, too and I am still learning something new every day.

What for me was a good start to get into VFP was this website:


It is a step by step video guide to get into VFP basics. And you get to learn a lot about the GUI especially the form designer and so on. It is definetly worth the view. There are 30 Videos in the "free" section with play lengths between a few minutes up to 1 1/2 hours. There are more videos available but you have to pay for them (I think it was about $80). I don't if it's worth the money because I didn't purchase them but I'm still considering it.

Chronologically you are supposed to watch the videos from left to right and row by row (I hope that makes sense). Not all videos are connected to each other, but when they do, they are titled with part 1, part 2, etc...

I hope they are helpful for you as they were for me!

Keep learning!

Sebastian
 
Sebastian,

SebastianK said:
What for me was a good start to get into VFP was this website:


Apologies for the delay in reply. Thanks for linking me to this!Although the videos drag on abit, I managed to get around to it after some time and it's proved helpful!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top