Solved

displaying a textfile

Posted on 2003-11-07
7
303 Views
Last Modified: 2010-04-16
I have a textfile called Inv and this is a part of my code:

Procedure CheckMinimum;
VAR
   MinStock : integer;

BEGIN
   reset (inv);
   MinStock := 0;
   Stock := 0;
   While not eof (inv) do
   BEGIN
      readln(inv, id, instock, price, min,  name);
   end;
      IF instock < min THEN
      BEGIN
         writeln('The following items have an amount less than the mininmum recommended:');
         writeln('   ID    In Stock      Minimum');
         writeln('==============================');
         writeln(id:5, instock:12, min:13);
      end;
   close(inv);
end; { CheckMinimum }


i want to display all items in the textfile that have items less the the minimum listed, my current code only displays the last item in the textfile that meets this criterea. how do i make it display all of them instead of just that one.
i would greatly appreciate any help
0
Comment
Question by:vyhoang
  • 4
  • 3
7 Comments
 
LVL 11

Accepted Solution

by:
bcladd earned 100 total points
ID: 9701174
Actually, if the last line in the file were "in stock", your program would not display anything at all. Why? Because you have a loop that read the file:

   While not eof (inv) do
     BEGIN
      readln(inv, id, instock, price, min,  name);
     end;

and you have a selection statement having to do with printing:

    IF instock < min THEN
      BEGIN
         writeln('The following items have an amount less than the mininmum recommended:');
         writeln('   ID    In Stock      Minimum');
         writeln('==============================');
         writeln(id:5, instock:12, min:13);
      end;

but one is not within the other. Be very careful when indenting your lines to make sure that something is indented when it is contained within a begin/end block. You want to change your loop to read:

  while not eof(inv) do
    BEGIN
      readln(inv, id, instock, price, min,  name);
      IF instock < min THEN
      BEGIN
         writeln('The following items have an amount less than the mininmum recommended:');
         writeln('   ID    In Stock      Minimum');
         writeln('==============================');
         writeln(id:5, instock:12, min:13);
      end;
    END;

Also, you probably want to move the header printing OUT of the loop altogether (put it above the while) and just print the information for the low stock item in the if statement.
0
 

Author Comment

by:vyhoang
ID: 9704734
Procedure Transaction;
VAR
   ordera, orderb, orderc    : char;                          {1st order letter, 2nd order letter, 3rd order letter}
   ordernum, idnum, stocknum : integer;                       {ordernumber, item number, number of items sold ot returned}
   status                    : char;                          {sold or return}
   LetterS, LetterR          : integer;
BEGIN
   reset (inv);  
   rewrite (newinventory);
   WHILE NOT eoln (inv) DO
   BEGIN
      readln(inv, id, instock, price, min, name);
      reset (invup);
      WHILE NOT eoln (invup) DO
      BEGIN
         readln(invup, ordera, orderb, orderc, ordernum, idnum, status, stocknum);
         If id = idnum THEN
         BEGIN
            IF status = 'S' THEN
            BEGIN
               IF status = 'R' THEN
               BEGIN
                  LetterR := instock + stocknum;
                  writeln (newinventory, id, LetterR, price, min, name);
               end;
               LetterS := instock - stocknum;
               writeln (newinventory, id, LetterS, price, min, name);
            end;
         end;
      end;
   end;

   close(inv);
   close(newinventory);
end; { Transaction }

This is what i have to do:
Update: Update the InventoryFile with the transactions from the InventoryUpdate file. (Do not actually change the InventoryFile as this will be awkward for debugging and testing. Write to a third file called newinventory.) To make the assignment easier the Leestma InventoryUpdate file has been altered to include a sentinel value at the end of the file, so the last line is:9999999 99999 99

But why when do i run it i get no output?
0
 

Author Comment

by:vyhoang
ID: 9704794
this is the invup file:

CCI7543 1012S  2

LTB3429 1012S  7

DJS6762 1021S  9

NQT1850 1022S  1

WYP6425 1023S  4

YOK2210 1023R  2

QGM3144 1023S  1

NPQ8685 1031S  5

MAP8102 1031S 13

JRJ6335 1031S  1

UWR9386 1032S  3

TJY1913 1032S 11

YHA9464 1041S  5

SYT7493 1041S  3

FHJ1657 1042S  7

OJQ1221 1043S  8

UOX7714 1043S  2

ERZ2147 1043S  7

MYW2540 1044S  1

UKS3587 1045S  2

AAN3759 1045S  2

WZT4171 1045S 12

TYR9475 1511S  1

FRQ4184 1511S  1

TAV3604 1512S  2

DCW9363 1522S  1

EXN3964 1522R  1

OIN5524 1522S  1

EOJ8218 1522S  1

YFK0683 2011S  2

PPX4743 2012S  4

DBR1709 2013S  4

JOM5408 2013S  3

PKN0671 2013S  1

LBD8391 3011S  9

DNL6326 3012S  9

BTP5396 3013S  1

GFL4913 3013S  8

EHQ7510 3013S  7

QQL6472 3013S  5

SVC6511 3014S  4

XJQ9391 3014S  4

ONO5251 3111S  3

CXC7780 3111S  1

VGT8169 3112S  8

IMK5861 3511S  2

QHR1944 3511S  1

ZPK6211 4011S  2

VDZ2970 4012S  6

BOJ9069 5011S  6

MNL7029 5011S  9

MRG8703 5021S 10

DEM9289 5021S  1

BXL1651 5031S  2

VAF8733 6111S 65

UYI0368 7011S  2

VIZ6879 8011S 16

GXX9093 8011S 19

HHO5605 8021S 41

BOL2324 8021S 49

PAG9289 8023S 15

MDF5557 8023S 17

IQK3388 8024S 12

OTB1341 8024S 28

SVF5674 8031S 24

ZDP9484 8031S 15

OSY8177 8032S 15

GJQ0185 8032S  8

VHW0189 8041S 20

WEU9225 8041S  6

YJO3755 8041S  8

9999999 99999  9
0
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 
LVL 11

Expert Comment

by:bcladd
ID: 9705403
I am not going to work through your homework for you. What, exactly, is your question about the code you posted? What does it do that is not as indicated in the assignment?

-bcl
0
 

Author Comment

by:vyhoang
ID: 9706009
when i run the program everything works but when it perfroms the prodedure transaction, it seems that it doesn't write the outout file for the new data, and i don't understand what the problem is within the code. if you could can you just give me a hint as to how to fix this
0
 

Author Comment

by:vyhoang
ID: 9706069
nevermind i figured out what the problem was, thankyou for all you help bcladd
0
 
LVL 11

Expert Comment

by:bcladd
ID: 9706799
Glad to be able to help. -bcl
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Are you unable to connect or configure Hotmail email account in Microsoft Outlook 2010, 2007? Or Outlook.com emails are not downloading to Outlook? Lets’ see the problem and resolve Outlook Connector error syncing folder hierarchy (0x8004102A).
In this article, I will show you HOW TO: Perform a Physical to Virtual (P2V) Conversion the easy way from a computer backup (image).
This tutorial demonstrates a quick way of adding group price to multiple Magento products.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now