count the results with combobox select

Hi, when i select "sale ok" i am adding to the database in field [13] called "testing 33".
this adds fine
So please dont include that in the code.

I want to be able to do this following:  I know the code is wrong but it willhelp explain what i need.

if
 DB5.Text=('Sale ok') and the labelsales:=('test33')
 then begin
form1.label1.caption :=  form1.adotable2.Fields[13].AsString; < must count
  end;

==============

I want it so when it adss to the label it counts.. so if i add 10 sales thelabel reads 10
please dont use posex or query as i need this part simple.#

thnx




if i have to edit the sale and give a refund, i will make change the status of sale ok to something.. and update. I then want it to take away the count igave it in label 1. for example if i sell 10 and refund someone,i change status of sale ok, label needs to say sold 9
boycoderAsked:
Who is Participating?
 
jimyXCommented:
You can't use both of inc and dec in the same place otherwise you get wrong value.
When a sales is made you increase the counter:
if (DB5.Text= 'Sale ok') and (labelsales.caption = '3 Months Membership') then
begin
  inc(counter);
  form1.label3.Caption :=  IntToStr(counter);
end;

Open in new window


And now, where do you click to make refund? Or how do you make refund?
At the moment you refund any sales you decrease the counter:
  dec(counter);
  if counter >= 0 then  // to avoid negative values unless it is required
    begin
      form1.label3.Caption :=  IntToStr(counter);
    end
  else
    counter := 0;

Open in new window

0
 
Geert GOracle dbaCommented:
you don't have english as your main language ???
your question is hard to follow !

and rename your components to something understandable

like
DB5 > dbSaleStatus
Label55 > lblTest33
AdoTable2 > tableSales
label1 > lblNumRecords

your identation is very odd

if dbSaleStatus.Text= 'Sale ok' and lblTest33 = 'test33' then
begin
  lblNumRecords.Caption :=  tableSales.Fields[7].AsString;
end;

0
 
fromerCommented:
var
  code : Integer;
  currentValue : Integer;
begin
   Val(form1.label1.caption, currentValue, code);
  if code <> 0 then
  begin
    currentValue := 0;
  end;

  form1.label1.caption := IntToStr(currentValue + 1);

  or

  form1.label1.caption := currentValue + form1.adotable2.Fields[7].AsInteger;
end;


if you are assigning form1.label.caption := '0' at the beginning,
you can skip the code
   Val(form1.label1.caption, currentValue, code);
  if code <> 0 then
  begin
    currentValue := 0;
  end;


it's really hard to understand what you want..you may give more information about what you are trying to do..


0
Cloud Class® Course: Microsoft Windows 7 Basic

This introductory course to Windows 7 environment will teach you about working with the Windows operating system. You will learn about basic functions including start menu; the desktop; managing files, folders, and libraries.

 
boycoderAuthor Commented:
Hi thanks, this keyboard is very stick sorry about that and i am doing so many things at once, i should be more clear. Anyway, i tried that and it didnt work. Please dont change the components i use as they are in my program about 100 times over.

Here is the code you gave me with the correct components and the error i get is:
incompitible types string and tlabel


if DB5.Text= 'Sale ok' and labelsales = 'test33' then
begin
  form1.label1.Caption :=  adotable2.Fields[13].AsString;
end;
0
 
boycoderAuthor Commented:
Ok i will explain what i want to do and you may have a better way, simple as possible.
I am trying to do the following:

when i select "sale ok" and also if labelsales has the word "test33"
then and only then add to my form1.label1 a value.
else.. do nothing

Each time i add a sale (when i click sale ok ) it adds another value to the form1.label1.

So, now if i add 2 sales the label would read you have sold 2

0
 
Geert GOracle dbaCommented:
if you are inside the code of TForm1
then remove all the usages of Form1.

Instead use Self.

this is a common mistake with beginning delphi programmers
(also with experienced ones ...)

in my opinion using any reference to a form variable is a mistake
(
except in the creation of a instance of a class)

Why do you use () around text ????

if DB5.Text='Sale ok' and labelsales = 'test33' then
begin
  label1.caption :=  adotable2.Fields[13].AsString; < must count
end;
0
 
Geert GOracle dbaCommented:
var temp: string;
if DB5.Text= 'Sale ok' and labelsales.caption = 'test33' then
begin
  temp := form1.label1.Caption;
  if Temp = '' then Temp := '0';
  form1.label1.Caption :=  IntToStr(StrToInt(Temp) + 1);
end;
0
 
fromerCommented:
DB5.Text=('Sale ok') and the labelsales:=('test33')
 then begin
 form1.label1.tag := form1.label1.tag + 1;
form1.label1.caption :=  form1.adotable2.Fields[13].AsString + IntToStr(form1.label1.tag);
  end;

i think you want this, cause you mentioned about posex :)...
0
 
Ephraim WangoyaCommented:


if (DB5.Text= 'Sale ok') and (labelsales.caption = 'test33') then
begin
   form1.label1.Caption :=  IntToStr(StrToIntDef(form1.label1.Caption, 0) + 1);
end;
0
 
boycoderAuthor Commented:
Thanks for the code both, but i amusing form1.label1 as i am working on form13.

I tested both codes and both give different error's.
Thanks for your help so far, but still not working or compiling Cheers

btw, i put () around text when i want to add  a further explanation, just basic english grammar.
0
 
boycoderAuthor Commented:
testing new code now
0
 
boycoderAuthor Commented:
thanks the code works great, however if i click sale ok and click submit, it obviously counts correct.

But, if i click on the customer again and read some details and re-click the button again it is going to add it twice as a value. Is there a way that once i click sale ok on a customer's form, it doesnt read it again if i reclick on him and hit the submit button again.

I have another field of a username? would this help? so we can add the sale ok + labesales + username ?

Would that work?
0
 
jimyXCommented:
Hi Boycoder,
Let's take it step by step please.
I assume DB5 is a combobox and the labelsales is a Label.
You want to check if "DB5" is 'Sale OK' and if the "labelsales" is 'test33' but what are the possible values that you might have in DB5 and labelsales?
What I am trying to know here is this do those words 'Sale OK' and 'test33' exist as a whole word or among other words? If yes, then the following code should show you the message 'Increase one'.
if (pos(uppercase('Sale ok'), uppercase(DB5.Text))>0) and (pos(uppercase('test33'), uppercase(labelsales.caption))>0) then
  begin
    showmessage('increase one');
  end;

Open in new window


Do you get that message?

Now this is a step 1, let us work on it and then we move to the second part (increase and decrease) OK?
0
 
Ephraim WangoyaCommented:

I think you need to re-evaluate your database design. You want to store the total for each customer but you can not do it on a label. you atleast need a filed in your database called TotalSales

In which case you will have your code as

if (DB5.Text= 'Sale ok') and (labelsales.caption = 'test33') then
begin
   form1.label1.Caption :=  IntToStr(form1.adotable2.FieldByName('TotalSales').AsInteger + 1);
end;

This way the total is stored for each customer separately.
This is my suggestion so you dont have to do all this unnecessary conversions from string to integer and your data is stored properly
0
 
boycoderAuthor Commented:
Jimmy,thanks mate i will check yours very soon as i actually want to test what you did as i can learn alot from that, so much. Cheers.

Ewangoya, thanks. That is the right idea, and yes i have a databse entry for that. However, i test it and when i click submit i have the error "test33 is not a valid integer value"

thanks very much for your input mate. Nearly there :)
0
 
boycoderAuthor Commented:
The code i am using to keep you updated is:

if (DB5.Text= 'Sale ok') and (labelsales.caption = 'test33') then
begin
   form1.label3.Caption :=  IntToStr(form1.adotable2.FieldByName('sales').AsInteger + 1);
end;
0
 
boycoderAuthor Commented:
However in the "sales" part of the table, the caption in the properties obj inspector is "Type of sale" if that helps.
0
 
Geert GOracle dbaCommented:
your approach is wrong by design

