Solved

Quick String "Ticker"?

Posted on 2002-07-19
4
144 Views
Last Modified: 2010-04-04
Does anyone have any good ideas for a quick and easy routine, to "tick" through all combinations of a-z and 0-9 characters?

Rather like a stop-watch, but with characters.

Example :

aaaaaa
aaaaab
aaaaac
aaaaad
......
......
aaaaba
aaaabb
......
......
......
aaa9ca
aaa9cb
aaa9cc
......
etc. etc. etc.

Thanks in advance.
0
Comment
Question by:nicey
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 26

Accepted Solution

by:
Russell Libby earned 150 total points
ID: 7165760

An object oriented (and very fast) approach....

Rollover capability (when number is maxed "999..." etc) and works from right to left. Works by incrementing from a-z0-9, when 9 move left until not 9. If at null, then reset to all 'a', else increment and go left to right setting back to 'a'.
 
Hope this fits your needs,
Russell

---------------------------------

unit ticker;

interface

uses
  Windows, SysUtils;

type
  ETickClass     =  class(Exception);
  TTickClass     =  class(TObject)
  private
     // Private declaration
     FSize:      Integer;
     FBuffer:    PChar;
     FStart:     PChar;
     FHead:      PChar;
     FTail:      PChar;
  protected
     // Protected declaration
     function    GetValue: String;
  public
     // Public declaration
     constructor Create(Size: Integer);
     destructor  Destroy; override;
     property    Value: String read GetValue;
     property    Size: Integer read FSize;
     procedure   Tick;
  end;

implementation

constructor TTickClass.Create(Size: Integer);
begin

  // Perform inherited
  inherited Create;

  // Set values
  FBuffer:=nil;
  FSize:=Size;

  // Check size
  if (FSize <= 0) then raise ETickClass.Create('Size must be greater than zero');

  // Allocate buffer
  FBuffer:=AllocMem(Size+2);

  // Set up buffers and pointers
  FHead:=FBuffer+1;
  FillMemory(FHead, Size, Byte('a'));
  FTail:=StrEnd(FHead);
  FStart:=FTail;
  Dec(FStart);

end;

destructor TTickClass.Destroy;
begin

  // Free memory
  if Assigned(FBuffer) then FreeMem(FBuffer);

  // Perform inherited
  inherited Destroy;

end;

function TTickClass.GetValue;
begin

  // Return current buffer value
  result:=FHead;

end;

procedure TTickClass.Tick;
var  ppos:       PChar;
begin

  // Set starting position
  ppos:=FStart;

  // Handle current position
  case ppos^ of
     // Jump to numerics
     'z'   :  ppos^:='0';
     // Nine is where the real work comes in
     '9'   :
     begin
        // Loop all the way to the front while nines and not null
        while (ppos^ = '9') do Dec(ppos);
        // If the whole string is nines then reset all to a's and were done
        if (ppos^ = #0) then
           FillMemory(FHead, FSize, Byte('a'))
        else
        begin
           // We are not at null, so increment byte
           if (ppos^ = 'z') then
              ppos^:='0'
           else
              Inc(Byte(ppos^));
           // Walk back from left to right
           Inc(ppos);
           while (ppos^ <> #0) do
           begin
              ppos^:='a';
              Inc(ppos);
           end;
        end;
     end;
  else
     Inc(Byte(ppos^));
  end;

end;

0
 
LVL 1

Author Comment

by:nicey
ID: 7165825
Mate, you're a star!

It works very nice indeed.  I've hooked it into my program, and the job is now a good one.

I'm just off to finish off the project.

Thanks again. ;-)
0
 
LVL 26

Expert Comment

by:Russell Libby
ID: 7165852

Anytime :-)

I also should have mentioned that the Size param on the create is used to define the length of your ticker string, but I think you already found that out.

Have a great weekend,
Russell
0
 
LVL 1

Author Comment

by:nicey
ID: 7165896
Yeah, the code is pretty tight - it only took a few read throughs, and it all sunk in.

Only thing is, my 500Mhz AMD chip is really "running" when working with the larger patterns. :-D

S'ok though, as the final program will be run a much much more upto date system.

Good weekend to you too. ;-)
0

Featured Post

[Webinar] How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
Suggested Courses
Course of the Month8 days, 3 hours left to enroll

617 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question