Solved

combobox help

Posted on 1998-10-17
17
351 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
  • 7
  • 7
  • 3
17 Comments
 
LVL 5

Accepted Solution

by:
scrapdog earned 10 total points
Comment Utility
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
Comment Utility
Note:

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

ComboBox1.ItemIndex


0
 
LVL 17

Author Comment

by:inthe
Comment Utility
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
 
LVL 10

Expert Comment

by:viktornet
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
Also change c :integer to c :real

Man, I better pay more attention to what I write!
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 5

Expert Comment

by:scrapdog
Comment Utility
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
Comment Utility
Same here.... What exactly is that that you are building???

Vik
0
 
LVL 17

Author Comment

by:inthe
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Suggested Solutions

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
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…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
This video discusses moving either the default database or any database to a new volume.

744 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now