I get this error:
when I try to use thisCode:[Error] C:\Simba\Scripts\Responder.simba(26:34): Type mismatch at line 25
Simba Code:If Text = (['Hi','Hey','Sup']) Then
I don't get what im doing wrong
I get this error:
when I try to use thisCode:[Error] C:\Simba\Scripts\Responder.simba(26:34): Type mismatch at line 25
Simba Code:If Text = (['Hi','Hey','Sup']) Then
I don't get what im doing wrong
Simba Code:var
text : string;
begin
text := 'hi';
if (text = 'hi') then
writeln('these strings match');
end.
OT: you can't compare a string to a string array without using a loop.
Simba Code:var
text : string;
i : integer;
texts : TStringArray;
begin
text := 'hi';
texts := ['ha', 'he', 'hi'];
for i := 0 to 2 do
if (text = texts[i]) then
writeln('these strings match'); // could break out too
end.
I believe the brackets must be around the entire if statement, because brackets normally imply that whatever's inside them must be calculated first, when doing math for example 3x3x3 vs (3x3)x3, and if you do it the way you did it, I believe the interpreter thinks the array is a bool, so you are trying to conpare a string to a bool, it may work without any brackets, but like Jingle did, Put the brackets around the entire statement and its fine
If that makes any sense3am
Programming is like trying keep a wall of shifting sand up, you fix one thing but somewhere else starts crumbling
If you're trying to see check if Text (which I assume is a string) is one of those three strings, you can use StrInArr. Does just what Jingle said, but it's easier to use.
EDIT:
This isn't correct. Parentheses don't do any type conversion or anything, it just affects precedence. He's getting the error because he's trying to compare a string to an array of string.
Just to show you a comparison, this works fine:
Simba Code:begin
if [5] = ([6]) then
Writeln('wat')
else
Writeln('ok');
end.
Last edited by i luffs yeww; 02-06-2013 at 02:22 AM.
Ah my mistake, didn't see OP was an array, but i'm sure something along the lines of this gave me errors before
Maybe it was using notCode:If string = (string) Then
Something with a string requires correct brackets, I just can't remember what lolCode:If Not string = string Then
Programming is like trying keep a wall of shifting sand up, you fix one thing but somewhere else starts crumbling
Yeah that's probably the cause of your error, since the 'not' keyword takes precedence over all other Boolean operators, which in turn take precedence over all arithmetic operators, hence giving an error as Boolean operators cannot be used on strings in Pascal. (Hence the use of parenthesis to override these orders)
thanks
There are currently 1 users browsing this thread. (0 members and 1 guests)