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!

dBase iii+ Do While problem

Status
Not open for further replies.

joewillerols

Programmer
Dec 29, 2020
20
US
[pre]BWCHECK is a field name of type character with a length of one.
The only value I want entered is T, b, B, or N.
This is the code I've written. The problem is that BWCHECK will accept any value.
It then exits and goes onto the next field.
Help!

Tks,
Joe

do while ((BWCHECK <> "T") .or. (BWCHECK <> "b") .or. (BWCHECK <>"B") .or. (BWCHECK <> "N"))
@ 2,2 GET BWCHECK
read
exit
loop
enddo[/pre]
 
Hi

First of all, sorry if this will be of no help in your case. My dBASE knowledge is very limited, most of my memories are about Clipper and FoxPro.

Check whether the [tt]valid[/tt] clause is supported by dBASE's [tt]@[/tt] .. [tt]get[/tt] :
Code:
@ 2,2 GET BWCHECK valid BWCHECK = "T" .or. BWCHECK = "b" .or. BWCHECK = "B" .or. BWCHECK = "N"
read


Feherke.
feherke.github.io
 
Feherke,
Tks for the quick response. Your suggestion didn't work. I got the usual error.

[pre]Unrecognized phrase/keyword in command.
?
@ 2,2 GET BWCHECK valid BWCHECK = "T" .or. BWCHECK = "b" .or. BWCHECK = "B" .or.
BWCHECK = "N"
called from - C:BLACKS.PRG
Cancel, Ignore, or suspend: (C, I, or S)[pre]

It seems that I cannot take a shortcut like this.

I tried this. DO WHILE worked fine but I was unable to store any value into BWCHECK. BWCHECK always had a value of 0.

DO WHILE choice < 1 .or. choice > 4

STORE 0 TO choice
DO WHILE ((choice < 1) .OR. (choice > 4))
@ 10,14 SAY "Please select one of the above options " GET choice PICTURE '9'
READ
ENDDO

DO CASE

* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
CASE choice = 1
@ 21,1 SAY "choice = 1"
store 1 to BWCHECK
@ 21,20 say BWCHECK
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
CASE choice = 2
@ 21,1 SAY "choice = 2"
store 2 to BWCHECK
@ 21,20 say BWCHECK
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
CASE choice = 3
@ 21,1 SAY "choice = 3"
store 3 to BWCHECK
@ 21,20 say BWCHECK
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
CASE choice = 4
@ 21,1 SAY "choice = 4"
store 4 to BWCHECK
@ 21,20 say BWCHECK
ENDCASE

ENDDO
RETURN[/pre]

Joe
 
Hi,
I used Dbase many years ago so my knowledge is rusty to say the least.
I'm not sure why you are using the Do while command.

Try using the CASE commands you have structured in its own separate program and run this to see what results you get.

Phil
 
The case structure should like similar to the following:-

Do Case

Case choice = '1'
Replace BWCHECK with 1
Case choice='2'
Replace BWCHECK with 2
Case choice='3'
Replace BWCHECK with 3
Case choice='4'
Replace BWCHECK with 4

Endcase

I am assuming that the field BWCHECK is numeric

Phil


 
Phil,

BWCHECK is a character.
I see that you used the REPLACE command rather than STORE.
I'll give it a try and let you know.

Joe
 
Hi,
Sorry, you do need the Do while bit, I was jumping ahead of myself and of course the replace BWCHECK with a number should be enclosed in quotes; "1" or '1' as it is character.

Phil
 
Hi,
I've just realised that you are not working in a database file and this is why you are getting nil results.
In a do while loop each record is checked by going through the database 1 record at a time from top to bottom
and then a field can be changed if it meets the criteria in a loop or replace/store command.
 
Phil,

I am working in a database. At the top I did say "BWCHECK is a field name of type character with a length of one."

I used your Do Case example. I made the necessary changes and it worked. I also added
@ 2,2 say BWCHECK
so that a "T", a "b", a "B", or an "N" would be displayed on the screen.

What I still do not understand is why original code did not work.
do while ((BWCHECK <> "T") .or. (BWCHECK <> "b") .or. (BWCHECK <>"B") .or. (BWCHECK <> "N"))
@ 2,2 GET BWCHECK
read
exit
loop
enddo

Joe
 
Hi,
Usually when building a program file you would see the USE command with the dbf filename near the top of the file, so I assume you opened it another way.

In your 'do while' structure I'm not sure why you are using brackets.

Tell me what you are trying to achieve with the Do While loop?

I'm currently working from home because of new lockdown so I will look for my Dbase III command book today to check what commands were valid at the time.

Cheers
Phil

 
The following is a repeat of my original request. I did not add a USE so as not to add unneeded information and I assumed that it was a given because I am having a problem with a FIELD and the value I have trying to put in it..

BWCHECK is a field name of type character with a length of one.
The only value I want entered is T, b, B, or N.
This is the code I've written. The problem is that BWCHECK will accept any value.
It then exits and goes onto the next field.

do while ((BWCHECK <> "T") .or. (BWCHECK <> "b") .or. (BWCHECK <>"B") .or. (BWCHECK <> "N"))
@ 2,2 GET BWCHECK
read
exit
loop
enddo

As for the parentheses, I recall being taught that way as well as saw it that way in a few example I found online.
I also tried the following to no avail.
do while (BWCHECK <> "T") .or. (BWCHECK <> "b") .or. (BWCHECK <>"B") .or. (BWCHECK <> "N")
and
do while (BWCHECK <> "T" .or. BWCHECK <> "b" .or. BWCHECK <>"B" .or. BWCHECK <> "N")
and
do while BWCHECK <> "T" .or. BWCHECK <> "b" .or. BWCHECK <>"B" .or. BWCHECK <> "N"

