Solved

VB6 to Delphi

Posted on 2011-02-16
5
818 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
[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
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:Ephraim Wangoya
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

733 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