Visual Basic窗体中途停止进程

时间:2016-02-02 19:30:36

标签: vb.net

我在主表单中遇到了一些有趣的问题。当我运行我的程序时,一切似乎都正常运行,但在表单加载后,我输入的一些函数没有运行,我定义的变量没有得到新的值。我不确定是什么导致功能阻塞。以下是我在表单加载操作中的内容。在EmailPort变量下面是不运行的。

我已经查看过此链接VS2010 does not show unhandled exception message in a WinForms Application on a 64-bit version of Windows之前回答的问题,虽然它很好地解释了为什么会出现这种情况,但我仍然不确定如何清除我的错误以便我可以正确调试。

    Private Sub MainScreen_Load(sender As Object, e As EventArgs) Handles Me.Load

    'read project path
    Dim path As String = My.Application.Info.DirectoryPath

    'split base path to find root
    Dim BasePath() As String = Split(path, "bin")

    'Sets the current Directory
    Directory.SetCurrentDirectory(BasePath(0) & "Resources")
    'Creates a Path for the file
    Dim Serverpath As String = IO.Path.Combine(BasePath(0), "Resources\Server.ini")
    Dim Configpath As String = IO.Path.Combine(BasePath(0), "Resources\PLCconfig.ini")
    Dim EmailPath As String = IO.Path.Combine(BasePath(0), "Resources\emailIP.ini")

    'Creates a StreamReader
    Dim Server As New StreamReader(Serverpath)
    Dim Config As New StreamReader(Configpath)
    Dim EmailIP As New StreamReader(EmailPath)

    'Read the config file 
    Dim allLinesServer As List(Of String) = New List(Of String)
    Do While Not Server.EndOfStream
        allLinesServer.Add(Server.ReadLine())
    Loop
    Server.Close()

    Dim allLinesConfig As List(Of String) = New List(Of String)
    Do While Not Config.EndOfStream
        allLinesConfig.Add(Config.ReadLine())
    Loop
    Config.Close()

    Dim allLinesEmail As List(Of String) = New List(Of String)
    Do While Not EmailIP.EndOfStream
        allLinesEmail.Add(EmailIP.ReadLine())
    Loop
    EmailIP.Close()

    'server information
    ServerName = ReadLine(1, allLinesServer)
    ServerUser = ReadLine(2, allLinesServer)
    ServerPassword = ReadLine(3, allLinesServer)

    'PLC Config Info
    plcIP = ReadLine(1, allLinesConfig)
    plcTag1 = ReadLine(2, allLinesConfig)

    EthernetIPforCLXCom1.IPAddress = plcIP

    EthernetIPforCLXCom1.Write(plcTag1 & ".InputStat", 1)

    'Email Alert Information
    EmailHost = ReadLine(1, allLinesEmail)
    EmailPort = ReadLine(2, allLinesEmail) <--------- Here is where the form stops working

    'Data buffer for intial read in values
    For i As Integer = 0 To 499
        newDatareal(i) = 999.999
        outDatareal(i) = 999.999
        outputDataReals(i) = 999.999
    Next

    For i As Integer = 0 To 999
        newDatabits(i) = vbFalse
        outdatabits(i) = vbFalse
    Next

    'Set up the timer for IO Manager
    outputInitalize = True

    Timer3.Enabled = True
    Timer3.Interval = 1000

    'Checks to see if main screen is open by itself, if it is, open the main dialog screen
    For Each form In My.Application.OpenForms

        If (form.name = Name) Then
            'form is loaded so can do work 
            'if you need to check whether it is actually visible

            MainDialogScreen.Show()

            If form.Visible Then
                MainDialogScreen.TopMost = True

            End If
        End If
    Next

End Sub

我在我的代码中使用Visual Studio社区和AdvancedHMI v399a。

提前感谢您提供的任何指导

编辑:我发现我的错误是将我的代码移动到按钮点击,如建议。因为我正在使用表单加载操作,所以我无法找到发生异常的位置。学过的知识。感谢Plutonix的调试提示

0 个答案:

没有答案