Author Topic: checking if input is integer, string, etc. [solved]  (Read 801 times)

0 Members and 1 Guest are viewing this topic.

Offline y0uRd34th

  • Camper
  • ***
  • Posts: 325
  • [i]Look Signature![/i]
checking if input is integer, string, etc. [solved]
« on: November 05, 2009, 05:46:54 am »
I'm not sure if i remember it right, but i thinked i've seen that somewhere, so..
Is there a way to check if the input in a func./proc. is integer, string, etc.? (input is variant)
« Last Edit: November 05, 2009, 06:11:53 am by y0uRd34th »

Offline DorkeyDear

  • Veteran
  • *****
  • Posts: 1507
  • I also go by Curt or menturi
Re: checking if input is integer, string, etc.
« Reply #1 on: November 05, 2009, 06:05:59 am »
The VarType function will return a numeric value for each different type the variant can be. Refer to http://devs.soldat.pl/wiki/index.php/Data_Types.

Offline y0uRd34th

  • Camper
  • ***
  • Posts: 325
  • [i]Look Signature![/i]
Re: checking if input is integer, string, etc.
« Reply #2 on: November 05, 2009, 06:11:40 am »
thanks, ill put it into search and found it :P

Code: [Select]
function GetTypeOF(Value: variant): string;
begin
  case VarType(Value) of
    3  : Result:= IntToStr(Value);
    5  : Result:= FloatToStr(Value);
    11 : Result:= iif(Value, 'true', 'false');
    256: Result:= Value;
  end;
end;

it was from curry wurst d:

Offline CurryWurst

  • Camper
  • ***
  • Posts: 265
    • Soldat Global Account System
Re: checking if input is integer, string, etc. [solved]
« Reply #3 on: November 05, 2009, 01:06:16 pm »
thanks, ill put it into search and found it :P

Code: [Select]
function GetTypeOF(Value: variant): string;
begin
  case VarType(Value) of
    3  : Result:= IntToStr(Value);
    5  : Result:= FloatToStr(Value);
    11 : Result:= iif(Value, 'true', 'false');
    256: Result:= Value;
  end;
end;

it was from curry wurst d:

Oh well, the function isn't complete. It lacks several variable types :-\ I only added the most common types.
Refer to the link DorkeyDear posted above to complement it.
Soldat Global Account System: #soldat.sgas @ quakenet

Offline y0uRd34th

  • Camper
  • ***
  • Posts: 325
  • [i]Look Signature![/i]
Re: checking if input is integer, string, etc. [solved]
« Reply #4 on: November 06, 2009, 03:23:31 am »
I just needed this for the VarType() function so far D:

btw. what i wnated to made shorter inttostr, [...] with it (too lazy to write :P, just better overview for the scirpt):
Code: [Select]
function int(value: variant): integer;
begin
  case VarType(value) of
    3:     Result := value;
    5, 17: Result := Round(value);
    256:   Result := StrToInt(Value);
  end;
end;

function str(value: variant): string;
begin
  case VarType(value) of
    3:     Result := IntToStr(value);
    5, 17: Result := FloatToStr(value);
    256:   Result := value;
  end;
end;

function float(value: variant): single;
begin
  case VarType(value) of
    3:     Result := value;
    5, 17: Result := value;
    256:   Result := StrToFloat(value);
  end;
end;