[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

combobox help

Posted on 1998-10-17
17
Medium Priority
?
395 Views
Last Modified: 2011-09-20
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.
0
Comment
Question by:inthe
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 7
  • 7
  • 3
17 Comments
 
LVL 5

Accepted Solution

by:
scrapdog earned 40 total points
ID: 1343258
procedure TForm1.Button1Click(Sender: TObject);
var b :string;
    a,c :integer;
begin
  a := val(Edit1.Text);
  b := ComboBox1.Items[ItemIndex];
  b := copy(b,2,length(b));           //removes $ sign
  c := b-a;

                      //c now holds the new price


                      //if you want to place this back in the combo box
                      //use the next three lines

  Str(c:6:2,b);       //change the formatting (:6:2) to fit your needs
  b := '$'+b;
  ComboBox1.Items[ItemIndex] := b;
end;



I did not test this, but hopefully you can figure out how it works.
0
 
LVL 5

Expert Comment

by:scrapdog
ID: 1343259
Note:

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

ComboBox1.ItemIndex


0
 
LVL 17

Author Comment

by:inthe
ID: 1343260
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".  
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 10

Expert Comment

by:viktornet
ID: 1343261
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
0
 
LVL 5

Expert Comment

by:scrapdog
ID: 1343262
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;
0
 
LVL 10

Expert Comment

by:viktornet
ID: 1343263
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
0
 
LVL 5

Expert Comment

by:scrapdog
ID: 1343264
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!
0
 
LVL 5

Expert Comment

by:scrapdog
ID: 1343265
Also change c :integer to c :real

Man, I better pay more attention to what I write!
0
 
LVL 5

Expert Comment

by:scrapdog
ID: 1343266
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.
0
 
LVL 10

Expert Comment

by:viktornet
ID: 1343267
Same here.... What exactly is that that you are building???

Vik
0
 
LVL 17

Author Comment

by:inthe
ID: 1343268
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
0
 
LVL 10

Expert Comment

by:viktornet
ID: 1343269
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
0
 
LVL 10

Expert Comment

by:viktornet
ID: 1343270
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
0
 
LVL 10

Expert Comment

by:viktornet
ID: 1343271
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
0
 
LVL 17

Author Comment

by:inthe
ID: 1343272
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
0
 
LVL 10

Expert Comment

by:viktornet
ID: 1343273
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 :(
0
 
LVL 5

Expert Comment

by:scrapdog
ID: 1343274
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...
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
Suggested Courses

656 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question