when you i enter a new sale in my system :
  > new sale header record > status > entry
  > add new sale items
  > after finishing, change the sale header status to finished

> after the sale status is changed to finished, use a trigger to increment a day count for the sales of that day for that user

this is all database work because of the possible multi-user environment
and because the person entering the sale items can jump from 1 terminal to another

don't ever think that somebody will remain on only 1 workstation in a shop
sometimes they have to follow the customer around the shop entering 1 item at a time from different workstations
0
 
boycoderAuthor Commented:
This is not a shop its just a small company that i run from my laptop. Its only going to ever stay on the laptop.
I cant use a trigger like that as the query is not reliable for date/time i need to to be accurate.
0
 
Geert GOracle dbaCommented:
you can't have it any more accurate or reliable except in a trigger
you really need to work out your design
0
 
boycoderAuthor Commented:
The design i have works perfect and is what i need. Ive been using this program i made for over a year now and tweaked to perfection, i just need to do some new updates to it that i am doing in these few weeks. This being one of them.

ewangoya's example looks similar to what i want as labelsales.caption just reads from the tablefield anyway.
0
 
boycoderAuthor Commented:
if (DB5.Text= 'Sale ok') and (labelsales.caption = 'test33') then
begin
   form1.label3.Caption :=  IntToStr(form1.adotable2.FieldByName('sales').AsInteger + 1);
end;


Update: If i remove the l(abelsales.caption = 'test33')  and try it , it gives the same error, like it's telling me that the text inside adotabe2.byfieldname('sales') is not a correct integer. The text in there is the same as the labelsales.

0
 
jimyXCommented:
What is the datatype of the field "Sales" is it Integer or Real?
If it's Real then:
if (DB5.Text= 'Sale ok') and (labelsales.caption = 'test33') then
begin
   form1.label3.Caption :=  FloatToStr(form1.adotable2.FieldByName('sales').AsFloat + 1);
end;

Open in new window

0
 
jimyXCommented:
>   "The text in there is the same as the labelsales"

Can you show a sample value of what the field "Sales" might be.

Can you show what you have in the label when you do this:
if (DB5.Text= 'Sale ok') and (labelsales.caption = 'test33') then
begin
   form1.label3.Caption :=  form1.adotable2.FieldByName('sales').AsString;
end;

Open in new window

0
 
boycoderAuthor Commented:
Yea sure.

I wont bother with the test33 thing, ill just use the actual code.

The field entry inside adotable2.FieldByName('sales') is '3 Months Membership'

You think the "3" is throwing it off as a value ?


labelsales.caption reads from the database inside "sales" when the form is opened. This reads as "3 Months Membership"

0
 
jimyXCommented:
Is "3" is the number that you are looking for to add 1 to it whenever sales is made?
like when doing "form1.label3.Caption :=  form1.adotable2.FieldByName('sales').Value + 1" you want the form1.label3.caption to be 4. Is that true?

0
 
boycoderAuthor Commented:
depending on what the customer wants, "3 Months Membership" or "15 Months Membership" and "1 Months Membership". These are added to the databse when the serial codes are added. These are located inside tabel2 in field "sales". So when i click on for example , a 3 month form to send him a serial code, when the form loads it pulls the text from "sales" into sales.caption. In this example, it is "3 Months Membership"

I want it so, after i fill the customers address in and other info and when "sale ok" is selected from the combobox and i click submit.

It shows on form1.label3 a value so i can keep track of how many i sell.. so each sale i make of a 3 month membership keeps adding up on form1.label3.

10 sales would be label3.caption  10

0
 
jimyXCommented:
I need more details please.

Does that relate to the value of the field Sales? I mean do you use the "3 month membership" whenever you are increasing the sales counter?

Because what you can do is having a counter for sales and whenever a sales is made you increase the counter. Something like:
var
  counter:integer=0;
...

if (DB5.Text= 'Sale ok') and (labelsales.caption = 'test33') then
begin
  inc(counter);
  form1.label3.Caption :=  IntToStr(counter);
