缘分小程序,VB 和 AU3 结果不同
Dim countM As IntegerDim countF As Integer
countM = 0
countF = 0
i = 1
Do
countM = Abs(Right(countM - Right(Asc(Mid(txtM.Text, i, 1)), 2), 2))
i = i + 1
Loop Until i > Len(txtM.Text)
i = 1
Do
countF = Right(countF + Right(Asc(Mid(txtF.Text, i, 1)), 2), 2)
i = i + 1
Loop Until i > Len(txtF.Text)
result = 10 * Right(countM - countF, 1) + Right(countM + countF, 1)
If Right(countM, 1) < 5 And Right(countF, 1) <> 9 Then result = result + 1
result = 100 - resultLocal $CountM = 0, $CountF = 0
Local $i = 1, $j = 1
Local $Result
Do
$CountM = Abs(StringRight($CountM - StringRight(Asc(StringMid($Male, $i, 1)), 2), 2))
$i += 1
Until $i > StringLen($Male)
Do
$CountF = StringRight($CountF + StringRight(Asc(StringMid($Female, $j, 1)), 2), 2)
$j += 1
Until $j > StringLen($Female)
$Result = 10 * StringRight($CountM - $CountF, 1) + StringRight($CountM + $CountF, 1)
If (StringRight($CountM, 1) < 5 And StringRight($CountF, 1) 9) Then $Result += 1
$Result = 100 - $Result
分别为 VB 和 AU3 代码,原理是将文字转换为 ASCII 运算。
可是,当给定的男方和女方是英文时,运算结果相同,但当是中文时,运算结果相差甚远。 Local $CountM = 0, $CountF = 0
Local $i = 1, $j = 1
Local $Result
$Male="什么"
$Female="什么"
For $i=1 To StringLen($Male)
If Asc(StringMid($Male, $i, 1))<127 Then
$CountM = Abs(StringRight($CountM - StringRight(Asc(StringMid($Male, $i, 1)), 2), 2))
Else
$CountM = Abs(StringRight($CountM - StringRight(Asc(StringMid($Male, $i, 1)), 2), 2))
$bin=StringToBinary(StringMid($Male, $i, 1))
$CountM = Abs(StringRight($CountM - StringRight(Dec(Hex(BinaryMid($bin,2,1))), 2), 2))
EndIf
Next
For $j=1 To StringLen($Female)
If Asc(StringMid($Female, $i, 1))<127 Then
$CountF = StringRight($CountF + StringRight(Asc(StringMid($Female, $j, 1)), 2), 2)
Else
$CountF = StringRight($CountF + StringRight(Asc(StringMid($Female, $j, 1)), 2), 2)
$bin2=StringToBinary(StringMid($Female, $i, 1))
$CountF = Abs(StringRight($CountF - StringRight(Dec(Hex(BinaryMid($bin2,2,1))), 2), 2))
EndIf
Next
$Result = 10 * StringRight($CountM - $CountF, 1) + StringRight($CountM + $CountF, 1)
If (StringRight($CountM, 1) < 5 And StringRight($CountF, 1)<>9) Then $Result += 1
$Result = 100 - $Result
MsgBox(0,"",$Result)
试试 vb的用ascw获取ascii值试下 试试
gto250 发表于 2014-2-11 20:10 http://www.autoitx.com/images/common/back.gif
依旧不行。
遇到这种问题,我通常比较笨的办法就是在每个计算值后都加个msgbox,看看计算出来的结果是不是我预期的结果,如果不是的话就好找问题了。
页:
[1]