Visual Basic编程包括符号



我使用的是Microsoft Visual Basic 2010,我能够创建一个生成文本行的程序。程序不会生成诸如+ * ( )之类的符号。

当我在记事本上测试程序时,它会输出字母、数字和一些符号,但不会显示%()符号。它跳过了那些符号。

Imports Spammer.MdlFunctions 'Imports all the functions, variables, declarations from MdlFunctions
Public Class Form1
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Const ModifierKey_ALT As Integer = 1
        RegisterMyHotkey(1, Keys.F10, ModifierKey_ALT) 'Lock?: Alt+F10
        RegisterMyHotkey(2, Keys.F11, ModifierKey_ALT) 'Start: Alt+F11
        RegisterMyHotkey(3, Keys.F12, ModifierKey_ALT) 'Stop : Alt+F12
    End Sub
    Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)
        Const WM_HOTKEY As Integer = 786
        If m.Msg = WM_HOTKEY Then
            Dim id As IntPtr = m.WParam
            Select Case (id.ToString) 'Get the hotkey ID (Optional: Convert the ID to a string becuse we used integer for ID's)
                Case "1" 'HotkeyID 1 is pressed: Lock?
                    If CheckBox1.Checked = True Then 'If the checkbox was checked
                        CheckBox1.Checked = False 'Uncheck it
                    Else
                        CheckBox1.Checked = True 'Check if it wasn't checked
                    End If
                Case "2" 'HotkeyID 2 is pressed: Start
                    StartSpam()
                Case "3" 'HotkeyID 3 is pressed: Stop
                    StopSpam()
            End Select
        End If
        MyBase.WndProc(m)
    End Sub

    Private Sub Form1_FormClosing(ByVal sender As System.Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles MyBase.FormClosing
        UnRegisterMyHotkey(1) 'Unregistering all the hotkeys to avoid errors
        UnRegisterMyHotkey(2) 'Unregistering all the hotkeys to avoid errors
        UnRegisterMyHotkey(3) 'Unregistering all the hotkeys to avoid errors
    End Sub
    Private Sub NumericUpDown1_ValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles NumericUpDown1.ValueChanged
        Timer1.Interval = NumericUpDown1.Value * 1000 'x1000 becuse the interval is in MilliSeconds
    End Sub
    Public Sub StartSpam()
        Timer1.Enabled = True
        Timer1.Start() 'Start spamming
    End Sub
    Public Sub StopSpam()
        Timer1.Enabled = False
        Timer1.Stop() ' Stop ofcourse spamming
    End Sub
    Dim IntCount As Integer = 0 'This will be our variable for counting the indexes we already used
    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        On Error Resume Next
        If CheckBox1.Checked = True Then 'Only Checked Items of the CheckedListbox
            If IntCount > CheckedListBox1.CheckedItems.Count - 1 Then 'If the index is higher then the max. index of the checkedlistbox
                IntCount = 0 ' The index will reset to 0
            End If
            SendKeys.SendWait(CheckedListBox1.CheckedItems(IntCount).ToString & "{ENTER}") 'Send keys to the active windows
            IntCount += 1 'Goto the next line
        Else 'All items
            If IntCount > CheckedListBox1.Items.Count - 1 Then 'If the index is higher then the max. index of the checkedlistbox
                IntCount = 0 ' The index will reset to 0
            End If
            SendKeys.SendWait(CheckedListBox1.Items(IntCount).ToString & "{ENTER}") 'Send keys to the active windows
            IntCount += 1 'Goto the next line
        End If

    End Sub
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        FrmAddOne.Show() 'Shows the form
    End Sub
    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        FrmAddMore.Show() 'Shows the form
    End Sub
    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        For i As Integer = 0 To CheckedListBox1.CheckedItems.Count - 1 'i is every number from 0 to the number of checked items CheckedListbox1 has
            CheckedListBox1.Items.Remove(CheckedListBox1.CheckedItems(i)) 'Remove all checked items
        Next
    End Sub
    Private Sub Button7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button7.Click
        For i As Integer = 0 To CheckedListBox1.Items.Count - 1 'i is every number from 0 to the number of checked or unchecked items CheckedListbox1 has
            CheckedListBox1.SetItemChecked(i, True) 'Check all items
        Next
    End Sub

    Private Sub Button8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button8.Click
        For i As Integer = 0 To CheckedListBox1.Items.Count - 1 'i is every number from 0 to the number of checked or unchecked items CheckedListbox1 has
            CheckedListBox1.SetItemChecked(i, False) 'Uncheck all items
        Next
    End Sub
    Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
        CheckedListBox1.Items.Clear() 'Clears the all items
    End Sub

    Private Sub Button9_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button9.Click
        StartSpam() 'Simply goto the sub StartSpam
    End Sub
    Private Sub Button10_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button10.Click
        StopSpam() 'Simply goto the sub StartSpam
    End Sub
    Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
        Dim richtextbox1 As New RichTextBox
        Dim Open As New OpenFileDialog()
        Dim myStreamReader As System.IO.StreamReader
        Open.Filter = "Text [*.txt*]|*.txt|All Files [*.*]|*.*"
        Open.CheckFileExists = True
        Open.Title = "Load"
        Open.ShowDialog(Me)
        Try
            Open.OpenFile()
            myStreamReader = System.IO.File.OpenText(Open.FileName) 'Opens the selected file
            richtextbox1.Text = myStreamReader.ReadToEnd 'Reads the text file till end
            For i As Integer = 0 To richtextbox1.Lines.Count - 1 'i is every number from 0 to the number of lines Richtextbox1 has
                CheckedListBox1.Items.Add(richtextbox1.Lines(i).ToString) 'adds every line
            Next 'i+1
        Catch ex As Exception
            MsgBox("Error: " & ex.Message, MsgBoxStyle.Critical, "Error") 'If an error occures, the program will show an error box with the error.
        End Try
    End Sub
    Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click
        Dim richtextbox1 As New RichTextBox
        For i As Integer = 0 To CheckedListBox1.Items.Count - 1 'i is every number from 0 to the number of checked or unchecked items CheckedListbox1 has
            richtextbox1.AppendText(CheckedListBox1.Items(i).ToString & vbNewLine) 'All the items of the checkedlistbox will be saved, sepperated with an enter (vbNewLine)
        Next
        Dim Save As New SaveFileDialog()
        Dim myStreamWriter As System.IO.StreamWriter
        Save.Filter = "Text [*.txt*]|*.txt|All Files [*.*]|*.*"
        Save.CheckPathExists = True
        Save.Title = "Save File"
        Save.ShowDialog(Me)
        Try
            myStreamWriter = System.IO.File.AppendText(Save.FileName) 'Write the File
            myStreamWriter.Write(richtextbox1.Text) 'Write all the text into the file
            myStreamWriter.Flush()
        Catch ex As Exception
            MsgBox("Error: " & ex.Message, MsgBoxStyle.Critical, "Error") 'If an error occures, the program will show an error box with the error.
        End Try
    End Sub
    Private Sub CheckBox2_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox2.CheckedChanged
    End Sub
    Private Sub CheckBox1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox1.CheckedChanged
    End Sub
    Private Sub Label4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label4.Click
    End Sub
    Private Sub CheckedListBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckedListBox1.SelectedIndexChanged
    End Sub
End Class

根据SendKeys的文档判断,一些字符被保留用于表示其他按键笔划。

  • +为SHIFT
  • ^是CTRL
  • %为ALT

对于这些,你需要把它们放在括号之间,所以要发送:

  • +{+}
  • ^{^}
  • %{%}

也许*是一样的,但我不认为它是保留的。你应该试试。在你的输入中,你可以找到这些字符,并使用Replace函数添加括号。

最后一点:给你的控件和变量命名一些有意义的东西。CCD_ 18、CCD_。几个月后,当你回到那个代码并能够快速理解它的含义时,你会很高兴。

相关内容

最新更新