2013-03-22 85 views
1

我無法弄清楚如何計算在text1中輸入數據後的校驗和,爲二進制字節中的除數輸入text1。我嘗試checksum.text = Text1.Text Xor Text2.Text但它不工作,我已經在互聯網上搜索,但它只適用於C + +和Java,可能在VB中?使用VB試圖計算二進制輸入後的校驗和

回答

1

您不能在字符串上使用XOR。你必須用2個數字來做,而不是一個字符串。

嘗試:

checksum.text = CStr(Clng(Text1.Text) Xor CLng(Text2.Text)) 
+0

不能也感謝BTW – 2013-03-22 15:50:04

+0

能不能細說了,好嗎? – George 2013-03-22 15:56:22

+0

這是我的代碼Private Sub Command1_Click() 如果Len(Text1.Text)&(Text2.Text)= 0或Text1.Text&(Text2.Text)Like「* [!0-1] *」Then Text3 =「輸入錯誤,請更正!!」 (2).Text =(Text1.Text)+(校驗和文本) Text3 =「祝賀CRC被生成( Else 校驗和文本= CStr(CLng(Text1.Text)Xor CLng(Text2.Text)) 「 End If End Sub – 2013-03-22 16:20:42

0

@George

Private Sub Command1_Click() 

    If Len(Text1.Text) & (Text2.Text) = 0 Or Text1.Text & Text2.Text) Like "[!0-1]" Then 
     Text3 = "Wrong Input, Please Correct it!!" 
    Else 
     checksum.Text = CStr(CLng(Text1.Text) Xor CLng(Text2.Text)) 
     Trans(2).Text = (Text1.Text) + (checksum.Text) 
     Text3 = "Congratulation CRC is generated" 
    End If 

End Sub 
+0

'如果Len(Text1.Text)&(Text2.Text)= 0'錯誤。應該是'Len(Text1.Text)&Len(Text2.Text)= 0'。我認爲&應該是OR,而不是AND。它不會出錯,但它不會改變任何數據,因爲編號XOR 0 =編號 – George 2013-03-22 16:34:26

+0

除非Ricky-2135意味着連接Text1.Text和Text2.Text'&'應該是'And'。 – jac 2013-03-22 16:40:10

+0

'Text1.Text&Text2.Text)像「[!0-1]」是錯誤的。應該是'Text1.Text Like「[!0-1]」和Text2.Text就像「[!0-1]」'但是再一次,你想用'Like'做什麼?模式'[!0-1]'很可能是不正確的,因爲你所做的只是檢查文本是不是0或1,而只是針對單個字符串。任何非單個字符的字符串都會將其驗證爲false,因此會陷入「Else」並破壞您的計算。 – George 2013-03-22 16:50:14