2013-11-09 58 views
0

對於我的課程之一,我必須製作一個小型加密程序。在我的程序中,我有三種形式:frmMenu,frmEncodage,frmChiffrement。當程序啓動時,彈出菜單表單。之後,這是一個ComboBox,它允許您在兩種類型的加密之間進行選擇。做出選擇後,按一下按鈕即可開始。不幸的是,當我完成了一個加密表單(frmEncodage)的編碼之後,當我在菜單中選擇它時,我的程序不會讓我打開表單。彈出錯誤: 「創建表單時發生錯誤,詳情請參閱Exception.InnerException,錯誤爲:從字符串」a「轉換爲」Integer「類型無效。在Visual Studio中切換窗體時出錯[VB.NET - beginner]

我不知道如何解決它,我需要你的幫助來幫助我。繼承人的代碼我frmMenu:

Private Sub btnDebuter_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDebuter.Click 
    If cbxMenuChoix.Text = "Rotation" Then 
     Me.Hide() 
     frmEncodage.Show() 
    ElseIf cbxMenuChoix.Text = "Chiffrement par substitution" Then 
     Me.Hide() 
     FrmChiffrement.Show() 
    Else 
     MessageBox.Show("Veuillez entrer un choix d'encodage") 
    End If 
End Sub 

這是frmEncodage代碼:

Dim boEncodageNeg, boMajuscule As Boolean 
Dim inDecalage As Integer 
Dim inProfondeur As Integer 
Dim tbValeurLettre() As Integer = {"a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"} 
Dim byValeurFinal As Byte 
Dim stInput, stLettre, stChaine As String 
Dim inLettreNum As Integer 


Private Sub btnRotRetour_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnRotRetour.Click 
    Me.Hide() 
    frmMenu.Show() 
End Sub 

Private Sub btnRotAide_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnRotAide.Click 
End Sub 

Private Sub btnRot13_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnRot13.Click 

End Sub 
Private Sub btnRotChiffrer_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnRotChiffrer.Click 
    stInput = rtbRotInput.Text 
    For i = 1 To stInput.Length - 1 
     For ii = 0 To inProfondeur 
      If ii = 0 Then 
       stLettre = stInput.Chars(i) 
      End If 
      If stLettre = stLettre.ToUpper Then 
       boMajuscule = True 
      Else 
       boMajuscule = False 
      End If 
      stLettre.ToLower() 
      For iii = 0 To tbValeurLettre.Length - 1 
       If stLettre = tbValeurLettre(iii) Then 
        inLettreNum = iii 
       End If 
      Next 
      byValeurFinal = inDecalage + inLettreNum 
      If byValeurFinal > 25 Then 
       byValeurFinal = byValeurFinal - 25 
      End If 
      stLettre = tbValeurLettre(byValeurFinal) 
     Next 
     stChaine &= stLettre 
    Next 
    rtbRotOutput.Text = stChaine 
End Sub 
Private Sub btnRotDechiffrer_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnRotDechiffrer.Click 

End Sub 

回答

0

的問題是這一行:

Dim tbValeurLettre() As Integer = {"a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"} 

你告訴電腦創建一個數組Integer s,但填寫String s(引號中的文字部分)。寫"a"C,"b"C等創建Chars其中可以轉換爲Integer s。

+0

非常感謝你! – Bubblesphere

+0

@ user2973533:你非常歡迎。如果我的回答對您有幫助,請將其標記爲已接受! – Timo

相關問題