Jump to content
kyoneko

Calculating and sending numbers

Recommended Posts

It has been a looong time since i have scripted anything with SCAR and most of my knowledge faded away to somewhere. But today i wanted to use it but i cant figure out how to do it anymore.

 

My basic idea is i want to type in a number by const L1. And then have L2 deduct 2 from that number. After that i want to have L2 writen somewhere on a external place like notepad or excel. What i have untill now does not seem to work in the slightest. Both calculating L2 and writing it out isn;t working properly. Here is my script in the hope someone can tell me what im doing wrong.

const
L1 = '281';

var
L2 : integer;

begin
L2 := L1-2;
wait(2000)
 typetext (L2)
end.

 

Kyon.

 

EDIT: I found part of the solution already. I had to replace typetext (L2) with typetext (IntToStr(L2)). But that still leaves the calculation itself thats not working yet.

Edited by kyoneko
Link to comment
Share on other sites

Ah ofcourse. That makes sence, thank you very much. How i managed to overlook that i dont even know. A other slight question. If i want to add a tab or a enter after that. How do i do that? I recall in the past it used to be something like sendchar(108) or keydown(108). But i cant seem ot figure out how to do that now.

Link to comment
Share on other sites

Ah ofcourse. That makes sence, thank you very much. How i managed to overlook that i dont even know. A other slight question. If i want to add a tab or a enter after that. How do i do that? I recall in the past it used to be something like sendchar(108) or keydown(108). But i cant seem ot figure out how to do that now.

VK_TAB and VK_RETURN??? Don't do a lot with keycodes. I always have to look them up.

Link to comment
Share on other sites

TypeText(IntToStr(L2));

 

I already stated in my first post i managed to solve that issue. But thanks for trying anyways. I got a extra minor problem. If i try to make L1 a decimal number. Like 281,5. I get a error message saying indentifier expected. Any way to get around this or push it through anyway? I tried to use a devide 1 by 2 to get a half and add that to 281. But neiter : nor / seems to devide anything.

 

..wait, what exactly are you trying to do?

 

Quite simple really. I want to make a bigger script which takes a number. Substracts and adds some numsers in diffrend variables. Then writes those out and presses enter. To make it simpler i conpressed it to one simpler part. All i need to know now is how to put in a command to make it press enter or tab. And now a resent problem is to figure how to put in decimal numbers.

 

You can do enter like this:

 

That worked indeed. Thank you very much. Now just the last minor thing and my day wouldn;t be able to get any better

Edited by kyoneko
Link to comment
Share on other sites

The script itself works as it should. But there is just one minor problem it gives me now. Sometimes when i ask it to write out its things it writes out decimal numbers with a comma in betwene, and somtimes with a period. I have no idea what makes it switch, or how to make it switch back. Normally this wont bother me but hte programm i use it on only accepts comma's. Anyone got any idea what makes SCAR switch betwene these two and how to make it switch when i want it to?

Link to comment
Share on other sites

No idea what causes this problem that you reported here, but here is a workaround, that you could use in your script:

 

function FloatToStrD(e: Extended): string;
begin
 Result := Replace(FloatToStr(e), ',', '.');
end;

function FloatToStrC(e: Extended): string;
begin
 Result := Replace(FloatToStr(e), '.', ',');
end;

begin
 WriteLn('Hey, this works: ' + FloatToStrD(1.2345)); 
 WriteLn('Hey, this works: ' + FloatToStrC(1.2345));
end.

 

-Jani

Edited by Janilabo
Link to comment
Share on other sites

Add those functions in your script and then replace all of the FloatToStr's with the method you need at certain parts of it?

 

- - - Updated - - -

 

Here is couple other workarounds, btw:

 

var
 decimalSeparator: Char;

function FloatToStr2(e: Extended): string;
begin
 Result := Replace(Replace(FloatToStr(e), ',', '.'), '.', decimalSeparator);
end;

begin
 ClearDebug;
 WriteLn('Hey, this works: ' + FloatToStr2(1.2345));
 decimalSeparator := ','; 
 WriteLn('Hey, this works: ' + FloatToStr2(1.2345));
 decimalSeparator := '.'; 
 WriteLn('Hey, this works: ' + FloatToStr2(1.2345));
 decimalSeparator := ','; 
 WriteLn('Hey, this works: ' + FloatToStr2(1.2345));
end.

 

..or...

 

function FloatToStrEx(e: Extended; decSep: Char): string;
begin
 Result := Replace(Replace(FloatToStr(e), ',', '.'), '.', decSep);
end;

begin
 ClearDebug;
 WriteLn('Hey, this works: ' + FloatToStrEx(1.2345, ' ')); 
 WriteLn('Hey, this works: ' + FloatToStrEx(1.2345, ','));
 WriteLn('Hey, this works: ' + FloatToStrEx(1.2345, '.'));
 WriteLn('Hey, this works: ' + FloatToStrEx(1.2345, ','));
end.

Edited by Janilabo
Link to comment
Share on other sites

Well yes. I tried that but i get Internal error (20) When i try that. I'll just pull out a part of my script to hopefully make it easyer.

 

var
A1, A1h, A1l, A1max, A1min : extended;

begin

A1   := 400;
A1h  := 0.4;
A1l  := 0.4;

A1max  := A1+A1h;
A1min  := A1-A1l;

wait(2000)
typetext(FloatToStr(A1) + #9 + FloatToStr(A1max) + #9 + FloatToStr(A1min));

end.

 

If i try to apply your code i get something like this.

 

var
A1, A1h, A1l, A1max, A1min : extended;

function FloatToStrC(e: Extended): string;
begin
 Result := Replace(FloatToStr(e), '.', ',');
end;



begin

A1   := 400;
A1h  := 0.4;
A1l  := 0.4;

A1max  := A1+A1h;
A1min  := A1-A1l;

wait(2000)
typetext(FloatToStrC(A1) + #9 + FloatToStrC(A1max) + #9 + FloatToStrC(A1min));

end.

 

OR i get

 

var
A1, A1h, A1l, A1max, A1min : extended;

function FloatToStrC(e: Extended): string;
begin
 Result := Replace(FloatToStr(e), '.', ',');
end;



begin

A1   := 400;
A1h  := 0.4;
A1l  := 0.4;

A1max  := A1+A1h;
A1min  := A1-A1l;

wait(2000)
typetext(FloatToStrC(FloatToSt(rA1)) + #9 + FloatToStrC(FloatToStr(A1max)) + #9 + FloatToStrC(FloatToStr(A1min)));

end.

 

Neiter of them seem to be working for me

Edited by kyoneko
Link to comment
Share on other sites

Well. That is certainly odd. I just retried it and it worked as well. Cant say i did anything diffrend at all. Eiter way thank you again for the help. Dont know it its related. but im using SCAR Devi 3.38 Portable edition because the place i work doesn;t allow me to install things.

Link to comment
Share on other sites

The bottom one of em is however problematic.

1. There's some typos in it.

2. Do NOT use FloatToStr inside FloatToStr[C|D|2|Ex]. That wont obviously work, because it would be incorrect type (string <> extended).

 

Simply, replace all the FloatToStr's with the function you are looking for (FloatToStr2, FloatToStrEx, FloatToStrC, FloatToStrP).

 

-Jani

Edited by Janilabo
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
  • Create New...