dbTalk Databases Forums  

Basic Program - Just learning and I need help

comp.databases.pick comp.databases.pick


Discuss Basic Program - Just learning and I need help in the comp.databases.pick forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Wytevette
 
Posts: n/a

Default Basic Program - Just learning and I need help - 03-06-2006 , 12:34 PM






Hello,
I have a Universe system.

There is a file called PMCM.CMMT that the DICT file shows eleven
fields.
Field number five is titled F1 and field number eight is titled F2 in
the DICT.

I am trying to write a BASIC program that will open the PMCM.CMMT file,
check F2 to see if it has the string "SLOW MOVEMENT" in it. Then if F2
= "SLOW MOVEMENT" I want to change the data in F1 to = "S"

Following is the code I started with:
OPEN '','PMCM.CMMT' ELSE STOP "CAN'T OPEN FILE"
SELECT TO PMCM.CMMT
10: READNEXT ID FROM PMCM.CMMT THEN PRINT ID ELSE GOTO 15:
GOTO 10:
*
15: PRINT

OPEN '','PMCM.CMMT' TO PMCM.CMMT ELSE STOP
SELECT PMCM.CMMT
COUNT=0
20*
READNEXT ID ELSE
PRINT 'COUNT= ',COUNT
STOP
END
COUNT=COUNT+1
GOTO 20

It seems to work and output what I expect.
ID is the first field in the PMCM.CMMT file. It is the record number,
and the above program prints it out and tallies how many records exist.

If I try to change line three to print F2 instead of ID, it still
prints the ID number. ( I did recompile)

10: READNEXT F2 FROM PMCM.CMMT THEN PRINT F2 ELSE GOTO 15:

Is "ID" irrelevant? Is that just a variable name, or is it actually
referencing the ID field of the record?

For starters I would like to get it to print the F1 and F2 fields. I
don't want to think about modifying the data until I can at least do
that.

Thank you for any assistance,
Phil


Reply With Quote
  #2  
Old   
Tracy Raines
 
Posts: n/a

Default Re: Basic Program - Just learning and I need help - 03-06-2006 , 01:06 PM






I don't know Universe very well, so I hope that this is actually
correct. It is correct from a D3 standpoint.

The READNEXT statement does not acutally read the record, it only gets
the next id from the list. You need to use the ID to read in the
record, and then you will be able to reference the data in the record.
If you do something like:

READ REC FROM PMCM.CMMT, ID ELSE REC = ''
PRINT REC<8>

This will print whatever value is stored in attribute 8 of the record.

Hope this helps.


Reply With Quote
  #3  
Old   
Lance
 
Posts: n/a

Default Re: Basic Program - Just learning and I need help - 03-06-2006 , 01:53 PM



Here is one that gives some examples to learn from:

OPEN '','PMCM.CMMT' TO PMCM.CMMT ELSE STOP 'PMCM.CMMT'
CT=0 ; F1=5 ; F2=8
CHANGED=0 ; PRINT.ONLY=1
SELECT PMCM.CMMT
LOOP
READNEXT ID FROM 0 THEN CT+=1 ELSE EXIT
READ RECORD FROM PMCM.CMMT,ID ELSE CONTINUE
IF PRINT.ONLY THEN
FIELDS.TO.PRINT = 11
* FIELDS.TO.PRINT = DCOUNT(RECORD,@FM)
CRT '*** ':ID:' *** '
FOR I=1 TO FIELDS.TO.PRINT
CRT I'R%3 ':RECORD<I>
NEXT I
CRT '<enter> for next record or (Q)uit -> ':
INPUT ANS,1
IF OCONV(ANS,'MCU')='Q' THEN EXIT
END ELSE
IF RECORD<F2>='SLOW MOVEMENT' THEN
RECORD<F2>='S'
* WRITE RECORD TO PMCM.CMMT,ID
CHANGED+=1
END ELSE
NULL
END
END
REPEAT
CRT 'Records Processed : ':CT
CRT 'Records Changed : ':CHANGED
END


Reply With Quote
  #4  
Old   
Wytevette
 
Posts: n/a

Default Re: Basic Program - Just learning and I need help - 03-06-2006 , 02:07 PM




Hi Tracy,

I added the lines you gave me right after the READNEXT.

OPEN '','PMCM.CMMT' ELSE STOP "CAN'T OPEN FILE"
SELECT TO PMCM.CMMT
10: READNEXT ID FROM PMCM.CMMT THEN PRINT ID ELSE GOTO 15:
READ REC FROM PMCM.CMMT, ID ELSE REC = ''
PRINT REC<8>
GOTO 10:

The compiler doesn't complain, but when I try to run it, I get:
Program "STUFF.PMCM.CMMT": Line 4, Improper data type.

Line 4 is the READ REC line.

Thank you for your help.

Phil


Reply With Quote
  #5  
Old   
Martin Kent
 
Posts: n/a

Default Re: Basic Program - Just learning and I need help - 03-06-2006 , 02:25 PM



The OPEN statement should read;

OPEN '','PMCM.CMMT' TO PMCM.CMMT ELSE STOP "CAN'T OPEN FILE"

