两个函数想改成vb代码,请帮忙

椅子 2004-10-05 06:07:44
function Encode(source : string):string;
var
Source_Len,Len : integer;
Count,c : integer;
a1,a2 : byte;
ind : dword;
Encode_Str : string;
begin
Result := '';
Encode_Str := '';
Len := 0;
a1 := 0;
a2 := 0;
c := 0;
ind := 0;
Count := 0;
Source_Len := Length(source);
while Count < Source_Len do
begin
if Len >= $2710 then
break;
ind := ord(source[Count+1]);
ind := ind shr (c+2);
a1 := ind or a2;
a1 := a1 and $3f;
ind := ord(source[Count+1]);
ind := ind shl (8-(c+2));
ind := ind shr 2;
a2 := ind and $3f;
inc(c,2);
if c >= 6 then
begin
if Len >= $270f then
begin
Encode_Str := Encode_Str + chr(a1 + $3c);
inc(Len);
end
else
begin
Encode_Str := Encode_Str + chr(a1 + $3c);
Encode_Str := Encode_Str + chr(a2 + $3c);
Inc(Len,2);
end;
c := 0;
a2 := 0;
end
else
begin
Encode_Str := Encode_Str + chr(a1 + $3c);
Inc(Len);
end;
inc(Count);
end;
if c > 0 then
begin
Encode_Str := Encode_Str + chr(a2 + $3c);
Inc(Len);
end;
SetLength(Encode_Str,Len);
Result := Encode_Str;
end;
...全文
127 16 打赏 收藏 转发到动态 举报
写回复
用AI写文章
16 条回复
切换为时间正序
请发表友善的回复…
发表回复
椅子 2004-10-28
  • 打赏
  • 举报
回复
感谢大家哈,刚出差回来,等吃完饭就结贴
ghchen 2004-10-25
  • 打赏
  • 举报
回复
up
ksaiy 2004-10-25
  • 打赏
  • 举报
回复
实在不想再进行转下去.我没有调试.因为没有环境.我随便写的。具体的你自己去弄了。

Public Function SHL(OPR As Byte, n As Integer) As Byte
Dim BD As Byte
Dim I As Integer
BD = OPR
For I = 1 To n - 1
BD = (BD And &H7F) * 2 '将D7位屏蔽左移,防止字节溢出
Next I
CF = BD And &H80 '判断D7位是否进位
SHL = (BD And &H7F) * 2
End Function
Public Function SHR(OPR As Byte, n As Integer) As Byte
Dim BD As Byte
Dim I As Integer
BD = OPR
For I = 1 To n - 1
BD = BD \ 2 '右移
Next I
CF = BD And 1 '判断D0位是否进位
SHR = BD \ 2
End Function

Function Encode(source As String) As String
Dim Source_Len, BLen As Integer
Dim Count, c As Integer
Dim a1, a2 As Byte
Dim ind As Long
Dim Encode_Str As String
Encode = ""
Encode_Str = ""
BLen = 0
a1 = 0
a2 = 0
c = 0
ind = 0
Count = 0
Source_Len = Len(source)
Do While Count < Source_Len
If BLen >= Chr$(2710) Then
Exit Do
End If
ind = ord(source(Count + 1))
ind = SHR(ind, (c + 2))
a1 = ind Or a2
a1 = a1 And Char$("3f")
ind = ord(source(Count + 1))
ind = SHL(ind, (8 - (c + 2)))
ind = SHR(ind, 2)
a2 = ind And Chr$("3f")
c = c + 2
If c >= 6 Then
If BLen >= Chr$("270f") Then
Encode_Str = Encode_Str + Chr(a1 + Chr$("3c"))
BLen = BLen + 1
Else
Encode_Str = Encode_Str + Chr(a1 + Chr$("3c"))
Encode_Str = Encode_Str + Chr(a2 + Chr$("3c"))
BLen = BLen + 2
End If
c = 0
a2 = 0
Else
Encode_Str = Encode_Str + Chr(a1 + Chr$("3c"))
BLen = BLen + 1
End If
Count = Count + 1
Exit Do
Loop

