The following code is supposed to use the data in the attatched file to generate a list of relavent houses available based on the specifacations that you enter. After I enter my prefered search method I can't get it to stop asking me how many bed/bathrooms or what price i want to search for. Could you guys help me out?

Here is the code:

'Ananda Bennett
'11/06/2006
'HHSS
OPEN "c:\homes.txt" FOR INPUT AS #1
PRINT"************************************"
PRINT"* 1 - Search by number of bedrooms *"
PRINT"* 2 - Search by number of bathrooms*"
PRINT"* 3 - Search by price *"
PRINT"************************************"
INPUT "What would you like to search for homes by?: "; schoice
CLS
DO WHILE EOF(#1) <> -1
INPUT #1, address$, city$, state$, proptype$, bedrooms, bathroom, price
SELECT CASE schoice
CASE 1
INPUT "How many bedrooms would you like to search by?; "; bedquant
IF bedquant = bedroom THEN
PRINT "Address: "; address$
PRINT "City: "; city$
PRINT "State: "; state$
PRINT "Prop. Type: "; proptype$
PRINT "Bedrooms: "; bedrooms; "Bathrooms: "; bathrooms; "Price: "; price;
PRINT "-----------------------------------------------------------------"
END IF
CASE 2
INPUT "How many bathrooms would you like to search by?; "; bathquant
IF bathquant = bedroom THEN
PRINT "Address: "; address$
PRINT "City: "; city$
PRINT "State: "; state$
PRINT "Prop. Type: "; proptype$
PRINT "Bedrooms: "; bedrooms; "Bathrooms: "; bathrooms; "Price: "; price;
PRINT "-----------------------------------------------------------------"
END IF
CASE 3
INPUT "What price would you like to search by?; "; prices
IF prices = price THEN
PRINT "Address: "; address$
PRINT "City: "; city$
PRINT "State: "; state$
PRINT "Prop. Type: "; proptype$
PRINT "Bedrooms: "; bedrooms; "Bathrooms: "; bathrooms; "Price: "; price;
PRINT "-----------------------------------------------------------------"
END IF
END SELECT
LOOP

Ananda:twisted:

Hi,

modify ur code this way,
remove the do while loop and the opening of txt file.
do not alter the select statemnet.

Print "************************************"
Print "* 1 - Search by number of bedrooms *"
Print "* 2 - Search by number of bathrooms*"
Print "* 3 - Search by price *"
Print "************************************"
INPUT "What would you like to search for homes by?: "; schoice
Input #1, address$, city$, State$, proptype$, bedrooms, bathroom, price
Select Case schoice
Case 1
INPUT "How many bedrooms would you like to search by?; "; bedquant
Open "c:\homes.txt" For Input As #1
DO WHILE EOF(#1) <> -1
If bedquant = bedroom Then
Print "Address: "; address$
Print "City: "; city$
Print "State: "; State$
Print "Prop. Type: "; proptype$
Print "Bedrooms: "; bedrooms; "Bathrooms: "; bathrooms; "Price: "; price;
Print "-----------------------------------------------------------------"
End If
Loop
Case 2
INPUT "How many bathrooms would you like to search by?; "; bathquant
Open "c:\homes.txt" For Input As #1
DO WHILE EOF(#1) <> -1
If bathquant = bedroom Then
Print "Address: "; address$
Print "City: "; city$
Print "State: "; State$
Print "Prop. Type: "; proptype$
Print "Bedrooms: "; bedrooms; "Bathrooms: "; bathrooms; "Price: "; price;
Print "-----------------------------------------------------------------"
End If
Loop
Case 3
INPUT "What price would you like to search by?; "; prices
Open "c:\homes.txt" For Input As #1
DO WHILE EOF(#1) <> -1
If prices = price Then
Print "Address: "; address$
Print "City: "; city$
Print "State: "; State$
Print "Prop. Type: "; proptype$
Print "Bedrooms: "; bedrooms; "Bathrooms: "; bathrooms; "Price: "; price;
Print "-----------------------------------------------------------------"
End If
Loop
End Select


Regards
Veena

Hi,

sorry, i forgot to tell u after end select, close the text file .

Regards

Veena

Hi,

sorry, i forgot to tell u after end select, close the text file .

Regards

Veena

Thank you very much!

I know you already have a reply, but I'll stick my 2 cents in anyway.

Your basic logic progression is to have the buyer select the criteria by which to search the houses offered, then search the house list and compile an additional list of properties which fit the buyer's criteria. The problem with your original code is that the do-while loop includes the input string for each criteria choice, and it will reiterate those input queries for every record in the file. I didn't count how many there were in your sample file, but it looked like well over 100.

Here's what I would have done. I would first get the customer's criteria, then open the house file for input and compare each listing to the customer's criteria. I would put each bit of info from each listing that met the criteria into arrays. The arrays could then either be printed to paper, screen, or to another text file. My code would look something like this:

(I have not plugged the code in to test it, since this is just to give you a new approach to the problem.)


'Ananda Bennett
'11/06/2006
'HHSS


dim counter(1) 'counter variable for array use

'the following are arrays for building the buyer's choice list

dim buyer_bed (10000)
dim buyer_bath(10000)
dim buyer_price(10000)
dim buyer_address$(10000)
dim buyer_city$(10000)
dim buyer_state$(10000)
dim buyer_proptype$(10000)

'Code Starts here --------------------------------------------------------

counter = 0

OPEN "c:\homes.txt" FOR INPUT AS #1

PRINT"************************************"
PRINT"* 1 - Search by number of bedrooms *"
PRINT"* 2 - Search by number of bathrooms*"
PRINT"* 3 - Search by price *"
PRINT"************************************"

INPUT "What would you like to search for homes by?: "; schoice
SELECT CASE schoice

CASE 1
INPUT "How many bedrooms would you like to search by?; "; bedquant

DO WHILE EOF(#1) <> -1
INPUT #1, address$, city$, state$, proptype$, bedrooms, bathroom, price

IF bedquant = bedroom THEN

counter = counter + 1 'increment counter for array
buyer_bed (counter) = bedrooms
buyer_bath(counter) = bathroom
buyer_price(counter) = price
buyer_address$(counter) = address$
buyer_city$(counter) = city$
buyer_state$(counter) = state$
buyer_proptype$(counter) = proptype$

END IF
LOOP

CASE 2
INPUT "How many bathrooms would you like to search by?; "; bathquant

DO WHILE EOF(#1) <> -1
INPUT #1, address$, city$, state$, proptype$, bedrooms, bathroom, price

IF bathquant = bedroom THEN

counter = counter + 1 'increment counter for array
buyer_bed (counter) = bedrooms
buyer_bath(counter) = bathroom
buyer_price(counter) = price
buyer_address$(counter) = address$
buyer_city$(counter) = city$
buyer_state$(counter) = state$
buyer_proptype$(counter) = proptype$

END IF
LOOP

CASE 3
INPUT "What price would you like to search by?; "; prices

DO WHILE EOF(#1) <> -1
INPUT #1, address$, city$, state$, proptype$, bedrooms, bathroom, price

IF prices = price THEN

counter = counter + 1 'increment counter for array
buyer_bed (counter) = bedrooms
buyer_bath(counter) = bathroom
buyer_price(counter) = price
buyer_address$(counter) = address$
buyer_city$(counter) = city$
buyer_state$(counter) = state$
buyer_proptype$(counter) = proptype$

END IF
LOOP

END SELECT

CLOSE #1

for x = 1 to counter
PRINT "Address: "; address$
PRINT "City: "; city$
PRINT "State: "; state$
PRINT "Prop. Type: "; proptype$
PRINT "Bedrooms: "; bedrooms; "Bathrooms: "; bathrooms; "Price: "; price
print""
next x

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.