Results 1 to 5 of 5

Thread: Couple Functions I've made [IsMultiple, ReverseString, FormatNumber]

  1. #1
    Join Date
    Mar 2007
    Posts
    40
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default Couple Functions I've made [IsMultiple, ReverseString, FormatNumber]

    Hey guys, well these are a couple functions I've created for making my progress report and figure they might be useful to some, IsMultiple and ReverseString are required if you want to use FormatNumber because it calls them, otherwise I probably wouldn't have put them in here because their fairly simple and basic. Anyways here they are (remember, if you use these, credit me):

    Code:
    {*******************************************************************************
    function IsMultiple(Number, Multiple: integer): boolean;
    by: DeathByVirus
    Description: Checks if "Number" is a multiple of "Multiple". (eg. IsMultiple(45, 5)   
    will return true, because 45 is a multiple of 5, as with IsMultiple(6, 2), which will return as true)
    *******************************************************************************}
    
    function IsMultiple(Number, Multiple: integer): boolean;
    begin
      repeat
        Number := Number - Multiple;
      until (Number = 0) or (Number < 0)
      
      if Number = 0 then
        Result := true
      else
        Result := false;
    end;
    
    {*******************************************************************************
    function ReverseString(S: string): string;
    by: DeathByVirus
    Description: Will return the reverse of "S" (eg. ReverseString('Hello') will return 'olleH')
    *******************************************************************************}
    
    function ReverseString(S: String): String;
    var
       i:integer;
    begin
      for i := 0 to Length(S) - 1 do begin
          Result := Result + S[Length(S) - i];
      end;
    end;
    
    {*******************************************************************************
    function FormatNumber(Num: integer): string;
    by: DeathByVirus
    Description: Will return a number with the appropriate separators (eg. FormatNumber(1820486) will return as '1,820,486')
    *******************************************************************************}
    
    function FormatNumber (Num: integer): String;
    var
       i: integer;
       Backwards: String;
       Formated: String;
       
    begin
      if Length(IntToStr(Num)) <= 4 then Result := IntToStr(Num)
      else begin
        Backwards := ReverseString(IntToStr(Num));
        
        for i := 1 to Length(Backwards) do begin
          Formated := Formated + Backwards[i]
          
          if (IsMultiple(i, 3)) and (i <> Length(Backwards)) then
            Formated := Formated + ',';
        end;
    
        Result := ReverseString(Formated);
        
      end;
    end;

  2. #2
    Join Date
    Feb 2006
    Location
    London, England
    Posts
    2,045
    Mentioned
    2 Post(s)
    Quoted
    0 Post(s)

    Default

    Hey, they are good functions

    These are two of mine, I thought I would just post them so you can see different (and maybe even more efficient!) ways of scripting.

    Enjoy!

    PHP Code:
    function ReverseString(Sstring): stringstdcall;
    var
      
    iInteger;
    begin
      
    for := Length(Sdownto 1 do
        
    Result := Result Copy(Si1);
    end;

    function 
    IsMultiple(NoMultipleInteger): Boolean;
    begin
      Result 
    := (No mod Multiple 0)
    end
    SRL Wiki | SRL Rules | SRL Stats
    Ultimate SCAR Scripting Tutorial | Starblaster100's Auth System | Join the official SRL IRC now!


    Help Keep SRL Alive! Please disable Advert Blockers on SRL! Help Keep SRL Alive!


  3. #3
    Join Date
    Mar 2007
    Posts
    40
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    there it is! lol i was seaching for a way to do counting down for loops but after searching the forums couldn't find it, and as for the IsMultiple one, i don't really know the mod function, i learned a bit of it when i was learning Turing (another basic line programing language, pascal based) but the teacher i had in school really had no understanding of programing and was only teaching it cuz there were no other teachers that could do it, so i don't really understand it, wanna help me out with it??? thanks

  4. #4
    Join Date
    Mar 2007
    Posts
    3,042
    Mentioned
    1 Post(s)
    Quoted
    14 Post(s)

    Default

    The mod function gives you the remainder of one number divided by another. You can check out the Wikipedia article for more information.

    Cool functions, by the way.
    :-)

  5. #5
    Join Date
    Mar 2007
    Posts
    40
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    i sorta get it now, wiki is never good for learning mathematical functions and other stuff, it's got all these crazy symbols that i'm to lazy to read up on what they mean haha

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •