In answer to your reply with regarding your explanations
I made this little table
database | query | field | variable
=================================================
sold | SQLQuery1 | price | stringprice (selling)
tabelle2 | SQLQuery3 | price | variablePrice (buying)
4. After the insert I oben a procedure: Form2.closeDB;
In this procedure there is the Exec command.
Ah ok. Then all is ok. But be aware that 'omitting' that kind of information can cause serious confusion :-)
In case you can not share that part of the code, then just add some comment to your snippet:
// Perform the Exec function for the query so that the data get inserted,
// do this
// do that
// and finally close the database.
Form2.closeDB;
VariablePrice is the price in the database. stringprice is for a buying price and variablePrice is for sell.
Then why not name your variables BuyingPrice and SellingPrice :-)
That seems much clearer to me (and for anyone else that is looking at the code) ?
If the buy price is smaller than sell price, no trade is done. than the variable p is true/1
p is something like "check done". just for better understanding.
Ok.
But as another suggestion, if that variable can only have two 'states' "0" and "1", why then not make it a boolean ?
And would it not be more clear to then name that variable NoTrade, or DoneTrade, or in case you prefer the opposite YesTrade/WillTrade/CanTrade ?
if not .... the While starts at the lowest variablePrice.
Ok, then perhaps i misunderstand something. Your code states:
while ((variablePrice <= stringPrice) or (p < '1')) do
or in human language: if (BuyingPrice is smaller then or same as SellingPrice) or (Not(DoneTrade))
That is where i am starting to get a little worried as the comparison does not make sense to me (unless you wish to increase the BuyingPrice with the value two, up to the point it will be just at or over the SellingPrice).
And should you not be doing that loop for as long trading was not Done ? (both conditions should match ?)
First i select all information at this lowest price.
I assume you are refering to:
Form2.SQLQuery1.SQL.Text := 'SELECT * from sold WHERE price ='''+variablePrice+''';';
or in human-talk: Select all fields from database sold where the field price matches BuyingPrice
Which brings the question does the sold database actually have a SellingPrice that matches BuyingPrice ?
and then i check if my IF ELSE the strings with the variables, i select from the database.
If one IF ELSE fits than i assign P:=1
Or with my used variable name: DoneTrade := true;
if no IF ELSE fits, than the variablePrice is +2
Than i select every information which belongs to the new variablePrice.
Than I check my if else conditions again.
If nothing fits I add to the variablePrice 2 again.
and select the information which belongs to this new variablePrice again
and so own
I can see some conflicting information there with regards to your code.
I still assume that variablePrice is the BuyingPrice.
variablePrice := Form2.SQLQuery1.FieldByName('price').AsString;
which was taken from the query:
Form2.SQLQuery1.SQL.Text := 'SELECT * from sold WHERE price ='''+variablePrice+''';';
In my understanding you are assigning the field price from the sold database to the BuyingPrice variable ?
In case that is the intention of that code then (for better reading) there should be a third variable name to swap around the numbers (but perhaps that is the reason why you named your variable "variablePrice" ?)
Also, if you are doing this by adding 2 to the buying price and loop around, then would it not be more convenient to order the last sqlquery (by price) and take the approach by comparing the other way around ?
Perhaps none of what i wrote made any sense. If that is the case then that is ok, as i am also still struggling to fully understand your current code, so it might be i made a wrong assumption somewhere along the line.
Please feel free to correct me if that is the case, although i do hope you are able to get something positive out of my response (instead of you having other troubles right now).