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

VDb Program Help 1

Status
Not open for further replies.

moggy44

Technical User
Nov 13, 2002
77
GB
I am in the process of writing a program for a Taxi Office for Dispatching cars,BUT, my Dbase knowledge is 20 years old and forgot most of it.
The bit that I am getting bogged down on is selecting Road/Street that is in a database called STREETDB to enter into booking screen.
The way I want it to work is to enter 4 letters say "Manr", the first 3 Road/Street name 4th letter R for Road S for Street etc so I can narrow down search, that I have working fine.
When it comes to finding the road/Street etc, I look for the space after the road name and then by adding one to the variable I find the first letter for Road or Street this will then give me a list of Roads begining with "Man" as above, obviously I have to find the number of charaters in the name to find the space, and make sure my database has only one space in the whole name i.e "Tongemoor Road" and not "Tonge Moor Road".

The problem is I was using a "DO WHILE EOF()" but then I have to put an "IF" statement to find and display the correct Road/Street and then another "IF" to tell it that is the correct Road/Street then get out of the "IF's" and get out of the "DO WHILE", but I can't seem to find the correct commands to get out after I have selected the correct Road/Street.

Can anyone point me in the right direction, I can display the code I have if it will help.

Regards John.m
 
Perhaps EXIT is the command you're looking for to exit the loop once you found a match?
 
I make have the solution, I have listed my program does it look to cluttered or does this seem OK.

* Program Name "streetex.prg"
* Used to Identify list of streets from Entered Data
set talk off
use c:\dbase\streetdb

* Data Variables
* mstreet is input data of 4 characters
* vstreet is the number value to point to the 1st character used for finding which Road/Street/Way etc
* istreet is the letter of the 1st character of Road/Street etc
* lstreet is the number of characters which must be = 4

clear
accept 'Street Name ' to mstreet

* Find number of characters entered and make sure not <> than 4
store len(mstreet) to lstreet
? lstreet
if lstreet <> 4
@ 10,10 say 'To Many/Few Characters'
wait
clear
accept 'Street Name ' to mstreet
store len(mstreet) to lstreet
endif
*******************************************************************
* First part of input complete
*******************************************************************

* Find First Character of Road/Street i.e:

* R - Road
* S - Street
* G - Grove
* W - Way
* W - Walk
* L - Lane
* F - Fold
* A - Avenue
* B - Brow



* Find right most character for Road/Street definition
store right(mstreet,1) to istreet


* Make istreet UPPER case
istreet = upper(istreet)

*******************************************************************

* Make mstreet only 3 characters long

store left(mstreet,3) to mstreet


* mstreet is part input of required location

*******************************************************************
* mstreet = First 3 characters of input
* vstreet = Space in Road name
* rstreet = First letter of "R"oad or "S"treet

go top
choice = ' '
DO WHILE .not. choice = 'Y'

if substr(street,1,3) = mstreet

* vstreet is the space in Road name, and is a numerical value
store at(' ',street) to vstreet

* Add 1 character to vstreet to point to first letter of Road/Street
store vstreet+1 to rstreet

if substr(street,rstreet,1) = istreet
clear
@ 10,30 say street
wait ' Confirm Y/N ' to choice
endif

endif

skip
enddo
wait ' End of File'
 
Code:
*    Program Name "streetex.prg"
*    Used to Identify list of streets from Entered Data
set talk off
use c:\dbase\streetdb

* Data Variables
* mstreet is input data of 4+ characters
* vstreet is the number value to point to the 1st character used for finding which Road/Street/Way etc
* istreet is the letter of the 1st character of Road/Street etc
* lstreet is the number of characters which must be = 4

clear
accept 'Street Name ' to mstreet

* Find number of characters entered and make sure not < than 4
store len(mstreet) to lstreet
? lstreet
if lstreet < 4
   @ 10,10 say 'Too Few Characters'
   wait
   clear
   accept 'Street Name ' to mstreet
   store len(mstreet) to lstreet
endif
***********************************************************
   * First part of input complete
***********************************************************

   * Find First Character of Road/Street i.e:

   * R - Road
   * S - Street
   * G - Grove
   * W - Way
   * W - Walk
   * L - Lane
   * F - Fold
   * A - Avenue
   * B - Brow

   * Find right most character for Road/Street definition
   * And make istreet UPPER case
   store upper(right(mstreet,1)) to istreet

***********************************************************

      * Make mstreet only 3 characters long

      store left(mstreet,len(mstreet)-1) to mstreet

      * mstreet is part input of required location

***********************************************************
      * mstreet = First 3+ characters of input
      * vstreet = Space in Road name
      * rstreet = First letter of "R"oad or "S"treet

