Results 1 to 4 of 4

Thread: First function (simple :P)

  1. #1
    Join Date
    Feb 2007
    Location
    Access Violation at 0x00000000
    Posts
    2,865
    Mentioned
    3 Post(s)
    Quoted
    18 Post(s)

    Default First function (simple :P)

    Hello, his is my first(, or 2nd, idk) function:

    SCAR Code:
    function Count(Ending : Integer): Boolean;
    var Starting : Integer;
    begin
      repeat
      Starting := Starting + 1;
      Writeln(''+IntToStr(Starting)+' msec');
      until(Starting = Ending);
      ClearDebug;
       if (Rep = True) then
       begin
        Writeln('Counted to '+IntToStr(Ending * HowMuch)+' msec / ~'+IntToStr(Ending * HowMuch / 1000)+' sec[s]');
       end else
       begin
        Writeln('Counted to '+IntToStr(Ending)+' msec / ~'+IntToStr(Ending / 1000)+'  sec[s]');
     end;
    end;

    And here's how it can be used:
    SCAR Code:
    program New;
    var T : Integer;

    const
    Rep = True; //Repeat?
    HowMuch = 5; //How much times to repeat?
    Msecs = 1500; //How much millisecs to count? (1000 = 1sec)

    function Count(Ending : Integer): Boolean;
    var Starting : Integer;
    begin
      repeat
      Starting := Starting + 1;
      Writeln(''+IntToStr(Starting)+' msec');
      until(Starting = Ending);
      ClearDebug;
       if (Rep = True) then
       begin
        Writeln('Counted to '+IntToStr(Ending * HowMuch)+' msec / ~'+IntToStr(Ending * HowMuch / 1000)+' sec[s]');
       end else
       begin
        Writeln('Counted to '+IntToStr(Ending)+' msec / ~'+IntToStr(Ending / 1000)+'  sec[s]');
     end;
    end;

    begin
    if (Rep = True) then
    begin
    repeat
    T := T + 1;
    Count(Msecs);
    until(T = HowMuch);
    end else
    Count(Msecs);
    end.
    Ce ne sont que des gueux


  2. #2
    Join Date
    Jun 2007
    Location
    Wednesday
    Posts
    2,446
    Mentioned
    3 Post(s)
    Quoted
    1 Post(s)

    Default

    I'm sorry, but that made no sense to me (reason wise). Firstly, why do you use msecs in the count method when you have no waiting method so it would give you a completely inaccurate time? Also, you could use a 'for starting:= 1 to Ending do' to shorten it a bit. Next, you should always make everything possible involved in the function/procedure, as having stuff like rep being defined as a const can easily mean that it gets left out. Lastly, this can all be pushed into about 4 lines without the writeln's, but why would you want it to count to 1500 5 times in the debug box?

    I'm sorry, because I know this sounds very negative and it is, but it's because, for a function, it's too simple and could be easily coded better.
    By reading this signature you agree that mixster is superior to you in each and every way except the bad ways but including the really bad ways.

  3. #3
    Join Date
    Feb 2007
    Location
    Access Violation at 0x00000000
    Posts
    2,865
    Mentioned
    3 Post(s)
    Quoted
    18 Post(s)

    Default

    This wasnt made with a sense, but just a simple test, i also wonder why i'd use this!
    Ce ne sont que des gueux


  4. #4
    Join Date
    Sep 2007
    Posts
    501
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    fixed your standards (i think) and cleaned it up
    SCAR Code:
    function Count(Ending: Integer): Boolean;
    var
      Starting : Integer;
    begin
      repeat
        Starting := Starting + 1;
        Writeln(IntToStr(Starting)+' msec'); // changed this line
      until(Starting = Ending);
      ClearDebug;
      if(Rep = True)then
        Writeln('Counted to '+IntToStr(Ending * HowMuch)+' msec / ~'+IntToStr(Ending * HowMuch / 1000)+' sec[s]');
      else Writeln('Counted to '+IntToStr(Ending)+' msec / ~'+IntToStr(Ending / 1000)+'  sec[s]');
    end;

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. WearingItemCust simple function
    By hamster in forum Research & Development Lounge
    Replies: 2
    Last Post: 02-29-2008, 01:18 PM
  2. Need help with simple counter function.
    By Floor66 in forum OSR Help
    Replies: 5
    Last Post: 02-23-2008, 08:51 AM
  3. Replies: 5
    Last Post: 03-26-2007, 07:57 PM

Posting Permissions

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