All I want is for the use to hit one of four letters and go on to the next FIELD/READ or loop back to try again.

Here is a Basic example of how this should work.

10 LOCATE 2,2
20 BWCHECK$=INKEY$
30 IF BWCHECK$="T" OR BWCHECK$="b" OR BWCHECK$="B" OR BWCHECK$="N"
40 GOTO 55
50 ELSE GO TO 10
55 END IF

60 LOCATE 2,2
70 BWSTRIPES$=INKEY$
80 IF BWSTRIPES$="T" OR BWCHECK$="b" OR BWCHECK$="B" OR BWCHECK$="N"
90 GOTO 105
100 ELSE GO TO 60
105 END IF

Joe
 
Hi Joe,
To make sure the correct data is input you would need to have an input screen to validate the letter that the inputter types and will not go any further if the wrong letter is entered.

I don't have Dbase anymore to test any programs on but I do have Visual Foxpro which uses the same language as Dbase and was always 1 step ahead.

Do while 'bBNT' $ bwcheck etc. should work. The $ sign is a substring operator which allows characters to be searched for within another char string.

Let me know what you think.




 
Hi Joe,
The $ sign command works in Foxpro but may not in Dbase.

You could do this;
Set filter to 'bBNT'$BWCHECK
Browse


Dbase should manage to do the above,
you should then be able to see the blanks assuming it is not a massive file.

Which version of dbase do you have?

Phil

 
Hi Joe,
I've sent 2 previous messages, however I've modified your Do while code as follows which works fine:-

close all
clear

USE BWdata
go top

Do while ((BWCHECK <> "T") .or. (BWCHECK <> "b") .or. (BWCHECK <>"B") .or. (BWCHECK <> "N"))
@ 25,25 GET BWCHECK
read
skip
If eof()
exit
endif
Enddo
clear
return

Would like to know where the CHOICE field fits into this.
I have found my old Dbase manual which covers upto and including Dbase III.
 
Let me start this again. I'll add some more information.

I am using dBase III+.
I have a DBF called BLACK.DBF. See the attached file.
I have already done the APPEND BLANK command to add a blank record.
One of the fields is called BWCHECK. This field is a character with a length of one.

I want the user to be able to enter one of the following; T, b, B, or N.

The code goes as follows.

clear
use BLACK

set color to
@ 2,2 SAY "█"
@ 3,2 SAY "█"

set color to W+
@ 2,4 say "Black And White Check"
@ 3,4 say "Black And White Stripes"

* More @ SAYs go here.
* After all the @ says are displayed then the @ GET/READs begin.

do while ((BWCHECK <> "T") .or. (BWCHECK <> "b") .or. (BWCHECK <>"B") .or. (BWCHECK <> "N"))
@ 2,2 GET BWCHECK
read
exit
loop
enddo

do while ((BWSTRIPES <> "T") .or. (BWSTRIPES <> "b") .or. (BWSWTRIPES <>"B") .or. (BWSTRIPES <> "N"))
@ 2,2 GET BWSTRIPES
read
exit
loop
enddo

* The remainder @ GET/READs go here.

close all

The problem is that no matter what the user enters, the next GET/READ is done.
I have tried various combinations of parenthesis including none at all.

I hope this makes better sense.

Joe
 
 https://files.engineering.com/getfile.aspx?folder=af17638c-42f9-4c73-a4e4-bd30e2fa3ee8&file=BLACK.DBF
Hi Joe,
I have started to write some code but have noticed the DBF file you sent is empty. It would probably help if some of the data is there for me to use as a test if that's okay.

Phil
 
Phil,

It is blank and is supposed to be blank. I am looking to add a new record to a new (never before used) DBF file and not edit old records. I'll worry about editing after I am able to input new records.

Joe
 
Joe,
Brilliant, that's what I thought. I'll now write an input screen with a type of validation suitable for Dbase III plus.

Phil

 
Joe,
The following works fine.
If okay, it can be refined to suit other fields that need input, maybe with a small menu:-

close all
clear
set confirm on

USE Black.dbf
go top

Do while .t.
X1=' '
@ 3,10 SAY 'Enter value for BWCHECK' get X1
@ 5,10 SAY 'Press esc to exit'
READ
IF READKEY()=12
CLEAR
EXIT
ENDIF
If X1='b'.or.X1='B'.or.X1='N'.or.X1='T'
Append blank
Replace bwcheck with X1
else
@ 8,10 SAY 'Enter one of these values only b B N T '
loop
Endif
Skip
Enddo
Return
Set confirm off
browse
 
Phil,

That worked except that it never would exit. See the attached screen shot.

That's okay. It got me thinking and I resolved the problem.
There is only one record so go top and skip is not needed.
I changed your code as follows. It works perfectly. It allows me to add more fields and exit after the last field.

Tks,
Joe

*go top

Do while .t.
X1=' '
@ 3,10 SAY 'Enter value for BWCHECK' get X1
* @ 4,10 SAY 'Press esc to exit'
READ
* IF READKEY()=12
* CLEAR
* EXIT
* ENDIF
If X1='b'.or.X1='B'.or.X1='N`'.or.X1='T'
* Append blank
Replace bwcheck with X1
exit
else
@ 9,10 SAY 'Enter one of these values only b B N T '
loop
Endif
* Skip
Enddo
*Return
 
 https://files.engineering.com/getfile.aspx?folder=57d60a97-de1c-4f94-b836-ba767d11daac&file=83RECORD.PNG
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top