求助!vb编程--BCD码转换成文本
怎样用vb6.0编数字转换系统?计算机接受的BCD码,要转换成文本文件.快帮帮我啊!拜托拉![ 本帖最后由 风花雪月 于 2006-11-20 08:52 编辑 ]
求助!vb编程!
用BYTE接收双BCD码,然后通过运算(对十六取模)分离两个 BCD码[此贴子已经被作者于2006-5-14 20:04:34编辑过]
budong '由BCD转ASCII码
FunctionBCDToAsc(BCD()AsByte)AsByte()
DimiAsInteger
DimbTempAsByte
DimbAsc()AsByte
DimintLenAsInteger
intLen=UBound(BCD)
ReDimbAsc(intLen*2+1)AsByte'重新定义数组上标
Fori=0TointLen
bTemp=(BCD(i)/16)And&HF
IfbTemp>9Then
bAsc(i*2)=bTemp+Asc("A")-10
Else
bAsc(i*2)=bTemp+Asc("0")
EndIf
bTemp=BCD(i)And&HF
IfbTemp>9Then
bAsc(i*2+1)=bTemp+Asc("A")-10
Else
bAsc(i*2+1)=bTemp+Asc("0")
EndIf
Next
BCDToAsc=bAsc
EndFunction
---------------------------------------------------------------
'由ASCII码转BCD码
FunctionAscToBCD(ASCII()AsByte)AsByte()
DimiAsInteger
DimbTempAsByte
DimbBCD()AsByte
DimbAsc()AsByte
DimbAAsByte
DimbBAsByte
DimintLenAsInteger
intLen=UBound(ASCII)
IfintLenMod2=0ThenintLen=intLen+1
ReDimbAsc(intLen)AsByte
ReDimbBCD((intLen+1)/2-1)AsByte
Fori=0ToUBound(ASCII)
bAsc(i)=ASCII(i)
Next
IfintLen>iThenbAsc(intLen)=&H0 '对数组不是偶数的补位
Fori=0TointLen
IfbAsc(i)<Asc("0")Then
bAsc(i)=Asc("0")
ElseIf((bAsc(i)>Asc("9"))And(bAsc(i)<Asc("A")))Then
bAsc(i)=Asc("0")
ElseIf((bAsc(i)>Asc("F"))And(bAsc(i)<Asc("a")))Then
bAsc(i)=Asc("0")
ElseIf(bAsc(i)>Asc("f"))Then
bAsc(i)=Asc("0")
EndIf
If(bAsc(i)>=Asc("0")AndbAsc(i)<=Asc("9"))Then
bA=bAsc(i)-Asc("0")
ElseIf(bAsc(i)>=Asc("a")AndbAsc(i)<=Asc("z"))Then
bA=bAsc(i)-Asc("a")+&HA
Else
bA=bAsc(i)-Asc("A")+&HA
EndIf
i=i+1
IfbAsc(i)<Asc("0")Then
bAsc(i)=Asc("0")
ElseIf((bAsc(i)>Asc("9"))And(bAsc(i)<Asc("A")))Then
bAsc(i)=Asc("0")
ElseIf((bAsc(i)>Asc("F"))And(bAsc(i)<Asc("a")))Then
bAsc(i)=Asc("0")
ElseIf(bAsc(i)>Asc("f"))Then
bAsc(i)=Asc("0")
EndIf
If(bAsc(i)>=Asc("0")AndbAsc(i)<=Asc("9"))Then
bB=bAsc(i)-Asc("0")
ElseIf(bAsc(i)>=Asc("a")AndbAsc(i)<=Asc("z"))Then
bB=bAsc(i)-Asc("a")+&HA
Else
bB=bAsc(i)-Asc("A")+&HA
EndIf
bBCD((i-1)/2)=(bA*16)XorbB
Next
AscToBCD=bBCD
EndFunction
---------------------------------------------------------------
调用BCDToAsc
PrivateSubCommand1_Click()
DimbA(3)AsByte
DimbB()AsByte
DimiAsInteger
bA(0)=Asc("1")
bA(1)=Asc("0")
bA(2)=Asc("a")
bA(3)=Asc("F")
bB=AscToBCD(bA)
Fori=0ToUBound(bB)
MsgBoxHex(bB(i))
Next
EndSub
页:
[1]