Solved

simple pascal algorithm

Posted on 2004-03-25
11
288 Views
Last Modified: 2012-06-27
i want to add up all the decimal values of each individual character in a string. I get a compiler error (Error 39: Ordinal Expression Expected), i dont know how to solve it. Im trying this atm:
for count := 1 to max_length do
     begin
         sum := sum + ord(copy(stringvariable,count,1));
     end;

any help mucho appreciated :)
0
Comment
Question by:RevelationUK
11 Comments
 
LVL 4

Accepted Solution

by:
ATAHAC earned 50 total points
ID: 10690919
try this
for count := 1 to max_length do
     begin
         sum := sum + ord(stringvariable[count]);
     end;
0
 
LVL 1

Expert Comment

by:xtremecris
ID: 10702086
The problem was that you were trying to call the ORD function giving a string parameter. If you would have looked in the Help(just press CTRL+F1 with the cursor over the "ORD" name) you would see that the function accepts only chars as a parameter returning the ASCII order of that character.

Best regards,
Cris.
0
 
LVL 1

Expert Comment

by:progex
ID: 10703248
Try this:

sum := sum + char(copy(stringvariable,count,1));
0
Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

 
LVL 11

Expert Comment

by:ZhaawZ
ID: 10763822
is max_length the same as length(stringvariable)?
0
 
LVL 1

Expert Comment

by:xtremecris
ID: 10763838
for count := 1 to length(stringvariable) do
     begin
         sum := sum + ord(stringvariable[count]);
     end;
0
 
LVL 3

Expert Comment

by:Aliev
ID: 10790688
Write full program. May be your types is wrong for this operation.
0
 

Author Comment

by:RevelationUK
ID: 10790862
its ok I worked it out, thanks anyway guys :)

sum := 0;
     max_length := length(password);
     for count := 1 to max_length do
     begin
          tempstring := copy(password,count,1);
          tempchar := tempstring[1];
          sum := sum + ord(tempstring[1]);
     end;
0
 
LVL 1

Expert Comment

by:xtremecris
ID: 10791209
That piece of code couldn't be more redundent even if you tried. Sorry for this remark but I couldn't help my self...

Why not use:  sum := sum + ord(password[count]); ?
Why is there a tempchar if you don't use it?

Best regards,
Cris.
0
 
LVL 11

Expert Comment

by:ZhaawZ
ID: 10793089
Can be done also without using ord():

var
  str : string;
  arr : array of byte absolute str;
  n, sum : integer;
...
sum := 0;
for n := low(arr) to high(arr) do sum := sum + arr[n];
0
 
LVL 100

Expert Comment

by:mlmcc
ID: 10969945
No comment has been added to this question in more than 21 days, so it is now classified as abandoned.

I will leave the following recommendation for this question in the Cleanup topic area:
   Accept - ATAHAC

Any objections should be posted here in the next 4 days. After that time, the question will be closed.

mlmcc
Pascal PE
0

Featured Post

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
TMemoryStream -> PNGImage -> TIcon convertion 22 1,239
Delphi: Read a array of strings in a OleVariant 4 1,143
Delphi Skype API 2 1,792
Delphi TSQL Connection runtime creating 1 1,091
When you’re making plans to join the modern business race, you should analyze various details that may affect your results. Nowadays, millions of businesses are trying to grow into established and appreciated professional enterprises.
SEO can be a real minefield to navigate, but there are three simple ways to up your SEO game just be re-assessing your content output.
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

776 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