If c > 0 Then
Encode_Str = Encode_Str + Chr(a2 + Chr$("3c"))
BLen = BLen + 1
End If
Trim (Encode_Str)
Encode = Encode_Str
End Function
fan_love 2004-10-25
  • 打赏
  • 举报
回复
传奇的?
jorge 2004-10-25
  • 打赏
  • 举报
回复
对了,一定记得去掉所有的分号
jorge 2004-10-25
  • 打赏
  • 举报
回复
参数定义中的冒号都改为 as
var段都改成dim 变量名 as 类型
begin都去掉
end分几种情况:
对应for的改为next
对应if的改为end if
对应while的改为loop
对应函数结尾的改为end function
break改为exit do
while ... do 改为 do while ...
:=都改成=
$...改为Chr$(&H...)
inc/dec(X)改为X=X+/-1
inc/dec(X,Y)改为X=X+/-Y
我去喘口气,后来的哥们接着说哈
S.F. 2004-10-23
  • 打赏
  • 举报
回复
vb 无移位运算符号 shr shl ,其他都可以照猫画虎
masterjames 2004-10-23
  • 打赏
  • 举报
回复
var dim
ARRAY 也不一样呀
redlegend_126_com 2004-10-23
  • 打赏
  • 举报
回复
这个太简单了,直接替换就可以了!把相应的函数直接转换!
var-->dim
songyanbin 2004-10-23
  • 打赏
  • 举报
回复
不一样的地方多了 可不是var-->dim就完了的。
ksaiy 2004-10-22
  • 打赏
  • 举报
回复
晕.怎么这么多的VB要装DELPHI...
DELPHI又要装VB的。刚刚才弄完一个又看到一个。晕哦.
rjy206 2004-10-22
  • 打赏
  • 举报
回复
up
hottey 2004-10-22
  • 打赏
  • 举报
回复
搞成VB代码很简单的,不过相信这里没多少人用那个。
哈哈!还是发到VB版去吧!
椅子 2004-10-22
  • 打赏
  • 举报
回复
我没delphi环境,不知道对不对阿
hsmserver 2004-10-05
  • 打赏
  • 举报
回复
把var 变成 dim
把:去了
然后就是那几个循环那把它改成VB语法的
有些函数可能不太一样,你查一下就行了

我这没VB环境,只能帮你那么多了
椅子 2004-10-05
  • 打赏
  • 举报
回复
function Decode(source : string):string;
var
Source_Len,Len : integer;
Count,c1,c2 : integer;
code : array[0..7] of byte;
a1,a2 : byte;
ind : dword;
Decode_Str : string;
label L1,L2;
begin
Result := '';
Decode_Str := '';
code[2] := $fc;
code[4] := $f0;
code[6] := $c0;
Len := 0;
a1 := 0;
a2 := 0;
c1 := 2;
c2 := 0;
ind := 0;
Count := 0;
Source_Len := Length(source);
while (Count < Source_Len) do
begin
if(ord(Source[Count+1]) - $3c) < 0 then
begin
Decode_Str := Decode_Str + Source[Count+1];
inc(Len);
inc(Count);
a1 := 0;
a2 := 0;
c1 := 2;
c2 := 0;
ind := 0;
Continue;
//break;
end;
a1 := ord(Source[Count+1]) - $3c;
if Len >= Source_Len then
begin
break;
end;
if (c2 + 6) < 8 then
begin
goto L2;
end;
ind := a1 and $3f;
ind := ind shr (6-c1);
Decode_Str := Decode_Str + chr(ind or a2);
Inc(Len);
c2 := 0;
if c1 >= 6 then
begin
c1 := 2;
goto L1;
end;
inc(c1,2);
L2 :a2 := a1 shl c1;
a2 := a2 and code[c1];
c2 := c2 + (8 - c1);
L1 :inc(count);
end;
SetLength(Decode_Str,Len);
Result := Decode_Str;
end;

16,749

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 语言基础/算法/系统设计
社区管理员
  • 语言基础/算法/系统设计社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