Forum > Windows

Measurement converter in Pascal

<< < (3/4) > >>

marcov:

--- 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";}};} ---program doconvertmilestokm;{$mode delphi} uses  ConvUtils,stdconvs,sysutils;   var  miles,kilometers : Double; begin  // Define the miles value  miles := 1;   // Convert to km  kilometers := Convert(miles, duMiles, duKilometers);   // Display both values  writeln(format('%f miles  = %f kilometers',[miles,kilometers ]));end. 

dzoole:
Now says coudn't identify ConvUtils.
Never mind, thanks anyway for your time.

af0815:

--- Quote from: dzoole on March 16, 2022, 10:26:14 pm ---Now says coudn't identify ConvUtils.

--- End quote ---
You are not using fpc/Lazarus. Are you using Subtitle workshop with pascalscript ?

In Lazarus you have to make a new program with 'Project->New Project->Simple Program' to create a new programm and insert the sample code.

dbannon:
dz, if all you want to do is convert miles to kilometers, just multiply by 1.609, does not need any special units at all. Its a simple floating point calc, ability to do that is there already.

Do you really need a Pascal Script ?  Or just a binary called, eg miles2km ? A line of code to check you have a just a number on the command line, a line of code to multiply it by 1.609, write that to std out.

Davo

dzoole:
I'm not using Subtitle Workshop to compile. I'm using it for subtitles, but if there is some problem with pascal scripts, subtitle workshop gives an info.
Subtitle Workshop is write in Delphi and can use pascal scripts for bunch of things with subtitles. Most of them are for timings, FPS, etc...
So the idea was this.
I don't know how to write those in Pascal.
Find any number before word miles and than multiple that number to 1.6 and replace word miles with kilometres.
And the idea was to add this type of conversion for feet to meters, inches to centimetres etc, etc..

Too bad that i can't multiple in reg ex
In reg ex i can only mark "miles" and convert into text "x1.6 kilometres" which will be reminder to turn on calculator and calculate.
<ERROR Find="[^0-9](miles)" ReplaceBy="x1.6 kilometres">

Find some pascal script for conversions without System.ConvUnits.
In the attachment

I don't know how to adapt for my purpose.

Navigation

[0] Message Index

[#] Next page

[*] Previous page

Go to full version