【问题标题】:How to call a function in a button in VB 10如何在 VB 10 中调用按钮中的函数
【发布时间】:2016-05-25 23:41:58
【问题描述】:

我只是 vb 10 的新手,我正在创建一个 vigenere 密码程序,但我不知道如何在按钮中调用函数。这是我的代码:

Public Shared Function Encrypt(ByVal cipherTxt As String, ByVal key As String)
    Dim encryptedText As String = ""
    For i As Integer = 1 To cipherTxt.Length
        Dim temp As Integer = AscW(GetChar(cipherTxt, i)) + AscW(GetChar(key, i Mod key.Length + 1))
        encryptedText += ChrW(temp)
    Next
    Return encryptedText
End Function

Public Shared Function Decrypt(ByVal cipherTxt As String, ByVal key As String)
    Dim decryptedText As String = ""
    For i As Integer = 1 To cipherTxt.Length
        Dim temp As Integer = AscW(GetChar(cipherTxt, i)) - AscW(GetChar(key, i Mod key.Length + 1))
        decryptedText += ChrW(temp)
    Next
    Return decryptedText
End Function

有什么帮助吗?谢谢。

【问题讨论】:

    标签: vb.net function encryption call vigenere


    【解决方案1】:

    你需要做这样的事情

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Encrypt("This is the string to Encrypt", "This is the key")
    End Sub
    

    您需要传入要加密的文本,该文本可能来自文本框,而密钥很可能是私有变量,以便更进一步。假设 TextBox1 包含一些您希望加密的文本(并将该加密文本返回到它来自的文本框;

    Private _myKey As String ="This is the key to encrypt & Decrypt"
    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        TextBox1.Text = Encrypt(TextBox1.text, _myKey)
    End Sub
    

    同样的基本功能也适用于解密。

    注意:这不包含错误检查,不建议以开放方式存储您的密钥,但这里应该有足够的内容让您开始

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-01-11
      • 1970-01-01
      • 2022-07-07
      • 2019-06-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多