Solved

Newbie needs some info..

Posted on 1998-09-18
8
152 Views
Last Modified: 2010-04-06
Hello,
I really need some info to get me going. I am building a
conversion program and have a couple of questions:
1/ From a combobox with a list of 12 conversions the user
would enter a number to convert in an edit box then select from the
combobox which conversion to do then print the result on
screen. (eg..in to mm and meters to in.)
I need to understand how to code this. Can anyone supply
an example of this? I can get this to work only for the first combobox selection.Also I am using the StrToInt function with the Edit box but if my formula includes a
decimal point eg/ Value1 * 3.28 this will not compile unless
I use a 3 with no decimals.
0
Comment
Question by:frw
8 Comments
 

Author Comment

by:frw
ID: 1340164
Adjusted points to 100
0
 
LVL 10

Accepted Solution

by:
viktornet earned 100 total points
ID: 1340165
Here is an example....I have an EditBox on the form and its name is Edit1..here is some code to show you an example convertions....
---------
function CmToMeter(Cm : double):double;
begin
  Result := Cm / 100;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
   try
            //Use the case statement...
         //case ConvertionKind of
         //CmToMeterConv : ShowMessage(FloatToStr(CmToMeter(StrToFloat(Edit1.text))));
         //InchToMeterConv: ...
         ShowMessage(FloatToStr(CmToMeter(StrToFloat(Edit1.text)))+ ' Meter(s)');
   except
         On EConvertError do MessageDlg('Syntax Error', mtWarning, [mbOK], 0);
   end;
end;
---------
Regards,
Viktor Ivanov
0
 
LVL 10

Expert Comment

by:viktornet
ID: 1340166
I just wanted to give you the code and the comments separately so you don't think one is code and another is comment.....
---------Code----------
//This code is an example that works...just try it out...
function CmToMeter(Cm : double):double;
begin
  Result := Cm / 100;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
  try
   ShowMessage(FloatToStr(CmToMeter(StrToFloat(Edit1.text)))+ ' Meter(s)');
  except
    On EConvertError do
      MessageDlg('Syntax Error', mtWarning, [mbOK], 0);
   end;
end;
----Comments------
//Use the case statement...
//case ConvertionKind of
//  CmToMeterConv  : ShowMessage(FloatToStr(CmToMeter(StrToFloat(Edit1.text))));
//  InchToMeterConv: ...
-------End-----

Regards,
Viktor Ivanov
0
 
LVL 10

Expert Comment

by:viktornet
ID: 1340167
If you need other convertions just tell me the formula and I'll show you how to make the code..

//Vik
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 2

Expert Comment

by:kjteng
ID: 1340168
1. Add a onClick even for the ComboBox. Something like this:

procedure TForm1.ComboBox1Click(Sender: TObject);
var i: integer;
begin
  i := ComboBox1.ItemIndex;
  case i of
  0: {do type 0 conversion here};
  1: {do type 0 conversion here};
  2: {do type 0 conversion here};
  3: {do type 0 conversion here};
   ...
   ...
  end; {case}
end;

Please also set the  style property of the combobox to: csDropDownList

2. To use StrToInt(x) function, x must be a str containing nothing other than numeric digits. If you want to convert a float to string. Depending on the types of data you want to convert to and convert from, you may use these function:
str, textToFloat, strToFloat etc.


0
 
LVL 10

Expert Comment

by:viktornet
ID: 1340169
I got an application for you....Just tell me your e-mail address and I'll send it to you...

Regards,
Viktor Ivanov
0
 

Expert Comment

by:gmsacoda
ID: 1340170
I will explain using the default names created by DELPHI3

- Create a new aplication

- On a FORM1 create : COMBOBOX1, EDIT1, LABEL1

- select the FORM1 in object inspector
- doubleclick on the field ONCREATE
- insert the folowing code lines:
  COMBOBOX1.ITEMS.ADD('cm to in');
  COMBOBOX1.ITEMS.ADD('in to cm');
  ...

- select the combobox1 in object inspector
- doubleclick on the field ONCHANGE
- insert the folowing code lines:
  CASE COMBOBOX1.ITEMINDEX OF
  0:LABEL1.CAPTION:=FLOATTOSTR(STRTOFLOAT(EDIT1.TEXT)/2.54);
  1:LABEL1.CAPTION:=FLOATTOSTR(STRTOFLOAT(EDIT1.TEXT)*2.54);
  ...
  END; {case}

Regards
Gilberto
0
 
LVL 10

Expert Comment

by:viktornet
ID: 1340171
Hello frw!

I still got a ready application I created for you to show you a basic program that can convert CmToMeter, MeterToCm, PoundToKg, KgToPound... If you wanted just tell me your e-mail and I'll send it to you with full source code :-)

Regards,
Viktor Ivanov
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
delphi custom sort exception 6 135
error 1.1 400 Bad request idhttp delphi 18 54
Delphi application Soap connection 5 96
Mobile Keyboard covers the display of the TMemo 3 78
A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

911 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

14 Experts available now in Live!

Get 1:1 Help Now