SRL Archive - Help

Problem with math


rj

2012-12-22 14:16:43

I keep getting a error at this line:

Writeln('' + ToStr(logscut) + ' logs cut/fletched' + (HowManyCut-(ToStr(logscut)) + 'left');

[Error] C:\Users\*\Desktop\simba\Scripts\MaplePowerCut 2.0.simba(371:87): Type mismatch at line 370
Compiling failed.

I don't get what the problem is?

Killerdou

2012-12-22 14:26:24

(HowManyCut-(ToStr(logscut)) ===> ToStr(HowManyCut-logscut) ?

rj

2012-12-22 14:28:05

From: Killerdou
(HowManyCut-(ToStr(logscut)) ===> ToStr(HowManyCut-logscut) ?


HowManyCut is a variable were the user inputs in a box how many they want the script to cut so I cant do that for both of them can i?

I put

Writeln('' + ToStr(logscut) + ' logs cut/fletched' + ToStr(HowManyCut-logscut) + 'left');

got the same error

J J

2012-12-22 14:58:55

From: rjj95
I keep getting a error at this line:

Writeln('' + ToStr(logscut) + ' logs cut/fletched' + (HowManyCut-(ToStr(logscut)) + 'left');

[Error] C:\Users\*\Desktop\simba\Scripts\MaplePowerCut 2.0.simba(371:87): Type mismatch at line 370
Compiling failed.

I don't get what the problem is?

The problem is here:
(HowManyCut-(ToStr(logscut)) 
HowManyCut is an Integer
LogsCut is an Integer
The first thing that gets executed is the convertion of LogsCut to a String
Then you try to substract LogsCut from HowManyCut.
So that means (Integer - String) -> Type mismatch.

Also, considering all results are Integers you can use IntToStr instead of letting Simba convert it to something printable with ToString.

program Test;
{$i srl/srl.simba}

procedure Test;
var
LogsCut, HowManyCut: Integer;

begin
HowManyCut := 500;
LogsCut := 25;

Writeln('We have fletched ' + IntToStr(logscut) + ' logs, this means we have '
+ IntToStr(HowManyCut-LogsCut) + ' left to fletch');
end;

begin
SetupSRL;
Test;
end.

Result: We have fletched 25 logs, this means we have 475 left to fletch

rj

2012-12-22 15:01:50

From: J J
The problem is here:
(HowManyCut-(ToStr(logscut)) 
HowManyCut is an Integer
LogsCut is an Integer
The first thing that gets executed is the convertion of LogsCut to a String
Then you try to substract LogsCut from HowManyCut.
So that means (Integer - String) -> Type mismatch.

Also, considering all results are Integers you can use IntToStr instead of letting Simba convert it to something printable with ToString.

program Test;
{$i srl/srl.simba}

procedure Test;
var
LogsCut, HowManyCut: Integer;

begin
HowManyCut := 500;
LogsCut := 25;

Writeln('We have fletched ' + IntToStr(logscut) + ' logs, this means we have '
+ IntToStr(HowManyCut-LogsCut) + ' left to fletch');
end;

begin
SetupSRL;
Test;
end.

Result: We have fletched 25 logs, this means we have 475 left to fletch


I get the same error, HowManyCut is a string declared here:
If (InputQuery('How many Logs to you want to cut?', 'Enter Number:' , HowManyCut)) Then

I think thats the problem

J J

2012-12-22 15:15:58

Then you can convert a String to an Integer using StrToInt
program Test;
{$i srl/srl.simba}

procedure Test;
var
HowManyCut: String;
LogsCut: Integer;

begin
HowManyCut := '500';
LogsCut := 25;

Writeln('We have fletched ' + IntToStr(logscut) + ' logs, this means we have '
+ IntToStr(StrToInt(HowManyCut)-LogsCut) + ' left to fletch');
end;

begin
SetupSRL;
Test;
end.

rj

2012-12-22 16:33:37

From: J J
Then you can convert a String to an Integer using StrToInt
program Test;
{$i srl/srl.simba}

procedure Test;
var
HowManyCut: String;
LogsCut: Integer;

begin
HowManyCut := '500';
LogsCut := 25;

Writeln('We have fletched ' + IntToStr(logscut) + ' logs, this means we have '
+ IntToStr(StrToInt(HowManyCut)-LogsCut) + ' left to fletch');
end;

begin
SetupSRL;
Test;
end.


Thanks! worked great