Solved

Generate Ordered Numbers (Starting at a Specified #)

Posted on 2006-06-20
11
249 Views
Last Modified: 2010-04-05
Hello All;
This is a bit of an "Must Have" issue.

I need to have a function that will Generate Numbers from a {Starting # that I specify} into the beginning of every line in a RichEdit.
For Example: (Have a TEdit, to allow for Starting Number Insertion)

Line line line line
Line line line line
Line line line line

In this example, I need to start the Number out at: [6] so it would be something like this
6 Line line line line
6 Line line line line
6 Line line line line


Please someone, have any idea's on this one?
Carrzkiss
0
Comment
Question by:Wayne Barron
  • 4
  • 4
  • 2
  • +1
11 Comments
 
LVL 3

Expert Comment

by:KyleyHarris
ID: 16940704
do you mean something like

6 line line line
7 line line line
8 line line line

I take it you already know how to insert text into a richedit? using SelPos, and SelText?

So what you need to do is determine what line number you want to start on, and then seek the endofline and insert the text.
Are you also wanting to remove numbers from the richedit if you call the routine again with a different starting number?

What control specifically do you want to do this with, Tedit, or TRichEdit? it makes a difference
0
 
LVL 10

Expert Comment

by:atul_parmar
ID: 16940737
var
  s, i : integer;
begin
  s := 10;
  for i := 0 to RichEdit1.Lines.Count - 1 do
    RichEdit1.Lines.Strings[i] := inttostr(s + i) + RichEdit1.Lines.Strings[i];
end;
0
 
LVL 10

Expert Comment

by:atul_parmar
ID: 16940745
If you dont want to increment the starting number then

var
  s, i : integer;
begin
  s := 10; // your starting number
  for i := 0 to RichEdit1.Lines.Count - 1 do
    RichEdit1.Lines.Strings[i] := inttostr(s) + RichEdit1.Lines.Strings[i];
end;

0
 
LVL 30

Author Comment

by:Wayne Barron
ID: 16941254
Yes Harris
6 line line line
7 line line line
8 line line line
That is what I meant. Sorry about that, was 1/2 a sleep while writing it.

Atul, I will get back with you sometime after while if this code is what I need.
The one thing that I do not see in either of the codes that you have supplied here
Is a way to manually change the beginning #, like a Edit1.text...

Thanks a bunch guys
0
 
LVL 30

Author Comment

by:Wayne Barron
ID: 16941263
Harris.
The Starting # would be a TEdit
The lines are contained in a TRichEdit.
(If that is what you are asking about)
And no, I will not be having to Remove the Numbers.
This will be used as a 1-time thing.

Thanks
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 10

Expert Comment

by:atul_parmar
ID: 16941279
var
  i : integer;
begin
  for i := 0 to RichEdit1.Lines.Count - 1 do
    RichEdit1.Lines.Strings[i] := Edit1.Text + RichEdit1.Lines.Strings[i];
end;
0
 
LVL 30

Author Comment

by:Wayne Barron
ID: 16941314
Sorry Atul.
I think that I goofed at the beginning of the post.
And you probably have not read my comment that cleared up my mistake.

I need the numbers to be like so:

Line line line line
Line line line line
Line line line line

In this example, I need to start the Number out at: [6] so it would be something like this
6 Line line line line
7 Line line line line
8 Line line line line

They need the numbers to be Ordered, (NOT) Rambom, and not just 1-single #

Sorry about the confusement.
I was 1/2 a sleep, when I wrote the starting of this Post/Question.
0
 
LVL 10

Accepted Solution

by:
atul_parmar earned 500 total points
ID: 16941356
var
  s, i : integer;
begin
  s := StrToInt(Edit1.Text);
  for i := 0 to RichEdit1.Lines.Count - 1 do
    RichEdit1.Lines.Strings[i] := inttostr(s + i) + RichEdit1.Lines.Strings[i];
end;


If you are using D7 above, use TryStrToInt instead of StrToInt function.
0
 
LVL 15

Expert Comment

by:mikelittlewood
ID: 16941411
var
  s, i, code : integer;
begin

  // first check that you have a valid integer to work with
  val( Trim(edit1.text), i, code)
  if code = 0 then
    s := i
  else
    exit;

  // now loop
  for i := 0 to RichEdit1.Lines.Count - 1 do
    RichEdit1.Lines.Strings[i] := inttostr(s + i) + RichEdit1.Lines.Strings[i];
end;
0
 
LVL 30

Author Comment

by:Wayne Barron
ID: 16945005
Sorry Mike.
I had already accepted "atul" as Answer.
Thank you for your time anyway.

Thank you both
0
 
LVL 15

Expert Comment

by:mikelittlewood
ID: 16949343
no problem :)
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Activex loadlibrary and show parented form issue 6 285
Working this component WebCopy with proxy, help 3 76
Working with hours 3 45
Adoquery sql  left join does not work 25 80
Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
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…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.
I designed this idea while studying technology in the classroom.  This is a semester long project.  Students are asked to take photographs on a specific topic which they find meaningful, it can be a place or situation such as travel or homelessness.…

929 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now