vb.net - InvalidOperationException未处理

时间:2015-03-26 12:21:39

标签: vb.net

请帮我解决一下我的代码:我把我现有的项目放在我的主要项目RASPI-CONTROLLER上,这个控制我的raspberrypi,我需要解决这个问题:

Imports RELEASEMAIN
Imports RELEASETOOLS
Imports RASPI_CONTROLLER
Imports System_Information
Imports System.Management
Imports System
Imports System.IO
Imports System.Text
Imports System.Diagnostics
Imports Microsoft.Win32
Imports System.Windows.Forms
Imports LCperiodic


Public Class MENU
    Dim rlstoolssplash As New RELEASETOOLS.SPLASH
    Dim rlstoolsmain As New RELEASETOOLS.MAIN
    Dim sysinfolist As New System_Information.System_Information_All_List
    Dim lcperiodicform2 As New LCperiodic.Form2
    Dim raspiform1 As New RASPI_CONTROLLER.Form1
    Dim raspimain As New RASPI_CONTROLLER.raspi_main

    Private Sub SYSTEMINFORMATIONSToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles SYSTEMINFORMATIONSToolStripMenuItem.Click
        RichTextBox1.AppendText(System.DateTime.Now & ">RELEASETOOLS - SYSTEM INFORMATIONS STARTING..." & Environment.NewLine)
        rlstoolssplash.Show()
        RichTextBox1.AppendText(System.DateTime.Now & ">RELEASETOOLS - SYSTEM INFORMATIONS STARTED" & Environment.NewLine)
        RichTextBox1.AppendText(System.DateTime.Now & ">RELEASEMAIN - NOT ENABLE SYS INFO" & Environment.NewLine)
        SYSTEMINFORMATIONSToolStripMenuItem.Visible = False
        RichTextBox1.AppendText(System.DateTime.Now & ">RELEASEMAIN - ENABLE RUN SYS INFO" & Environment.NewLine)
        RUNToolStripMenuItem.Visible = True
        SYSTEMINFORMATIONFORMToolStripMenuItem.Visible = True
        RichTextBox1.AppendText(System.DateTime.Now & ">DONE" & Environment.NewLine)
    End Sub

    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        RichTextBox1.AppendText("-------------------------------------------------------" & Environment.NewLine)
        RichTextBox1.AppendText("RELEASETOOLS - CODED BY LJMF00" & Environment.NewLine)
        RichTextBox1.AppendText("VISIT MY WEBSITE: http://releasenetwork.eu5.org/" & Environment.NewLine)
        RichTextBox1.AppendText("-------------------------------------------------------" & Environment.NewLine)
        RichTextBox1.AppendText(System.DateTime.Now & ">RUN RELEASEMAIN PROJECT" & Environment.NewLine)
        ToolStripStatusLabel2.Text = (System.DateTime.Now)
        RichTextBox1.AppendText(System.DateTime.Now & ">RELEASEMAIN PROJECT RUNNED" & Environment.NewLine)
        RichTextBox1.AppendText(System.DateTime.Now & ">RELEASETOOLS DIR EXIST?" & Environment.NewLine)
        If Not My.Computer.FileSystem.DirectoryExists("c://RELEASETOOLS") Then
            RichTextBox1.AppendText(System.DateTime.Now & ">RELEASETOOLS DIR NOT EXIST, EXEC SHELL" & Environment.NewLine)
            Shell("cmd.exe /c cd c:/ && md RELEASETOOLS")
        End If
        RichTextBox1.AppendText(System.DateTime.Now & ">RELEASETOOLS OUTPUTS DIR EXIST?" & Environment.NewLine)
        If Not My.Computer.FileSystem.DirectoryExists("c://RELEASETOOLS/output") Then
            RichTextBox1.AppendText(System.DateTime.Now & ">RELEASETOOLS OUTPUTS DIR NOT EXIST, EXEC SHELL" & Environment.NewLine)
            Shell("cmd.exe /c cd c:/RELEASETOOLS && md output")
        End If
        RichTextBox1.AppendText(System.DateTime.Now & ">RELEASETOOLS PERIODIC TABLE DIR EXIST?" & Environment.NewLine)
        If Not My.Computer.FileSystem.DirectoryExists("c://RELEASETOOLS/lcperiodic") Then
            RichTextBox1.AppendText(System.DateTime.Now & ">RELEASETOOLS PERIODIC TABLE DIR NOT EXIST, EXEC SHELL" & Environment.NewLine)
            Shell("cmd.exe /c cd c:/RELEASETOOLS && md lcperiodic")
        End If
        RichTextBox1.AppendText(System.DateTime.Now & ">RELEASETOOLS - SYSTEM INFORMATION CPU OUTPUT CMD" & Environment.NewLine)
        Shell("cmd.exe /c wmic PATH Win32_processor > c://RELEASETOOLS/output/cpu_output.rlstext")
        RichTextBox1.AppendText(System.DateTime.Now & ">RELEASETOOLS - SYSTEM INFORMATION GPU OUTPUT CMD" & Environment.NewLine)
        Shell("cmd.exe /c wmic PATH Win32_videocontroller GET description > c://RELEASETOOLS/output/gpu_output.rlstext")
        RichTextBox1.AppendText(System.DateTime.Now & ">RELEASETOOLS - SYSTEM INFORMATION DEBUG OUTPUT CMD" & Environment.NewLine)
        Shell("cmd.exe /c systeminfo > c://RELEASETOOLS/output/debug_output.rlstext")
        RichTextBox1.AppendText(System.DateTime.Now & ">RELEASETOOLS - WAIT TO CLOSE CMD BEFORE USE AN TOOLS" & Environment.NewLine)
        RichTextBox1.AppendText(System.DateTime.Now & ">DONE." & Environment.NewLine)
    End Sub

    Private Sub SYSTEMINFORMATIONFORMToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles SYSTEMINFORMATIONFORMToolStripMenuItem.Click

        RichTextBox1.AppendText(System.DateTime.Now & ">RELEASETOOLS - SHOW FORM" & Environment.NewLine)
        rlstoolsmain.Show()
        RichTextBox1.AppendText(System.DateTime.Now & ">DONE." & Environment.NewLine)
    End Sub

    Private Sub EXITToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles EXITToolStripMenuItem.Click
        End
    End Sub

    Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
        Dim stringhour As Integer = System.DateTime.Now.ToString("hh")
        Dim stringminute As Integer = System.DateTime.Now.ToString("mm")
        Dim stringsecond As Integer = System.DateTime.Now.ToString("mm")
        Dim Red As String
        Dim Green As String
        Dim Blue As String
        Dim hexcolor As Integer = stringhour & stringminute & stringsecond
        Dim color As String = Replace(hexcolor, "#", "")
        Red = Val("&H" & Mid(hexcolor, 1, 2))
        'The red value is now the long version of "00"

        Green = Val("&H" & Mid(hexcolor, 3, 2))
        'The red value is now the long version of "FF"

        Blue = Val("&H" & Mid(hexcolor, 5, 2))
        'The red value is now the long version of "1F"
        ToolStripStatusLabel2.Text = (System.DateTime.Now)
        Me.ToolStripStatusLabel2.ForeColor = System.Drawing.Color.FromArgb(CType(CType(Red, Byte), Integer), CType(CType(Green, Byte), Integer), CType(CType(Blue, Byte), Integer))
    End Sub

    Private Sub RESTARTToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles RESTARTToolStripMenuItem.Click
        Application.Restart()
    End Sub

    Private Sub RESTARTToolStripMenuItem1_Click(sender As Object, e As EventArgs) Handles RESTARTToolStripMenuItem1.Click
        Application.Restart()
    End Sub

    Private Sub ABOUTToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles ABOUTToolStripMenuItem.Click
        RichTextBox1.AppendText(System.DateTime.Now & ">RELEASEMAIN - SHOW ABOUT FORM" & Environment.NewLine)
        MAINSPLASH.Show()
        RichTextBox1.AppendText(System.DateTime.Now & ">ABOUTFORM - SPLASH BUTTON VISIBLE" & Environment.NewLine)
        MAINSPLASH.Button1.Visible = True
        RichTextBox1.AppendText(System.DateTime.Now & ">DONE." & Environment.NewLine)
    End Sub

    Private Sub WIN32LIBSToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles WIN32LIBSToolStripMenuItem.Click
        RichTextBox1.AppendText(System.DateTime.Now & ">SYSINFO - WIN32 CLASSES STARTING..." & Environment.NewLine)
        sysinfolist.Show()
        RichTextBox1.AppendText(System.DateTime.Now & ">SYSINFO - WIN32 CLASSES STARTING..." & Environment.NewLine)
        RichTextBox1.AppendText(System.DateTime.Now & ">RELEASEMAIN - NOT ENABLE WIN32 CLASS" & Environment.NewLine)
        WIN32LIBSToolStripMenuItem.Visible = False
        RichTextBox1.AppendText(System.DateTime.Now & ">RELEASEMAIN - ENABLE RUN WIN32 CLASS" & Environment.NewLine)
        RUNToolStripMenuItem.Visible = True
        WIN32CLASSESFORMToolStripMenuItem.Visible = True
        RichTextBox1.AppendText(System.DateTime.Now & ">DONE" & Environment.NewLine)
    End Sub

    Private Sub WIN32CLASSESFORMToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles WIN32CLASSESFORMToolStripMenuItem.Click
        RichTextBox1.AppendText(System.DateTime.Now & ">SYSINFO - SHOW FORM" & Environment.NewLine)
        sysinfolist.Show()
        RichTextBox1.AppendText(System.DateTime.Now & ">DONE." & Environment.NewLine)
    End Sub

    Private Sub TIMECOLORHAXToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles TIMECOLORHAXToolStripMenuItem.Click
        RichTextBox1.AppendText(System.DateTime.Now & ">OPENING FORMCOLOR FORM..." & Environment.NewLine)
        Formcolor.Show()
        RichTextBox1.AppendText(System.DateTime.Now & ">FORMCOLOR OPPEND" & Environment.NewLine)
        RichTextBox1.AppendText(System.DateTime.Now & ">DONE." & Environment.NewLine)
    End Sub

    Private Sub TESTCOLORHEXToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles TESTCOLORHEXToolStripMenuItem.Click
        Dim stringhour As Integer = System.DateTime.Now.ToString("hh")
        Dim stringminute As Integer = System.DateTime.Now.ToString("mm")
        Dim stringsecond As Integer = System.DateTime.Now.ToString("ss")
        Dim Red As String
        Dim Green As String
        Dim Blue As String
        Dim hexcolor As Integer = stringhour & stringminute & stringsecond
        Dim color As String = Replace(hexcolor, "#", "")
        Red = Val("&H" & Mid(hexcolor, 1, 2))
        'The red value is now the long version of "00"

        Green = Val("&H" & Mid(hexcolor, 3, 2))
        'The red value is now the long version of "FF"

        Blue = Val("&H" & Mid(hexcolor, 5, 2))
        'The red value is now the long version of "1F"
        Me.RichTextBox1.ForeColor = System.Drawing.Color.FromArgb(CType(CType(Red, Byte), Integer), CType(CType(Green, Byte), Integer), CType(CType(Blue, Byte), Integer))
    End Sub

    Private Sub MYEXTENSIONSToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles MYEXTENSIONSToolStripMenuItem.Click
        RichTextBox1.AppendText(System.DateTime.Now & ">INITIALIZING DATABASE..." & Environment.NewLine)
        RichTextBox1.AppendText(System.DateTime.Now & ">OPENING EXTENSIONS FORM..." & Environment.NewLine)
        EXTENSIONS.Show()
        RichTextBox1.AppendText(System.DateTime.Now & ">EXTENSIONS OPPEND" & Environment.NewLine)
        RichTextBox1.AppendText(System.DateTime.Now & ">DONE." & Environment.NewLine)
    End Sub

    Private Sub CLEARCONSOLEToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles CLEARCONSOLEToolStripMenuItem.Click
        RichTextBox1.AppendText(System.DateTime.Now & ">CLEARING CONSOLE..." & Environment.NewLine)
        RichTextBox1.Text = ""
        RichTextBox1.AppendText(System.DateTime.Now & ">CONSOLE CLEARED" & Environment.NewLine)
    End Sub

    Private Sub ABOUTToolStripMenuItem1_Click(sender As Object, e As EventArgs) Handles ABOUTToolStripMenuItem1.Click

    End Sub

    Private Sub NotifyIcon1_MouseDoubleClick(sender As Object, e As MouseEventArgs) Handles NotifyIcon1.MouseDoubleClick
        If SAMPLEToolStripMenuItem.Visible = True Then
            RichTextBox1.AppendText(System.DateTime.Now & ">HACKING MODE DISABLE" & Environment.NewLine)
            SAMPLEToolStripMenuItem.Visible = False
        Else
            RichTextBox1.AppendText(System.DateTime.Now & ">HACKING MODE ENABLE" & Environment.NewLine)
            SAMPLEToolStripMenuItem.Visible = True
        End If
    End Sub

    Private Sub CONSOLENORMALToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles CONSOLENORMALToolStripMenuItem.Click
        Me.RichTextBox1.Font = New System.Drawing.Font("Microsoft Sans Serif", 8.25!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.RichTextBox1.ForeColor = System.Drawing.Color.Lime
    End Sub

    Private Sub CONSOLEHACKINGToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles CONSOLEHACKINGToolStripMenuItem.Click
        Me.RichTextBox1.Font = New System.Drawing.Font("Wingdings 3", 72.0!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
    End Sub

    Private Sub LCPERIODICToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles LCPERIODICToolStripMenuItem.Click
        RichTextBox1.AppendText("-------------------------------------------------------" & Environment.NewLine)
        RichTextBox1.AppendText("LCPERIODIC - CODED BY LJMF00" & Environment.NewLine)
        RichTextBox1.AppendText("VISIT MY WEBSITE: http://lcproject.host22.com/lcprojects.html" & Environment.NewLine)
        RichTextBox1.AppendText("-------------------------------------------------------" & Environment.NewLine)
        RichTextBox1.AppendText(System.DateTime.Now & ">RELEASEPERIODIC - INITIALIZING..." & Environment.NewLine)
        lcperiodicform2.Show()
        RichTextBox1.AppendText(System.DateTime.Now & ">LCPERIODIC STARTED" & Environment.NewLine)
        RichTextBox1.AppendText(System.DateTime.Now & ">LCPERIODIC - NOT ENABLE SYS INFO" & Environment.NewLine)
        LCPERIODICToolStripMenuItem.Visible = False
        RichTextBox1.AppendText(System.DateTime.Now & ">LCPERIODIC - ENABLE RUN SYS INFO" & Environment.NewLine)
        RUNToolStripMenuItem.Visible = True
        PERIODICTABLEToolStripMenuItem.Visible = True
        RichTextBox1.AppendText(System.DateTime.Now & ">DONE" & Environment.NewLine)
    End Sub

    Private Sub PERIODICTABLEToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles PERIODICTABLEToolStripMenuItem.Click
        lcperiodicform2.Show()
    End Sub

    Private Sub RANDOMIZEToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles RANDOMIZEToolStripMenuItem.Click
        Randomized.Show()
    End Sub

    Private Sub TOOLSToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles TOOLSToolStripMenuItem.Click

    End Sub

    Private Sub RASPICONTROLLERToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles RASPILBL.Click
        RichTextBox1.AppendText("-------------------------------------------------------" & Environment.NewLine)
        RichTextBox1.AppendText("RASPICONTROLLER - CODED BY LJMF00" & Environment.NewLine)
        RichTextBox1.AppendText("VISIT MY WEBSITE: http://lcproject.host22.com/lcprojects.html" & Environment.NewLine)
        RichTextBox1.AppendText("-------------------------------------------------------" & Environment.NewLine)
        RichTextBox1.AppendText(System.DateTime.Now & ">RASPICONTROLLER - INITIALIZING..." & Environment.NewLine)
        Raspiform1.Show()
        RichTextBox1.AppendText(System.DateTime.Now & ">RASPICONTROLLER STARTED" & Environment.NewLine)
        RichTextBox1.AppendText(System.DateTime.Now & ">RASPICONTROLLER - NOT ENABLE SYS INFO" & Environment.NewLine)
        RASPILBL.Visible = False
        RichTextBox1.AppendText(System.DateTime.Now & ">RASPICONTROLLER - ENABLE RUN SYS INFO" & Environment.NewLine)
        RUNToolStripMenuItem.Visible = True
        RASPIRUNLBL.Visible = True
        RichTextBox1.AppendText(System.DateTime.Now & ">DONE" & Environment.NewLine)
    End Sub

    Private Sub RASPIRUNLBL_Click(sender As Object, e As EventArgs) Handles RASPIRUNLBL.Click
        raspimain.Show()
    End Sub
End Class

当我调试我的项目时,请执行以下错误:

http://i.stack.imgur.com/quzB4.png

1 个答案:

答案 0 :(得分:0)

在这段代码中,有问题:

  

Dim raspimain As New RASPI_CONTROLLER.raspi_main

以我的形式"校长必须区分所有变量,以便可以运行辅助表格。在这种情况下,必须区分用户名,主机名和密码,并注意:

Imports System.IO
Imports System.IO.File
Imports Renci.SshNet
Imports System.Net
Imports System.Net.FtpClient

Public Class raspi_main

    Public Ip As String = Form1.Ip
    Public Port As String = Form1.Port
    Public Username As String = Form1.Username
    Public Password As String = Form1.Password
    Public ConnInfo As New Renci.SshNet.PasswordConnectionInfo(Ip, Username, Password)
    Public SshClient As New Renci.SshNet.SshClient(ConnInfo)
    Public Cmdlistchecked As Renci.SshNet.SshCommand
    Public Cmdramusage As Renci.SshNet.SshCommand
    Public Cmdramstats As Renci.SshNet.SshCommand
    Public Cmdcpustats As Renci.SshNet.SshCommand
    Public Cmdfled As Renci.SshNet.SshCommand
    Public Cmdsled As Renci.SshNet.SshCommand
    Public Cmdusblist As Renci.SshNet.SshCommand
    Public Cmddeck1 As Renci.SshNet.SshCommand
    Public Cmddeck2 As Renci.SshNet.SshCommand
    Public Cmddeck3 As Renci.SshNet.SshCommand
    Public Cmddeck4 As Renci.SshNet.SshCommand
    Public Cmdmusicreconnect As Renci.SshNet.SshCommand
    Public Cmddiskusage As Renci.SshNet.SshCommand
    Private Sub raspi_main_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        ramTimer.Start()
        cpuTimer.Start()
        Me.Size = New System.Drawing.Size(793, 552)
        If My.Computer.FileSystem.FileExists("C://RASPICONTROLLER/yes.raspi") Then
            Form1.Hide()
        End If
        ...
        Public Ip As String = Form1.Ip
        Public Port As String = Form1.Port
        Public Username As String = Form1.Username
        Public Password As String = Form1.Password

然后我们必须将变量放在主窗体中,从而结束:

...
    Private Sub RASPIRUNLBL_Click(sender As Object, e As EventArgs) Handles RASPIRUNLBL.Click
        If My.Computer.FileSystem.ReadAllText("C://RASPICONTROLLER/yes.raspi") = "local" Then
            Raspiform1.Ip = My.Computer.FileSystem.ReadAllText("C://RASPICONTROLLER/ip-local.raspi")
        Else
            Raspiform1.Ip = My.Computer.FileSystem.ReadAllText("C://RASPICONTROLLER/ip-public.raspi")
        End If
        Raspiform1.Port = My.Computer.FileSystem.ReadAllText("C://RASPICONTROLLER/prt.raspi")
        Raspiform1.Username = My.Computer.FileSystem.ReadAllText("C://RASPICONTROLLER/usr.raspi")
        Raspiform1.Password = My.Computer.FileSystem.ReadAllText("C://RASPICONTROLLER/psd.raspi")
        Dim raspimain As New RASPI_CONTROLLER.raspi_main
        raspimain.Show()
    End Sub
End Class

抱歉我的英语不好;)