PMCM.CMMT is the file handle that you can use to READ/WRITE/DELETE
records with. Please note that this may be BASIC, but the use of GOTO's
is not encouraged!


Reply With Quote
  #6  
Old   
murthi
 
Posts: n/a

Default Re: Basic Program - Just learning and I need help - 03-06-2006 , 02:29 PM



Check the manuals for the syntax of the relevant statements.

OPEN without a TO clause sets up an internal, unnamed file variable, so the
READ ...FROM PMCM.CMMT cannot work.

Either: The OPEN should be with a "TO PMCM.CMMT" or the READ shuld be
without the ":FROM PMCM.COUNT" clause.

Chandru Murthi


"Wytevette" <philmoore (AT) atvpix (DOT) com> wrote

Quote:
Hi Tracy,

I added the lines you gave me right after the READNEXT.

OPEN '','PMCM.CMMT' ELSE STOP "CAN'T OPEN FILE"
SELECT TO PMCM.CMMT
10: READNEXT ID FROM PMCM.CMMT THEN PRINT ID ELSE GOTO 15:
READ REC FROM PMCM.CMMT, ID ELSE REC = ''
PRINT REC<8
GOTO 10:

The compiler doesn't complain, but when I try to run it, I get:
Program "STUFF.PMCM.CMMT": Line 4, Improper data type.

Line 4 is the READ REC line.

Thank you for your help.

Phil




Reply With Quote
  #7  
Old   
Wytevette
 
Posts: n/a

Default Re: Basic Program - Just learning and I need help - 03-06-2006 , 02:33 PM



Hi Lance,
I am experimenting with your program right now.

I erred earlier, I said that F1 and F2 were fields 5 and 8. That was
incorrect they are 1 and 2.
I changed the variables so F1=1 and F2=2

Thank you,
Phil


Reply With Quote
  #8  
Old   
Lance
 
Posts: n/a

Default Re: Basic Program - Just learning and I need help - 03-07-2006 , 09:24 AM



Cool. Let me know how things turn-out or if you need anymore pointers.


Reply With Quote
  #9  
Old   
Wytevette
 
Posts: n/a

Default Re: Basic Program - Just learning and I need help - 03-07-2006 , 10:05 AM



Hi Lance,

It worked great for me. Here is what I ended up with:

OPEN '','PMCM.CMMT' TO PMCM.CMMT ELSE STOP 'PMCM.CMMT'
CT=0 ; F1=1 ; F2=2
CHANGED=0 ; PRINT.ONLY=1
SELECT PMCM.CMMT
LOOP
READNEXT ID FROM 0 THEN CT+=1 ELSE EXIT
READ RECORD FROM PMCM.CMMT,ID ELSE CONTINUE
IF PRINT.ONLY THEN
FIELDS.TO.PRINT = 3
* FIELDS.TO.PRINT = DCOUNT(RECORD,@FM)
CRT '*** ':ID:' *** '
FOR I=1 TO FIELDS.TO.PRINT
CRT I'R%3 ':RECORD<I>
NEXT I
IF RECORD<F2>='SLOW MOVEMENT' THEN
CRT 'FOUND IT! - ':
CRT 'CHANGING RECORD F1 FOR ID ':ID:'OK?'
CRT '<enter> To change and continue or (Q)uit -> ':
INPUT ANS,1
IF OCONV(ANS,'MCU')='Q' THEN EXIT
RECORD<F1>='S'
WRITE RECORD TO PMCM.CMMT,ID
CHANGED+=1
END ELSE
NULL
END
END
REPEAT
CRT 'Records Processed : ':CT
CRT 'Records Changed : ':CHANGED
END

Thank you for your help.
Phil


Reply With Quote
  #10  
Old   
B Faux
 
Posts: n/a

Default Re: Basic Program - Just learning and I need help - 03-08-2006 , 01:20 PM




"Wytevette" <philmoore (AT) atvpix (DOT) com> wrote

Quote:
Hi Lance,

It worked great for me. Here is what I ended up with:

OPEN '','PMCM.CMMT' TO PMCM.CMMT ELSE STOP 'PMCM.CMMT'
CT=0 ; F1=1 ; F2=2
CHANGED=0 ; PRINT.ONLY=1

SELECT PMCM.CMMT
[snip]

Quote:
END

Thank you for your help.
Phil

That's all great and you could also just deal with the items you want by
changing the BASIC SELECT to an EXECUTE statement such as:

EXECUTE \SELECT PMCM.CMMT WITH F2 = "SLOW MOVEMENT"\

Note the use of back-slash bounding the entire statement and the double
quote bounding the literal "SLOW MOVEMENT". This also pre-supposes the
dictionary item for 'F2' is actually called 'F2' in the dictionary, if not
make appropriate substitute.

The execute will select only the items with the specified string and then
you would not need to loop thru the entire file (can be a big time saver if
you have lots of logic to isolate items) because Basic SELECT just starts at
the first item and follows all of the subsequent record links until it runs
out of data.

Check your doco for 'EXECUTE' statements as Universe might differ slightly
from what I have used (Pick, D3, Mentor and Ultimate).

Happy coding...

BFaux




Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.