go top
choice = ' '
DO WHILE .not. choice = 'Y'

   if upper(substr(street,1,len(mstreet))) = upper(mstreet)

      * vstreet is the space in Road name, and is a numerical value
         store at(' ',street) to vstreet

      * Add 1 character to vstreet to point to first letter of Road/Street
  
      store vstreet+1 to rstreet

      if substr(street,rstreet,1) = istreet
         clear
         @ 10,30 say street
         wait ' Confirm Y/N ' to choice
         choice = upper(choice)
         if choice = "Y"
            EXIT
         endif
      endif

   endif

   skip
enddo
wait ' End of File'
 
In looking over the original sample you submitted, I'd guess the problems you had were that you were entering "y" to confirm but the program was looking for a capital "Y". Then if you did enter a capital "Y", it would skip to the next street before stopping, which was not the street you accepted.

This sample should allow you to leave spaces in street names such as "Tonge Moor Road ". It will split the one file into 2 variables, one with the street name possibly containing spaces and the other with the street type. Then it does the compare.
Code:
*    Program Name "streetex.prg"
*    Used to Identify list of streets from Entered Data
set talk off
use c:\dbase\streetdb

* Data Variables
* mstreet is input data of 4+ characters
* cstreet is trimmed complete street name
* vstreet is the number value to point to the 1st character used for finding which Road/Street/Way etc
* istreet is the letter of the 1st character of Road/Street etc
* lstreet is the number of characters which must be = 4

clear
accept 'Street Name ' to mstreet

* Find number of characters entered and make sure not < than 4
store len(mstreet) to lstreet
? lstreet
if lstreet < 4
   @ 10,10 say 'Too Few Characters'
   wait
   clear
   accept 'Street Name ' to mstreet
   store len(mstreet) to lstreet
endif
***********************************************************
   * First part of input complete
***********************************************************

   * Find First Character of Road/Street i.e:

   * R - Road
   * S - Street
   * G - Grove
   * W - Way
   * W - Walk
   * L - Lane
   * F - Fold
   * A - Avenue
   * B - Brow

   * Find right most character for Road/Street definition
   * And make istreet UPPER case
   store upper(right(mstreet,1)) to istreet

***********************************************************

      * Make mstreet extract only name portion

      store left(mstreet,len(mstreet)-1) to mstreet

      * mstreet is part input of required location

***********************************************************
      * mstreet = First 3+ characters of input
      * vstreet = Space in Road name
      * rstreet = First letter of "R"oad or "S"treet

go top
choice = ' '
DO WHILE .not. choice = 'Y'
   * remove trailing spaces from street field
   cstreet = rtrim(street)

   * get rightmost space - should be between street name and type
   vstreet = rat(" ",cstreet)

   * get street name
   cstreet1 = left(cstreet,vstreet-1)

   * get street type
   cstreet2 = substr(cstreet,vstreet+1)

   if upper(substr(cstreet1,1,len(mstreet))) = upper(mstreet) ;
      .and. upper(left(cstreet2,1)) = upper(istreet)

         clear
         @ 10,30 say street
         wait ' Confirm Y/N ' to choice
         choice = upper(choice)

   endif

   if choice <> "Y"
      skip
   endif

enddo
wait ' End of File'
 
Hi dbmark,
thanks for the corrections, I will try when I get the time.
Not sure if I will ever get a perfect working program as I think there are some limitations using VDB, but Its the only language I know a little of, you may be able to help me in my quest, if I get stuck.LOL.

Regards and thanks John.M
 
So cool to see someone talking dBase code. I was a beta tester for Borland when they were developing Visual dBase for Windows and spent the better part of a year hanging out on the dBase forum on Compuserve. Those were good times and I still use the programs I wrote for my own business during that time.

It's been so long now I don't remember much but it was fun reading your code. Thought I'd pop in and say hi!

Steve
 
Hi,
I've not used Dbase for 20years and then it was only for a speific program that I couldn't find anywhere.

Keep looking as I am sure I will needs lots of help in developing this Taxi dispatch Program.

I will start a new thread as this one is getting a bit long.

Ragards John.M
 
If you happen to have a street name (possibly with one or more spaces) then a street type then an area name you will have to modify the search slightly.

Sample reocrd: Thames Ferry Road Farnworth

Then modify the rat() function by adding a 3rd parameter to tell it to find the 2nd space from the right:

* get second rightmost space - should be between street name and type/area
vstreet = rat(" ",cstreet,2)
 
Hi dbmark,

Thanks for the info I will have a look asap a bit busy, what with car repairs, work, PC Repairs, Xmas decorations, etc etc etc.

Thanks again.
Regards John.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top