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

Container

Status
Not open for further replies.

realm174

Programmer
Jan 3, 2002
154
CA
Howdy!

Ok, I'm stumped... I have an application all put together that reads some information out a text file and acts upon what it reads. For the most part, it all goes well. A little more details tho. The text file contains incident information on the status of different area of a car. Each area of the car is broken down in sections. So you'd have "left front" "left side" "left rear", same thing on the right side, etc...

Each area can have 4 states: slightly, moderately or severely damaged, or removed.

Through the course of reading the file, the status of the car section can go from slightly to moderately or severely damaged. What I want to remember at the end, is the "worse" state of that body part.

Where this gets complicated, is that the text file has the report for many different cars (numbered), and the status of the body part is not grouped in any way. So you could have the status of the left front of car 1, followed by the status of right rear of car 7, then the rear of car 1, etc...

My main programming backgroud is Turbo Pascal, and unfortunately, that's how my brain thinks :) And in TP, I'd just create an array of records, and modify the array as I go.

I can't figure out how to do that in FPD.

Any help will be highly appreciated!

thanks!



Cheers,

Realm174
 
When you read the information from the text file you must be putting it SOMEWHERE. Perhaps into memory variables?

Anyway, wherever you have the information (data) you can then put it into and a multi-dimentional array like in TP, if you wish, or better yet into a data table (database).

If you wanted to use an array to dynamically analyze the data you can by creating the Array. Look at your Foxpro Help file for DIMENSION With it you create a new array or re-dimension an existing one.

Obviously since an array is comprised of memory elements, it is only good during the execution of the program and has no lasting value for a subsequent program execution.

To put the data into a table you first need to create a table to store the information into.

Look at your Foxpro Help file for CREATE TABLE
It will give you the general syntax.

Something like:
CREATE TABLE MyTable (car C(25),;
problem C(20),;
etc.)

This does not have to be done programmatically within your application. You can create them in Foxpro's Command Window, save them to disk, and then USE them in your program when you need them.

Or, if you have already created a table, you can USE it, SELECT it, then add new records to it to hold the new data.

SELECT MyTable
APPEND BLANK && Create new blank record
REPLACE field1 WITH newDat1, field2 WITH newDat2, ...

If you use tables the data is saved into a file on the disk and it can be referenced and used at a subsequent program execution.

If you choose to use tables you should give a good deal of thought to how you want to "architect" the data tables so that you can best normalize the data and make it most efficient.

Also think of how you want the user to interface with your application. What functionality do you want to provide? That may need to be reflected in how you create the tables.

One last comment, why are you going to do this project in FPD? If any of the non-Visual Foxpro's I would recommend Foxpro 2.6 for Windows. At least that will have the application appearing and operating as though it was developed somewhere in the 20th century.

While the simplicity of your task might not require it, for a 21st century approach you might want to consider VFP 6, 7, or 8. The learning curve is greater, but the options available to it are quite extensive. And, unlike the non-Visual versions, Micro$oft has not yet made it obsolete.

Good Luck,


JRB-Bldr
VisionQuest Consulting
Business Analyst & CIO Consulting Services
CIOServices@yahoo.com
 
Howdy! Thanks for the detailled response.

The main reason why I'm doing this in FPD is because it's already in FPD. So I'm just trying to fix something that's broke.

As for moving to the 21st century I'm getting there... slowly... I have been trying to find some documentation (sortof "learn VFP in 21 days/weeks/months") kinda book, but it seems that no book/computer stores around here have them. I could most likely buy them online, but I like to see the book before I buy it, so that I have an idea if I'll be able to learn from it or not. I did find one online at some point, (Special Edition Using Visual FoxPro 6) but I can't quite get my head around the differences between DOS and visual Foxpro.

