Link to home
Start Free TrialLog in
Avatar of inthe
inthe

asked on

combobox help

hello
 first sorry for the lame amount of points i spent the rest going through all the old questions ,anyway here goes
I have a combobox loaded with integers (prices)like so:
$2.50
$1.75
$3.99
what i need to do is on a button click take a value
from an edit box (say 30) and take that value away
from the selected value in the combobox (say the $1.75)
to change the price.
i know the itemindex is the selected one but taking
away just changes the itemindex not not the selected texts value.
any help appreciated greatly.
ASKER CERTIFIED SOLUTION
Avatar of scrapdog
scrapdog
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Note:

I think that ItemIndex in the above code should be changed to

ComboBox1.ItemIndex


Avatar of inthe
inthe

ASKER

got a few errors ,tried a few work arounds to no avail
but have a better idea now .
im needing to change currency on other events as well so ill use a label instead.
I'll only have the combobox loaded with numbers now.
do you know a simple way of just changing the selected numbers value?
this is really helping me a lot and wish it was worth more
ive decided to give people who help me a mention in my programs "about box".ll also have to read the help files more i never new about the "val procedure".  
Hello Kevin!

What's up??? Finally got some free time on the weekend, and I'm reading the Assembler tutrials. I'm up to chapter 5, where actually the real assembler starts. How is everything going around ya???
///////////////////////////
A few notes:
-You didn't use the Val() function as it is suppose to be used....here is the right way
var
  a, Code: Integer;
begin
  Val(Edit1.Text, a, Code);
  if code = 0 then begin
  //rest of code goes here....
 end;
-Also check out the Str() function
Str(c, b);//is the right way to do... and there are also formattings so you can check them out too

InThe: What exactly is that you want to change????

Regards,
Viktor Ivanov
You need the val function to convert strings to numeric variables.  All values in a combo box are stored as strings.  In order to do mathematical operations, you must use numeric variables.

Str converts a numeric variable back to a string, in case you want to put it on a label or in a combo box.  I realize now that I made a mistake in the code I gave you:

change

c := b-a;

to

c := val(b)- a;
You can also use

Actually what I gave you isn't right about the Str() function since you need to keep the decimal point...   e.g. 1.75

so here is what to use instead...

b := Format('%f', [c]);

Hope this helps

Regards,
Viktor Ivanov
Ahh, Vik you are right.

I am accustomed to the standard Val function in Pascal (or maybe BASIC???).  Looking in the help file, I see that Val is a *procedure* in Delphi.

Speaking of assembler book, I haven't had time to get past first chapter!
Also change c :integer to c :real

Man, I better pay more attention to what I write!
Inthe:

Looking at your profile, I am curious.  You are building applications for the music industry.  What kind?  Software for making music (i.e trackers), or business applications for record companies, etc...

I am just curious because I am in the process of writing a tracker right now.
Same here.... What exactly is that that you are building???

Vik
Avatar of inthe

ASKER

hello again viktor & scrapdog
 Im an engineer/programmer at a company that makes cd's and cd roms ,bloody great job get to see all the good games before they go to market ;-) my other hobbie is making stuff with microchip pic's
 funny you say a tracker because the app's name is "Stock Tracker" yes its only a boring old stock database but i didnt want to use msaccess or a prebuilt database app and me and my mate at work (who by the way is teaching me assembler ,it's very difficult but i get to see how the systems really work in depth so its good in that way)thought this was an exellent way for me to properly learn delphi so we are building the whole thing from scratch.anyway im on holiday at the moment and decided to finish it at home and i cant get in touch with my mate for help for another 3 weeks so you guy's are like my saviors or something(did any of above make sense im very tired )
below is the code as i've got so far probably not right..
ignore takput and combobox1 they're getting the filename
to save prices to.
i get an error at  c := val(b)- a; (not enough parameters)

procedure TMainFrm.SpeedButton1Click(Sender: TObject);
var
 TakPut : String;
 b :string;
 c :real;
 a, Code: Integer;

  begin
 if MessageDlgPos('Are you sure? This will alter the stock',
    mtConfirmation, [mbOk, mbCancel], 0,230,330) = mrOk then
begin
   TakPut:=Combobox1.Text;  
    Val(Edit1.Text, a, Code);
    if code = 0 then begin
     b := eamount.Items[eamount.ItemIndex];
      b := copy(b,2,length(b));
     c := val(b) - a;
    b:=Format('%F',[C]);
   eamount.Items[eamount.ItemIndex] := b;
  eamount.items.savetofile(TakPut+'Am.dll'); //encrypted later
 end;
  end
 Else MessageDlgPos('Thankyou No Alterations were Made.',      mtInformation,[mbOk], 0,260,330);
 end;
 
ok dudes keep learning the asm im going to sleep
ps."The Art Of Assembly Language" by Randall Hyde is a good Book its on the net somewhere.are you using masm ,tasm
Hello InThe :-)

Here is how the code is suppose to look like,,,,

procedure TMainFrm.SpeedButton1Click(Sender: TObject);
     var
      TakPut : String;
      b :string;
      c :real;
      a, C1, c2: Integer;

       begin
      if MessageDlgPos('Are you sure? This will alter the stock',
         mtConfirmation, [mbOk, mbCancel], 0,230,330) = mrOk then
     begin
        TakPut:=Combobox1.Text;  
         Val(Edit1.Text, a, C1);
          b := eamount.Items[eamount.ItemIndex];
          b := copy(b,2,length(b));
         val(b, c, c2);
         if (c1 = 0)and(c2=0) then begin
         c :=  c - a;
         b:=Format('%F',[C]); //note : you need to use always numbers as 1.56 1.23 1.00
        eamount.Items[eamount.ItemIndex] := b;
       eamount.items.savetofile(TakPut+'Am.dll'); //encrypted later
         end;
       end
      Else MessageDlgPos('Thankyou No Alterations were
     Made.',      mtInformation,[mbOk], 0,260,330);
      end;

Haven't tested this but something like this should work :-)

Regards,
Viktor Ivanov
By the way.... I think the variable C has to be of type REAL not of type INTEGER... Go change that....

About the assembler language.... Yeah.. Kevin(ScrapDog) told me exactly about that book.. "The Art Of Assembly Language"....but I see that the author has used MASM to write the book, and I have only TASM and A86.... compilers..... Any ideas where I can get MASM preferably for free....???

10x to y'all

Regards,
Viktor Ivanov

Regards,
Viktor Ivanov
Oh, one more change is needed.... change this code....
b:=Format('%F',[C]);

to this one,,,

b:=Format('$%F',[C]);

Ok, I guess that's all...if you need more hlpe let us know :-)

Regards,
Viktor Ivanov
Avatar of inthe

ASKER

Thankyou scrapdog and viktor.

Viktor if your serious about masm mail me and i'll sort something out for you mail to : inthe@future.easyspace.com
Hello again!

I told you about the variable C to be of type REAL... Now I see that it is of type REAL. What I meant was that you need to change the variable A from an INTEGER to a REAL.. Sorry for the misstyping :(
Vik:

TASM can assemble source code written for MASM (I think).

Even though the author used MASM, you can get by using either TASM or A86.  A86 requires no red tape at all.  The directives that will be of interest to you are pretty much similar for all three assemblers...