懂VB的朋友 看看这段检查和的算法 ( 积分: 100 )

  • 主题发起人 主题发起人 cui5555
  • 开始时间 开始时间
C

cui5555

Unregistered / Unconfirmed
GUEST, unregistred user!
下面是VB关于计算检查和的函数,请给变为D7 代码,
Public Function ProcessOutputString(outputString As String) As String
Dim i As Integer
Dim CSb1 As Integer
Dim CSb2 As Integer
Dim CSb3 As Integer
Dim CSb$
Dim X
X = 0
For i = 1 To (Len(outputString)) 'Starting with the CMD character
X = X + Asc(Mid(outputString, i, 1)) 'adds ascii values together
Next i
CSb1 = 256 - X
CSb2 = 127 And (CSb1) 'Twos Complement
CSb3 = 64 Or (CSb2) 'OR 0x40
CSb$ = Chr(Val("&H"
&
(Hex(CSb3))))
ProcessOutputString = Chr(2) &
outputString &
CSb$ &
Chr(3)
End Function
 
Function ProcessOutputString(outputString:String):String;
var
i ,
CSb1 ,
CSb2 ,
CSb3 ,
X : integer;
CSb : char;
begin
X:= 0;
For i:= 1 To Len(outputString)do
X = X + byte(copy(outputString, i, 1));
CSb1:=256 - X;
CSb2:=127 And (CSb1);
CSb3:= 64 Or (CSb2)
CSb:= inttohex(CSb3);
result:= Chr(2) + outputString + CSb$ + Chr(3)
end;
 
楼上基本上正确,不过
For i:= 1 To Len(outputString)do
X = X + byte(copy(outputString, i, 1));
改为
For i:= 1 To Length(outputString)do
X := X + ord(copy(outputString, i, 1));
为好
 
多人接受答案了。
 

Similar threads

后退
顶部