All this being said, the way the application works now is that it's calculating the cost of damage each time it sees one of the line from the text file. So say for example that minimal damage is worth 2000$ and medium is 5000$, and it sees that there is 2 lines with medium damage and 3 lines with minimal, it SHOULD count it as only 1 time $5000, which is the worse of the two. Right now, it's making it $16000, which is the sum of them all. The way it's doing it, is that it's updating a field (called damage cost) in a database, each time it sees the info, depending on which car it is.

Hence the reason why I want to keep the information in memory and update it as I go through the file. Once the entire file is read, then I want to update the database based on the worse of the damage for each body part.

I should have mentionned, the text file is changing all the time, so it's not a "one time thing" but rather a weekly thing. So each week, the text file is totally different, and the cost is cumulative from one week to the next.

I guess the idea of the array is where I got lost... Can I have an array of array? What I'm trying to accomplish, and I might be on the right track, or totally out to lunch, is something like this (if you're familiar with Pascal structures):

type
carinfo = record
front_left : byte;
mid_left : byte;
rear_left : byte;
rear : byte
rear_right : byte;
mid_right : byte;
front_right : byte;
front : byte;
end;
var
car : array[1..50] of carinfo;

Each byte in the record would have a value of 0 (no damage),
1 (minor damage), 2 (medium damage), 3 (severe damage), 4 (removed).

So in Pascal, that's quite easy because I know how to do an array of records.

Should I understand that in Foxpro, I should have an array of 8 (one for each body part), and then an array of 50 of those, 1 for each car?

Would it be something like:

Dimension car(50,8) and then just populate the "50" with the car number, and the "8" with the status between 0 and 4? would this work?

Thanks again!!!


Cheers,

Realm174
 
With the amount of back-and-forth Q&A that might be necessary to help you out, why don't we take this off-line and discuss this via email (use below).

In that way if you need to send me files, etc. I can review them to get a better understanding.

From your basic description, I would first question how the tables are currently laid out and how they are being utilized.

But you say that this is an existing application and, I assume, it is working (if only somewhat). Then we might be forced to stay within what is already in place.

"Dimension car(50,8) and then just populate the "50" with the car number, and the "8" with the status between 0 and 4? would this work?" Yes you can do it this way.

But my first suggestion would be to use temporary tables (possibly created through SQL Queries) instead of an memory array to do our data collection and analysis. Then, when done, you can blow them away. By using tables there are many additional operations available to us to use for analysis purposes.

Good Luck,


JRB-Bldr
VisionQuest Consulting
Business Analyst & CIO Consulting Services
CIOServices@yahoo.com
 
FPD is good at tables so ... get the data into a table ie

structures as follows:
carinfo c-50,;
bodypart c-25,;
status N-1

then when all the text file is read assign each to a record. At this point, it doesn't matter if there are duplicate carinfo,bodypart records with a different status.

Then use a SQL command to generate a new table or cursor to get the worst status( highest number) for each unique carinfo,bodypart as follows:
SELECT carinfo, bodypart, max(status) from <TextTable> ;
order by 1,2 group by 1,2 into <NewTable>
This will give you a table with a single record for each carinfo,bodypart with the worst STATUS.

You can then assign a dollar value for each number with possibley with a small function

Function GetDollar
parameter nStatus
private rValue
do case
case nStatus = 0
rValue = 0
case nStatus = 1
rValue = 1000.00
case nStatus = 2
rVAlue = 3000.00

otherwise
* --- possible error message here

endcase
return rValue

Am I missing something ...

JanRog




 
jrbbldr: Thank you my friend, I'll email you the specifics, along with a sample of the text files I read through.. you'll be in a better position to visualise what I'm trying to do.

JanRog: I'm not familiar with the create table command. So I'll have to experiment. But I get the idea... :)

DSummm: Thanks, I've been there already, and in all honesty, because I'm so unfamiliar with the visual environment, I got totally lost. I mean, I understand what I'm reading, and it makes sense, however, when I try to apply it, it doesn't quite work for me.. The brain doesn't want to computer anymore :) But that'll have to be for the next project as I don't really want to rewrite this entire (badly written) application...



Cheers,

Realm174
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top