Solved

VB6 to Delphi

Posted on 2011-02-16
5
831 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

MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

Question has a verified solution.

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

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
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…

691 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