Solved

VB6 to Delphi

Posted on 2011-02-16
5
807 Views
Last Modified: 2013-11-25
How do i convert the following code to a Delphi format ?

Check = Check Mod (CLng(2) ^ CLng(16))
 
  MSB = Check \ (2 ^ 8)
  MSB = MSB Or 2 ^ 7
 
  LSB = Check Mod (2 ^ 8)
  LSB = LSB Or 2 ^ 7
 
  CalcCheck = Chr$MSB) & Chr$(LSB)

Thanks.
0
Comment
Question by:DavidYori
5 Comments
 
LVL 24

Accepted Solution

by:
jimyX earned 500 total points
ID: 34907098
I am not a VB coder but here I try;
uses Math;
procedure TForm1.Button1Click(Sender: TObject);
var
  check, MSB,LSB :integer;
  CalcCheck : string;
begin
  Check := Check mod round(math.Power(2,16));
  MSB := Check div round(math.Power(2,8));
  MSB := MSB or round(math.Power(2,7));
  LSB := Check mod round(math.Power(2,8));
  LSB := LSB or round(math.Power(2,7));
  CalcCheck := Chr(MSB) + Chr(LSB);
end;

Open in new window

0
 
LVL 37

Expert Comment

by:Geert Gruwez
ID: 34907240
you could also use shl
var
   check, Msb, LSB: integer;
 
begin
  Check := Check mod (2 shl 16);
  MSB := Check div (2 shl 8);
  MSB := MSB or (2 shl 7);
  LSB := Check mod (2 shl 8);
  LSB := LSB or (2 shl 7);
  CalcCheck := Chr(Msb) + Chr(Lsb);
end;
 
0
 
LVL 32

Expert Comment

by:ewangoya
ID: 34908368

Geert
You are trying to be sleek, LOL
Nice and fast code
0
 

Author Closing Comment

by:DavidYori
ID: 34909886
thanks, works a treat
0
 
LVL 37

Expert Comment

by:Geert Gruwez
ID: 34910211
nope it should have 1 shl 16
... my bad :)
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

813 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

18 Experts available now in Live!

Get 1:1 Help Now