View Full Version : 2 questions
Rune Hacker
07-28-2007, 05:34 PM
1.) If you have the string '5+5+5', is there a way for it to do the math and turn it back into a string? You can't turn it into an integer because the "+" symbol is not a whole number.
2.) Is it possible to open up a web page inside a form in any way (like maybe inside a TRichEdit or something, idk). If it can, can i use a little html code also so it does what i want?
Smartzkid
07-28-2007, 05:39 PM
You could (technically) make a webbrowser in SCAR, but you'd have to manually parse and render the html.
You could also parse a mathematical string to turn it into valid operations, but, no, SCAR has no functions to do it automatically.
Rune Hacker
07-28-2007, 05:58 PM
umm, could you explain that a little bit more please because i dont know what parse, render, and mathimatical string mean
Lalaji
07-28-2007, 06:14 PM
If you can make the string do the math then turn it back to a string, would that mean that a calculator can be created in scar with forms?
Rune Hacker
07-28-2007, 06:22 PM
its not possible to do the math while it is a string i believe.
itSchRis917
07-28-2007, 06:24 PM
Ok, well, here's what i got for the 1st question, it involves what Smartzkid said, but i think there has got to be a better way to do it..
program New;
var
ThingToAdd:String;
Procedure Thing;
Var
I, Number, Num, Each:Integer;
Begin
Number := StrToInt(TrimOthers(ThingToAdd));
For I := 0 to 2 do
Begin
Each:= StrToInt(Copy(Inttostr(Number), I, 1));
End;
Writeln(Inttostr(Each*3));
End;
begin
ThingToAdd := '5+5+5';
Thing;
end.
Smartzkid
07-28-2007, 06:26 PM
Parse:
with the calculator part, it'd be something like this:
for i := 1 to length(mathstring)do
begin
if(IsNumeric(mathstring[i]))then
tempnumber := tempnumber + StrToInt(mathstring[i]);
if(mathstring[i] := '+')then
//add
...
end;
Basically, parsing is the process of seperating a long string into smaller, usable strings.
Rendering the html would make it appear on the screen in the correct format.
Dynamite
07-28-2007, 06:28 PM
hi this is probably off topic but do i need to download an srl? i have scar divi cde 3.06
itSchRis917
07-28-2007, 06:40 PM
hi this is probably off topic but do i need to download an srl? i have scar divi cde 3.06
What the hell is wrong with you?!?!?!?!? GTFO!!! 8000000000 nub points for you bitch!
Click File -> Download SRL in DIVI.
Smartzkid
07-28-2007, 06:43 PM
Okay, I went ahead and made a parser for the math (it does everything left to right, parenthesis and order of operation are ignored)
program New;
var
OpStr: String;
function ParseOps(Operation: String): Integer;
var
Total, i: Integer;
Numbers: Array of Integer;
Ops: Array of Char;
begin;
for I := 1 to Length(Operation) do
begin
if(pos(Operation[I], '0123456789') <> 0)then
begin
SetLength(Numbers, Length(Numbers) + 1);
Numbers[Length(Numbers) - 1] := StrToInt(Operation[i]);
end;
if(pos(Operation[I], '+-*/\') <> 0)then
begin
SetLength(Ops, Length(Ops) + 1);
Ops[Length(Ops) - 1] := Operation[I];
end;
end;
total := Numbers[0];
for I := 0 to Length(Ops) - 1 do
begin
case Ops[i] of
'+' : total := total + Numbers[i + 1];
'-' : total := total - Numbers[i + 1];
'*' : total := total * Numbers[i + 1];
'/', '\' : total := total / Numbers[i + 1];
end;
end;
result := total;
End;
begin
OpStr:= '5 + 5 - 3 * 2 / 7 * 5';
WriteLn( IntToStr( ParseOps( OpStr ) ) );
end.
Edit: It also only works with one digit numbers; later today I'll adapt it to work with multiples if you want.
bullzeye95
07-28-2007, 06:48 PM
hi this is probably off topic but do i need to download an srl? i have scar divi cde 3.06
NOOBNOOBNOOBNOOBNOOBNOOBNOOBNOOBNOOBNOOBNOOBNOOB
You, The Man, have been reported for being a NOOB.
Your Current violations include Not Searching for http://itsat.tehintar.net/share/noobpoints.png (http://www.villavu.com/forum/showthread.php?t=5265) http://itsat.tehintar.net/share/noobpoints.png (http://www.villavu.com/forum/showthread.php?t=5265) http://itsat.tehintar.net/share/noobpoints.png (http://www.villavu.com/forum/showthread.php?t=5265)
Thread/ Off Topic Post for http://itsat.tehintar.net/share/noobpoints.png (http://www.villavu.com/forum/showthread.php?t=5265)
Useless Post for http://itsat.tehintar.net/share/noobpoints.png (http://www.villavu.com/forum/showthread.php?t=5265)
This brings you to a new total of http://itsat.tehintar.net/share/noobpoints.png (http://www.villavu.com/forum/showthread.php?t=5265)http://itsat.tehintar.net/share/noobpoints.png (http://www.villavu.com/forum/showthread.php?t=5265)http://itsat.tehintar.net/share/noobpoints.png (http://www.villavu.com/forum/showthread.php?t=5265)http://itsat.tehintar.net/share/noobpoints.png (http://www.villavu.com/forum/showthread.php?t=5265)http://itsat.tehintar.net/share/noobpoints.png (http://www.villavu.com/forum/showthread.php?t=5265) (5) Noob Points!
For more information on The Man (http://noobpoints.tehintar.net/noobadmin.php?noob_name=The+Man) please go Here. (http://noobpoints.tehintar.net/noobadmin.php?noob_name=The+Man)
For more information on Noobs (http://www.villavu.com/forum/showthread.php?t=5265) please go Here. (http://www.villavu.com/forum/showthread.php?t=5265)
NOOBNOOBNOOBNOOBNOOBNOOBNOOBNOOBNOOBNOOBNOOBNOOB
itSchRis917
07-28-2007, 06:48 PM
Yeah, use his RuneHacker... Lol, you just HAD to show me up..
@Bullzeye95: Only 5???
bullzeye95
07-28-2007, 06:50 PM
I wish I could give more, but the selection is limited :(
itSchRis917
07-28-2007, 07:13 PM
Dang. I think we should push for a change in the rule.. Just for him.. We can make a little exception..
Rune Hacker
07-28-2007, 09:54 PM
Wow Smartzkid, that is amazing. Barely any of that makes sense to me lol. Thanks, ill look at it and see what i can do, + rep
Smartzkid
07-30-2007, 11:20 PM
Many updates:
///////////////////////////////////////////////////////////
// ParseOps //
///////////////////////////////////////////////////////////
// ~~~~~~~~~~~ -By Smartzkid //
// ~Version 3~ //
// ~~~~~~~~~~~ //
// //
// Supports: //
// -Addition, Subtraction, Multiplication, and Division //
// -Multiple Operations (5 * 2 + 6) //
// -Negative Numbers (-2 * 8) //
// -Decimals in results (ParseOps -F and -FEx) //
// -Decimal Limiting (ParseOpsFEx) //
// //
// Coming Soon (hopefully): //
// -Decimals in operations //
// -Order of operations //
///////////////////////////////////////////////////////////
program ParseOps;
var
OpStr: String;
function ParseOpsF(Operation: String): Extended;
//By Smartzkid
//Parse Operation(s). Returns an extended integer (decimals)
var
i: Integer;
Total: Extended;
Numbers: Array of Integer;
Ops: Array of Char;
lastnum, NextNegative: Boolean;
begin;
I := 1;
while Operation[I] = ' ' do
I := I + 1;
if(Pos(Operation[I], '+-*/\') <> 0)then
Insert('0 ', Operation, 1);
for I := 1 to Length(Operation) do
begin
if(pos(Operation[I], '0123456789') <> 0)then
begin
if(lastnum)then
begin
Numbers[Length(Numbers) - 1] := (Numbers[Length(Numbers) - 1] * 10) + StrToInt(Operation[i]);
end else
begin
SetLength(Numbers, Length(Numbers) + 1);
Numbers[Length(Numbers) - 1] := StrToInt(Operation[i]);
if(NextNegative)then
begin
Numbers[Length(Numbers) - 1] := - Numbers[Length(Numbers) - 1];
NextNegative := false;
end;
lastnum := true;
end;
end;
if(pos(Operation[I], '+-*/\') <> 0)then
begin
if(not(lastnum))then
if(Operation[I] = '-')then
NextNegative := true
else
begin
writeln('Syntax error!');
result := -1;
Exit;
end;
if(not(NextNegative))then
begin
SetLength(Ops, Length(Ops) + 1);
Ops[Length(Ops) - 1] := Operation[I];
lastnum := false;
end;
end;
end;
total := Numbers[0];
for I := 0 to Length(Ops) - 1 do
begin
case Ops[i] of
'+' : total := total + Numbers[i + 1];
'-' : total := total - Numbers[i + 1];
'*' : total := total * Numbers[i + 1];
'/', '\' : begin
if(Numbers[i + 1] = 0)then
begin
writeln('Divide by zero error!')
result := -1;
Exit;
end else
total := total / Numbers[i + 1];
end;
end;
end;
result := total;
End;
function ParseOpsI(Operation: String): Integer;
//By Smartzkid
//Parse Operation(s). Returns an integer;
begin
result := Round(ParseOpsF(Operation));
end;
function ParseOpsFEx(Operation: String; DecDigits: Integer): Extended;
//By Smartzkid
//Parse Operation(s), limits amount of decimals to DecDigits. Returns an extended integer (decimals)
var
CutStr: String;
begin
result := ParseOpsF(Operation);
if(DecDigits < 0)then
DecDigits := -DecDigits;
CutStr := FloatToStr(result);
if(pos('.', CutStr) = 0)then Exit;
CutStr := Copy(CutStr, 0, pos('.', CutStr) + DecDigits);
result := StrToFloat(CutStr);
end;
begin
OpStr:= '20 * -5 / 3 + 52';
WriteLn( IntToStr( ParseOpsI( OpStr ) ) );
WriteLn( FloatToStr( ParseOpsFEx( OpStr, 2 ) ) );
WriteLn( FloatToStr( ParseOpsF( OpStr ) ) );
end.
Powered by vBulletin® Version 4.2.1 Copyright © 2024 vBulletin Solutions, Inc. All rights reserved.