end;

Open in new window


But what happens when you close your application an reopen it, does that label still remember the value in it?
0
 
Geert GOracle dbaCommented:
does it have to add these values in memory
or keep a counter even when you shutdown your laptop ?

keep in mind that not naming your components/controls to something better than label1, form1, edit15, adotable624567
will always make people ask questions what each component is for

just imagine when you would give this to somebody else to extend
and have 300 forms with each 20 components on
or ask help on a site like this ... it would be hell
but that's what programming is ... isn't it ?
0
 
boycoderAuthor Commented:
Thanks for the help again, noi t doesnt need to keep them in memory.
But, jim when i compile that it gives an error, but when i remove the 0 from the counter:integer=0;
it compiles, counts, but doesnt count above 1. I know i need to keep the correct code just to keep you updated.

I will be refreshing the program each day anyway, so i only need to count sales during the day.
0
 
jimyXCommented:
>   "but when i remove the 0 from the counter:integer=0; it compiles"

The initialization of the counter should be in the global VAR as follows:
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs;

type
  TForm1 = class(TForm)
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;
  counter:integer=0;

implementation

{$R *.dfm}

...

Open in new window


If that is not giving you the result you are expecting, could you please demonstrate your idea by applying it in a scenario where the values are entered and the expected results are shown. For example, show the current values and when and operation (such as sales) is performed update the values showing what's expected to happen.
0
 
boycoderAuthor Commented:
That works, thanks very much that is excellent. However, if i relick on the customer to view the details and if i change the combobox from sale ok to another selection, and click update, the caption takes the value away from the label ?

for example, say i have to refund someone after the sale is counted .
0
 
boycoderAuthor Commented:
sorry i mean to say "can the caption label change from 2" to "1" if i sold 2 but have to refund someone.
0
 
jimyXCommented:
For refund use:
  dec(counter);
  if counter >= 0 then  // to avoid negative values unless it is required
    form1.label3.Caption :=  IntToStr(counter);

Open in new window

0
 
jimyXCommented:
Update:
  dec(counter);
  if counter >= 0 then  // to avoid negative values unless it is required
    begin
      form1.label3.Caption :=  IntToStr(counter);
    end
  else
    counter := 0;

Open in new window

0
 
boycoderAuthor Commented:
In cant seem to get it to count again mate, this is the code i am using.


if (DB5.Text= 'Sale ok') and (labelsales.caption = '3 Months Membership') then
begin
  inc(counter);
  form1.label3.Caption :=  IntToStr(counter);
  dec(counter);
  if counter >= 0 then  // to avoid negative values unless it is required
    begin
      form1.label3.Caption :=  IntToStr(counter);
    end
  else
    counter := 0;
0
 
boycoderAuthor Commented:
should i add an else end begin in there?
0
 
Geert GOracle dbaCommented:
it doesn't have to keep the count in memory
but you don't want a solution which does it in the database ...
  because you don't want it with a query ... or a update statement ...

it's either one or the other

you are getting solutions in memory from jimyX, direction ... but the design is inadequate
you haven't any idea what you really want ... get pen and paper and write down what you expect

you aren't going anywhere if you don't have a clear direction where you want to go
0
 
boycoderAuthor Commented:
When i make a refund i use the combobox1.
sale ok is located in there too.

If i select "3 Months Membership" from combobox1 that would refund.
0
 
boycoderAuthor Commented:
Sorry when i say combobox1, i mean DB5.TEXT
0
 
boycoderAuthor Commented:
if (DB5.Text= '3 Months Membership') then
  dec(counter);
  if counter >= 0 then  // to avoid negative values unless it is required
    begin
      form1.label3.Caption :=  IntToStr(counter);
    end
  else
    counter := 0;


that works!!!
0
 
boycoderAuthor Commented:
To all who helped, thanks very much, =)

Jim, thanks very much mate i really appreciate what you have done. Thanks for your expert help in this matter.
0
 
boycoderAuthor Commented:
A++++++++++++++++
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.