Visual Basic编程包括符号

时间:2013-08-27 06:24:14

标签: vb.net ascii symbols

我正在使用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

1 个答案:

答案 0 :(得分:0)

根据SendKeys的documentation判断,某些字符保留用于表示其他键击。

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

对于这些,您需要将它们放在括号之间,以便发送:

  • +执行{+}
  • ^执行{^}
  • %执行{%}

也许*是相同的,但我不认为它是保留的。你应该试试看。在输入中,您可以找到这些字符,并使用替换功能添加括号。

最后一点:将控件和变量命名为有意义的东西。 myStreamReaderButton1毫无意义。几个月后,当您回到该代码并快速理解其含义时,您会很高兴。