Forum > Windows
Measurement converter in Pascal
dzoole:
Hi, i' m a newbie in pascal programing. I have need for measurement converter in Pascal to use in Subtitle Workshop as pascal script.
Found some codes online for other converters, but can't figure out how to do it for example miles to kilometres.
Can someone help me to do it.
This is the pascal script.
unit units;
interface
uses
Classes,
Controls,
Dialogs,
Forms,
StrUtils,
SysUtils,
Variants,
Windows;
begin
function MilesToKillometres(MyNumber: variant): string;
function InchesToCentimetres(MyNumber: variant): string;
function FeetToCentrimetres(MyTens: variant): string;
function GalonsToLitres(MyDigit: variant): string;
implementation
function MilesToKillometres(MyNumber: variant): string;
var
Temp: string;
Miles, Killometres, Words: string;
km, iCount: string;
begin
//Find any number before miles
Words:= (MyNumber + 'miles');
end;
begin
//Convert Miles
Temp := LeftStr((MyNumber + 'miles') * 1,6);
km := ' and ' + ConvertMiles(Temp) + ' km';
end;
end.
winni:
Hi!
A simple solution which exstracts the number from a string,
coverts miles to km an gives a output:
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---function MilesToKm (miles: string) : string;var i : integer; mileVal, kmVal : single; tmp : string;begin tmp := ''; for i := 1 to length(miles) do if miles[i] in ['0'..'9','.'] then tmp := tmp+miles[i]; mileVal := strToFloat(tmp); kmVal := 1.609344 * mileVal; // kmVal := 1.852 * mileVal; ==>nautic mile result := FloatToStr(kmVal)+' Kilometer'; end;
The decimal separator in Pascal is a dot!
Winni
marcov:
In Free pascal/Lazarus, the unit with measurement conversions is convutils, and is modelled after the same unit in Delphi (though not 100% compatible yet)
Winni: strtofloat is locale dependent (using either comma or dot as decimal separator), while your set check isn't.
dzoole:
Thank you for your fast answer. And yes in my system locale , coma is decimal separator.
I'll try the script now, to see does it work in Subtitle Workshop.
I don't why but I can't compile it. When I run Subtitle Workshop says error compiler expected closed bracket ]
In Lazarus syntax check OK, but can't compile.
winni:
Hi!
For Lazarus error: show us the error message. We have no crystall balls.
For Subtitle Workshop: Ask there. This is a Lazarus/fpc Forum.
Winni
Navigation
[0] Message Index
[#] Next page