Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

VB.NET System.OverflowException

Status
Not open for further replies.

sharikbaig

Member level 1
Joined
Aug 24, 2013
Messages
41
Helped
4
Reputation
8
Reaction score
4
Trophy points
1,288
Activity points
1,613
Hi,
A first chance exception of type 'System.OverflowException' occured in Microsoft.VisualBasic.dll

I am trying to read registers from PLC giving different values from 0 to 65536. However, at any instant, it shows this error and the value becomes 0. Please share your knowledge and tell me why is this happening and how to eliminate this error. Also sometimes i get StackOverflowException. Being a beginner in VB and a noob in programming, I have made this software with much efforts but this is what i got in the end. Any help would be appreciated.

Here's the FULL code:

Code:
Imports Communication
Imports Excel = Microsoft.Office.Interop.Excel

Public Class Form1
    Dim plc As PLCEthernetReadWrite
    Dim APP As New Excel.Application
    Dim worksheet As Excel.Worksheet
    Dim workbook As Excel.Workbook
    Dim FilePath As String
    Dim SpeedDisplay As Double

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        plc = New PLCEthernetReadWrite("192.168.1.5")
        Timer1.Start()
        FileVerificationLabel.Visible = False
        Label3.Visible = True
        Label4.Visible = True
        S1m1.Visible = False
        S2m1.Visible = False
        S3m1.Visible = False
        S4m1.Visible = False
        S5m1.Visible = False
        S6m1.Visible = False
        S7m1.Visible = False
        S8m1.Visible = False
        S9m1.Visible = False
        S10m1.Visible = False
        S11m1.Visible = False
        S12m1.Visible = False
        S13m1.Visible = False
        S14m1.Visible = False
        S15m1.Visible = False
        S16m1.Visible = False
        S17m1.Visible = False
        S18m1.Visible = False
        S19m1.Visible = False
        T1m1.Visible = False
        T2m1.Visible = False
        T3m1.Visible = False
        T4m1.Visible = False
        T5m1.Visible = False
        T6m1.Visible = False
        T7m1.Visible = False
        T8m1.Visible = False
        T9m1.Visible = False
        T10m1.Visible = False
        T11m1.Visible = False
        T12m1.Visible = False
        T13m1.Visible = False
        T14m1.Visible = False
        T15m1.Visible = False
        T16m1.Visible = False
        T17m1.Visible = False
        T18m1.Visible = False
        T19m1.Visible = False
    End Sub

    Private Sub Form1_FormClosed(ByVal sender As System.Object, ByVal e As System.Windows.Forms.FormClosedEventArgs) Handles MyBase.FormClosed
        plc.writeword("404145", 0)
        workbook.Application.DisplayAlerts = False
        APP.Quit()
    End Sub

    Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
        MeterCount.Text = plc.ReadWord("404597")
        MeterCount.Text = Val(MeterCount.Text) / 100
        Label4.Text = plc.ReadWord("404141")
        SpeedDisplay = Val(Label4.Text) / 1000
        SpeedDisplay = Math.Round(SpeedDisplay, 1)
        Speed.Text = SpeedDisplay
        Label3.Text = plc.ReadWord("404145")
    End Sub

    Private Sub BrowseButton_Click(sender As Object, e As EventArgs) Handles BrowseButton.Click
        Dim myFileDlog As New OpenFileDialog()

        'look for files in the c drive
        myFileDlog.InitialDirectory = "d:\Defects Data"

        'specifies what type of data files to look for
        myFileDlog.Filter = "All Files (*.xlsx*)|*.xlsx*"

        'specifies which data type is focused on start up
        myFileDlog.FilterIndex = 2

        'Gets or sets a value indicating whether the dialog box restores the current directory before closing.
        myFileDlog.RestoreDirectory = True

        'seperates message outputs for files found or not found
        If myFileDlog.ShowDialog() = _
            DialogResult.OK Then
            If Dir(myFileDlog.FileName) <> "" Then
                MsgBox("File Loaded: " & _
                       myFileDlog.FileName, _
                       MsgBoxStyle.Information)
            Else
                MsgBox("File Not Found", _
                       MsgBoxStyle.Critical)
            End If
        End If

        'Adds the file directory to the text box and Loads the File
        PathTextBox.Text = myFileDlog.FileName
        FilePath = Me.PathTextBox.Text
        workbook = APP.Workbooks.Open(FilePath)
        worksheet = workbook.Worksheets("sheet1")
        PieceNoReadLabel.Text = worksheet.Cells(2, 1).Value
        PieceMtrReadLabel.Text = worksheet.Cells(2, 3).Value

        FileVerificationLabel.Text = worksheet.Cells(1, 1).Value
        If FileVerificationLabel.Text <> "PieceNo" Then
            MsgBox("Wrong File")
        Else
            MsgBox("Right File")

        End If
        'Defect Code Labels for data display:
        DC1.Text = worksheet.Cells(2, 4).Value
        DC2.Text = worksheet.Cells(3, 4).Value
        DC3.Text = worksheet.Cells(4, 4).Value
        DC4.Text = worksheet.Cells(5, 4).Value
        DC5.Text = worksheet.Cells(6, 4).Value
        DC6.Text = worksheet.Cells(7, 4).Value
        DC7.Text = worksheet.Cells(8, 4).Value
        DC8.Text = worksheet.Cells(9, 4).Value
        DC9.Text = worksheet.Cells(10, 4).Value
        DC10.Text = worksheet.Cells(11, 4).Value
        DC11.Text = worksheet.Cells(12, 4).Value
        DC12.Text = worksheet.Cells(13, 4).Value
        DC13.Text = worksheet.Cells(14, 4).Value
        DC14.Text = worksheet.Cells(15, 4).Value
        DC15.Text = worksheet.Cells(16, 4).Value
        DC16.Text = worksheet.Cells(17, 4).Value
        DC17.Text = worksheet.Cells(18, 4).Value
        DC18.Text = worksheet.Cells(19, 4).Value
        DC19.Text = worksheet.Cells(20, 4).Value

        'Defect Name Labels for data display:
        DN1.Text = worksheet.Cells(2, 5).Value
        DN2.Text = worksheet.Cells(3, 5).Value
        DN3.Text = worksheet.Cells(4, 5).Value
        DN4.Text = worksheet.Cells(5, 5).Value
        DN5.Text = worksheet.Cells(6, 5).Value
        DN6.Text = worksheet.Cells(7, 5).Value
        DN7.Text = worksheet.Cells(8, 5).Value
        DN8.Text = worksheet.Cells(9, 5).Value
        DN9.Text = worksheet.Cells(10, 5).Value
        DN10.Text = worksheet.Cells(11, 5).Value
        DN11.Text = worksheet.Cells(12, 5).Value
        DN12.Text = worksheet.Cells(13, 5).Value
        DN13.Text = worksheet.Cells(14, 5).Value
        DN14.Text = worksheet.Cells(15, 5).Value
        DN15.Text = worksheet.Cells(16, 5).Value
        DN16.Text = worksheet.Cells(17, 5).Value
        DN17.Text = worksheet.Cells(18, 5).Value
        DN18.Text = worksheet.Cells(19, 5).Value
        DN19.Text = worksheet.Cells(20, 5).Value

        'Start Meter Labels for data display:
        S1.Text = worksheet.Cells(2, 6).Value
        S2.Text = worksheet.Cells(3, 6).Value
        S3.Text = worksheet.Cells(4, 6).Value
        S4.Text = worksheet.Cells(5, 6).Value
        S5.Text = worksheet.Cells(6, 6).Value
        S6.Text = worksheet.Cells(7, 6).Value
        S7.Text = worksheet.Cells(8, 6).Value
        S8.Text = worksheet.Cells(9, 6).Value
        S9.Text = worksheet.Cells(10, 6).Value
        S10.Text = worksheet.Cells(11, 6).Value
        S11.Text = worksheet.Cells(12, 6).Value
        S12.Text = worksheet.Cells(13, 6).Value
        S13.Text = worksheet.Cells(14, 6).Value
        S14.Text = worksheet.Cells(15, 6).Value
        S15.Text = worksheet.Cells(16, 6).Value
        S16.Text = worksheet.Cells(17, 6).Value
        S17.Text = worksheet.Cells(18, 6).Value
        S18.Text = worksheet.Cells(19, 6).Value
        S19.Text = worksheet.Cells(20, 6).Value

        'End Meter Labels for data display:
        T1.Text = worksheet.Cells(2, 7).Value
        T2.Text = worksheet.Cells(3, 7).Value
        T3.Text = worksheet.Cells(4, 7).Value
        T4.Text = worksheet.Cells(5, 7).Value
        T5.Text = worksheet.Cells(6, 7).Value
        T6.Text = worksheet.Cells(7, 7).Value
        T7.Text = worksheet.Cells(8, 7).Value
        T8.Text = worksheet.Cells(9, 7).Value
        T9.Text = worksheet.Cells(10, 7).Value
        T10.Text = worksheet.Cells(11, 7).Value
        T11.Text = worksheet.Cells(12, 7).Value
        T12.Text = worksheet.Cells(13, 7).Value
        T13.Text = worksheet.Cells(14, 7).Value
        T14.Text = worksheet.Cells(15, 7).Value
        T15.Text = worksheet.Cells(16, 7).Value
        T16.Text = worksheet.Cells(17, 7).Value
        T17.Text = worksheet.Cells(18, 7).Value
        T18.Text = worksheet.Cells(19, 7).Value
        T19.Text = worksheet.Cells(20, 7).Value

        'Do not display 0 for Start Meter & 'Minus 1 for PLC
        If S1.Text = "0" Then
            S1.Visible = False
            S1m1.Text = S1.Text
        Else
            S1.Visible = True
            S1m1.Text = Val(S1.Text) - 1
        End If

        If S2.Text = "0" Then
            S2.Visible = False
            S2m1.Text = S2.Text
        Else
            S2.Visible = True
            S2m1.Text = Val(S2.Text) - 1
        End If

        If S3.Text = "0" Then
            S3.Visible = False
            S3m1.Text = S3.Text
        Else
            S3.Visible = True
            S3m1.Text = Val(S3.Text) - 1
        End If

        If S4.Text = "0" Then
            S4.Visible = False
            S4m1.Text = S4.Text
        Else
            S4.Visible = True
            S4m1.Text = Val(S4.Text) - 1
        End If

        If S5.Text = "0" Then
            S5.Visible = False
            S5m1.Text = S5.Text
        Else
            S5.Visible = True
            S5m1.Text = Val(S5.Text) - 1
        End If

        If S6.Text = "0" Then
            S6.Visible = False
            S6m1.Text = S6.Text
        Else
            S6.Visible = True
            S6m1.Text = Val(S6.Text) - 1
        End If

        If S7.Text = "0" Then
            S7.Visible = False
            S7m1.Text = S7.Text
        Else
            S7.Visible = True
            S7m1.Text = Val(S7.Text) - 1
        End If

        If S8.Text = "0" Then
            S8.Visible = False
            S8m1.Text = S8.Text
        Else
            S8.Visible = True
            S8m1.Text = Val(S8.Text) - 1
        End If

        If S9.Text = "0" Then
            S9.Visible = False
            S9m1.Text = S9.Text
        Else
            S9.Visible = True
            S9m1.Text = Val(S9.Text) - 1
        End If

        If S10.Text = "0" Then
            S10.Visible = False
            S10m1.Text = S10.Text
        Else
            S10.Visible = True
            S10m1.Text = Val(S10.Text) - 1
        End If

        If S11.Text = "0" Then
            S11.Visible = False
            S11m1.Text = S11.Text
        Else
            S11.Visible = True
            S11m1.Text = Val(S11.Text) - 1
        End If

        If S12.Text = "0" Then
            S12.Visible = False
            S12m1.Text = S12.Text
        Else
            S12.Visible = True
            S12m1.Text = Val(S12.Text) - 1
        End If

        If S13.Text = "0" Then
            S13.Visible = False
            S13m1.Text = S13.Text
        Else
            S13.Visible = True
            S13m1.Text = Val(S13.Text) - 1
        End If

        If S14.Text = "0" Then
            S14.Visible = False
            S14m1.Text = S14.Text
        Else
            S14.Visible = True
            S14m1.Text = Val(S14.Text) - 1
        End If

        If S15.Text = "0" Then
            S15.Visible = False
            S15m1.Text = S15.Text
        Else
            S15.Visible = True
            S15m1.Text = Val(S15.Text) - 1
        End If

        If S16.Text = "0" Then
            S16.Visible = False
            S16m1.Text = S16.Text
        Else
            S16.Visible = True
            S16m1.Text = Val(S16.Text) - 1
        End If

        If S17.Text = "0" Then
            S17.Visible = False
            S17m1.Text = S17.Text
        Else
            S17.Visible = True
            S17m1.Text = Val(S17.Text) - 1
        End If

        If S18.Text = "0" Then
            S18.Visible = False
            S18m1.Text = S18.Text
        Else
            S18.Visible = True
            S18m1.Text = Val(S18.Text) - 1
        End If

        If S19.Text = "0" Then
            S19.Visible = False
            S19m1.Text = S19.Text
        Else
            S19.Visible = True
            S19m1.Text = Val(S19.Text) - 1
        End If

        'Do not display 0 for End Meter

        If T1.Text = "0" Then
            T1.Visible = False
            T1m1.Text = T1.Text
        Else
            T1.Visible = True
            T1m1.Text = Val(T1.Text) - 1
        End If

        If T2.Text = "0" Then
            T2.Visible = False
            T2m1.Text = T2.Text
        Else
            T2.Visible = True
            T2m1.Text = Val(T2.Text) - 1
        End If

        If T3.Text = "0" Then
            T3.Visible = False
            T3m1.Text = T3.Text
        Else
            T3.Visible = True
            T3m1.Text = Val(T3.Text) - 1
        End If

        If T4.Text = "0" Then
            T4.Visible = False
            T4m1.Text = T4.Text
        Else
            T4.Visible = True
            T4m1.Text = Val(T4.Text) - 1
        End If

        If T5.Text = "0" Then
            T5.Visible = False
            T5m1.Text = T5.Text
        Else
            T5.Visible = True
            T5m1.Text = Val(T5.Text) - 1
        End If

        If T6.Text = "0" Then
            T6.Visible = False
            T6m1.Text = T6.Text
        Else
            T6.Visible = True
            T6m1.Text = Val(T6.Text) - 1
        End If

        If T7.Text = "0" Then
            T7.Visible = False
            T7m1.Text = T7.Text
        Else
            T7.Visible = True
            T7m1.Text = Val(T7.Text) - 1
        End If

        If T8.Text = "0" Then
            T8.Visible = False
            T8m1.Text = T8.Text
        Else
            T8.Visible = True
            T8m1.Text = Val(T8.Text) - 1
        End If

        If T9.Text = "0" Then
            T9.Visible = False
            T9m1.Text = T9.Text
        Else
            T9.Visible = True
            T9m1.Text = Val(T9.Text) - 1
        End If

        If T10.Text = "0" Then
            T10.Visible = False
            T10m1.Text = T10.Text
        Else
            T10.Visible = True
            T10m1.Text = Val(T10.Text) - 1
        End If

        If T11.Text = "0" Then
            T11.Visible = False
            T11m1.Text = T11.Text
        Else
            T11.Visible = True
            T11m1.Text = Val(T11.Text) - 1
        End If

        If T12.Text = "0" Then
            T12.Visible = False
            T12m1.Text = T12.Text
        Else
            T12.Visible = True
            T12m1.Text = Val(T12.Text) - 1
        End If

        If T13.Text = "0" Then
            T13.Visible = False
            T13m1.Text = T13.Text
        Else
            T13.Visible = True
            T13m1.Text = Val(T13.Text) - 1
        End If

        If T14.Text = "0" Then
            T14.Visible = False
            T14m1.Text = T14.Text
        Else
            T14.Visible = True
            T14m1.Text = Val(T14.Text) - 1
        End If

        If T15.Text = "0" Then
            T15.Visible = False
            T15m1.Text = T15.Text
        Else
            T15.Visible = True
            T15m1.Text = Val(T15.Text) - 1
        End If

        If T16.Text = "0" Then
            T16.Visible = False
            T16m1.Text = T16.Text
        Else
            T16.Visible = True
            T16m1.Text = Val(T16.Text) - 1
        End If

        If T17.Text = "0" Then
            T17.Visible = False
            T17m1.Text = T17.Text
        Else
            T17.Visible = True
            T17m1.Text = Val(T17.Text) - 1
        End If

        If T18.Text = "0" Then
            T18.Visible = False
            T18m1.Text = T18.Text
        Else
            T18.Visible = True
            T18m1.Text = Val(T18.Text) - 1
        End If

        If T19.Text = "0" Then
            T19.Visible = False
            T19m1.Text = T19.Text
        Else
            T19.Visible = True
            T19m1.Text = Val(T19.Text) - 1
        End If

        'Writing  to PLC
        plc.writeword("404518", S1m1.Text)
        plc.writeword("404519", T1m1.Text)
        plc.writeword("404520", S2m1.Text)
        plc.writeword("404521", T2m1.Text)
        plc.writeword("404522", S3m1.Text)
        plc.writeword("404523", T3m1.Text)
        plc.writeword("404524", S4m1.Text)
        plc.writeword("404525", T4m1.Text)
        plc.writeword("404526", S5m1.Text)
        plc.writeword("404527", T5m1.Text)
        plc.writeword("404528", S6m1.Text)
        plc.writeword("404529", T6m1.Text)
        plc.writeword("404530", S7m1.Text)
        plc.writeword("404531", T7m1.Text)
        plc.writeword("404532", S8m1.Text)
        plc.writeword("404533", T8m1.Text)
        plc.writeword("404534", S9m1.Text)
        plc.writeword("404535", T9m1.Text)
        plc.writeword("404536", S10m1.Text)
        plc.writeword("404537", T10m1.Text)
        plc.writeword("404538", S11m1.Text)
        plc.writeword("404539", T11m1.Text)
        plc.writeword("404540", S12m1.Text)
        plc.writeword("404541", T12m1.Text)
        plc.writeword("404542", S13m1.Text)
        plc.writeword("404543", T13m1.Text)
        plc.writeword("404544", S14m1.Text)
        plc.writeword("404545", T14m1.Text)
        plc.writeword("404546", S15m1.Text)
        plc.writeword("404547", T15m1.Text)
        plc.writeword("404548", S16m1.Text)
        plc.writeword("404549", T16m1.Text)
        plc.writeword("404550", S17m1.Text)
        plc.writeword("404551", T17m1.Text)
        plc.writeword("404552", S18m1.Text)
        plc.writeword("404553", T18m1.Text)
        plc.writeword("404554", S19m1.Text)
        plc.writeword("404555", T19m1.Text)

        plc.writeword("404505", PieceMtrReadLabel.Text)

    End Sub

    Private Sub Timer2_Tick(sender As Object, e As EventArgs) Handles Timer2.Tick
        If Val(MeterCount.Text) >= Val(S1.Text) And Val(MeterCount.Text) <= Val(T1.Text) Then
            DC1.BackColor = Color.Orange
            DN1.BackColor = Color.Orange
            S1.BackColor = Color.Orange
            T1.BackColor = Color.Orange
            worksheet.Cells(2, 9).Value = "Incomplete"

        Else
            DC1.BackColor = Color.Transparent
            DN1.BackColor = Color.Transparent
            S1.BackColor = Color.Transparent
            T1.BackColor = Color.Transparent
        End If

        If Val(MeterCount.Text) >= Val(T1.Text) Then
            DC1.BackColor = Color.LightGreen
            DN1.BackColor = Color.LightGreen
            S1.BackColor = Color.LightGreen
            T1.BackColor = Color.LightGreen
            worksheet.Cells(2, 9).Value = "Processed"

        End If

        If Val(MeterCount.Text) >= Val(S2.Text) And Val(MeterCount.Text) <= Val(T2.Text) Then
            DC2.BackColor = Color.Orange
            DN2.BackColor = Color.Orange
            S2.BackColor = Color.Orange
            T2.BackColor = Color.Orange
            worksheet.Cells(3, 9).Value = "Incomplete"
        Else
            DC2.BackColor = Color.Transparent
            DN2.BackColor = Color.Transparent
            S2.BackColor = Color.Transparent
            T2.BackColor = Color.Transparent
        End If

        If Val(MeterCount.Text) >= Val(T2.Text) Then
            DC2.BackColor = Color.LightGreen
            DN2.BackColor = Color.LightGreen
            S2.BackColor = Color.LightGreen
            T2.BackColor = Color.LightGreen
            worksheet.Cells(3, 9).Value = "Processed"
        End If

        If Val(MeterCount.Text) >= Val(S3.Text) And Val(MeterCount.Text) <= Val(T3.Text) Then
            DC3.BackColor = Color.Orange
            DN3.BackColor = Color.Orange
            S3.BackColor = Color.Orange
            T3.BackColor = Color.Orange
            worksheet.Cells(4, 9).Value = "Incomplete"
        Else
            DC3.BackColor = Color.Transparent
            DN3.BackColor = Color.Transparent
            S3.BackColor = Color.Transparent
            T3.BackColor = Color.Transparent
        End If

        If Val(MeterCount.Text) >= Val(T3.Text) Then
            DC3.BackColor = Color.LightGreen
            DN3.BackColor = Color.LightGreen
            S3.BackColor = Color.LightGreen
            T3.BackColor = Color.LightGreen
            worksheet.Cells(4, 9).Value = "Processed"
        End If

        If Val(MeterCount.Text) >= Val(S4.Text) And Val(MeterCount.Text) <= Val(T4.Text) Then
            DC4.BackColor = Color.Orange
            DN4.BackColor = Color.Orange
            S4.BackColor = Color.Orange
            T4.BackColor = Color.Orange
            worksheet.Cells(5, 9).Value = "Incomplete"
        Else
            DC4.BackColor = Color.Transparent
            DN4.BackColor = Color.Transparent
            S4.BackColor = Color.Transparent
            T4.BackColor = Color.Transparent
        End If

        If Val(MeterCount.Text) >= Val(T4.Text) Then
            DC4.BackColor = Color.LightGreen
            DN4.BackColor = Color.LightGreen
            S4.BackColor = Color.LightGreen
            T4.BackColor = Color.LightGreen
            worksheet.Cells(5, 9).Value = "Processed"
        End If

        If Val(MeterCount.Text) >= Val(S5.Text) And Val(MeterCount.Text) <= Val(T5.Text) Then
            DC5.BackColor = Color.Orange
            DN5.BackColor = Color.Orange
            S5.BackColor = Color.Orange
            T5.BackColor = Color.Orange
            worksheet.Cells(6, 9).Value = "Incomplete"
        Else
            DC5.BackColor = Color.Transparent
            DN5.BackColor = Color.Transparent
            S5.BackColor = Color.Transparent
            T5.BackColor = Color.Transparent
        End If

        If Val(MeterCount.Text) >= Val(T5.Text) Then
            DC5.BackColor = Color.LightGreen
            DN5.BackColor = Color.LightGreen
            S5.BackColor = Color.LightGreen
            T5.BackColor = Color.LightGreen
            worksheet.Cells(6, 9).Value = "Processed"
        End If

        If Val(MeterCount.Text) >= Val(S6.Text) And Val(MeterCount.Text) <= Val(T6.Text) Then
            DC6.BackColor = Color.Orange
            DN6.BackColor = Color.Orange
            S6.BackColor = Color.Orange
            T6.BackColor = Color.Orange
            worksheet.Cells(7, 9).Value = "Incomplete"
        Else
            DC6.BackColor = Color.Transparent
            DN6.BackColor = Color.Transparent
            S6.BackColor = Color.Transparent
            T6.BackColor = Color.Transparent
        End If

        If Val(MeterCount.Text) >= Val(T6.Text) Then
            DC6.BackColor = Color.LightGreen
            DN6.BackColor = Color.LightGreen
            S6.BackColor = Color.LightGreen
            T6.BackColor = Color.LightGreen
            worksheet.Cells(7, 9).Value = "Processed"
        End If

        If Val(MeterCount.Text) >= Val(S7.Text) And Val(MeterCount.Text) <= Val(T7.Text) Then
            DC7.BackColor = Color.Orange
            DN7.BackColor = Color.Orange
            S7.BackColor = Color.Orange
            T7.BackColor = Color.Orange
            worksheet.Cells(8, 9).Value = "Incomplete"
        Else
            DC7.BackColor = Color.Transparent
            DN7.BackColor = Color.Transparent
            S7.BackColor = Color.Transparent
            T7.BackColor = Color.Transparent
        End If

        If Val(MeterCount.Text) >= Val(T7.Text) Then
            DC7.BackColor = Color.LightGreen
            DN7.BackColor = Color.LightGreen
            S7.BackColor = Color.LightGreen
            T7.BackColor = Color.LightGreen
            worksheet.Cells(8, 9).Value = "Processed"
        End If

        If Val(MeterCount.Text) >= Val(S8.Text) And Val(MeterCount.Text) <= Val(T8.Text) Then
            DC8.BackColor = Color.Orange
            DN8.BackColor = Color.Orange
            S8.BackColor = Color.Orange
            T8.BackColor = Color.Orange
            worksheet.Cells(9, 9).Value = "Incomplete"
        Else
            DC8.BackColor = Color.Transparent
            DN8.BackColor = Color.Transparent
            S8.BackColor = Color.Transparent
            T8.BackColor = Color.Transparent
        End If

        If Val(MeterCount.Text) >= Val(T8.Text) Then
            DC8.BackColor = Color.LightGreen
            DN8.BackColor = Color.LightGreen
            S8.BackColor = Color.LightGreen
            T8.BackColor = Color.LightGreen
            worksheet.Cells(9, 9).Value = "Processed"
        End If

        If Val(MeterCount.Text) >= Val(S9.Text) And Val(MeterCount.Text) <= Val(T9.Text) Then
            DC9.BackColor = Color.Orange
            DN9.BackColor = Color.Orange
            S9.BackColor = Color.Orange
            T9.BackColor = Color.Orange
            worksheet.Cells(10, 9).Value = "Incomplete"
        Else
            DC9.BackColor = Color.Transparent
            DN9.BackColor = Color.Transparent
            S9.BackColor = Color.Transparent
            T9.BackColor = Color.Transparent
        End If

        If Val(MeterCount.Text) >= Val(T9.Text) Then
            DC9.BackColor = Color.LightGreen
            DN9.BackColor = Color.LightGreen
            S9.BackColor = Color.LightGreen
            T9.BackColor = Color.LightGreen
            worksheet.Cells(10, 9).Value = "Processed"
        End If

        If Val(MeterCount.Text) >= Val(S10.Text) And Val(MeterCount.Text) <= Val(T10.Text) Then
            DC10.BackColor = Color.Orange
            DN10.BackColor = Color.Orange
            S10.BackColor = Color.Orange
            T10.BackColor = Color.Orange
            worksheet.Cells(11, 9).Value = "Incomplete"
        Else
            DC10.BackColor = Color.Transparent
            DN10.BackColor = Color.Transparent
            S10.BackColor = Color.Transparent
            T10.BackColor = Color.Transparent
        End If

        If Val(MeterCount.Text) >= Val(T10.Text) Then
            DC10.BackColor = Color.LightGreen
            DN10.BackColor = Color.LightGreen
            S10.BackColor = Color.LightGreen
            T10.BackColor = Color.LightGreen
            worksheet.Cells(11, 9).Value = "Processed"
        End If

        If Val(MeterCount.Text) >= Val(S11.Text) And Val(MeterCount.Text) <= Val(T11.Text) Then
            DC11.BackColor = Color.Orange
            DN11.BackColor = Color.Orange
            S11.BackColor = Color.Orange
            T11.BackColor = Color.Orange
            worksheet.Cells(12, 9).Value = "Incomplete"
        Else
            DC11.BackColor = Color.Transparent
            DN11.BackColor = Color.Transparent
            S11.BackColor = Color.Transparent
            T11.BackColor = Color.Transparent
        End If

        If Val(MeterCount.Text) >= Val(T11.Text) Then
            DC11.BackColor = Color.LightGreen
            DN11.BackColor = Color.LightGreen
            S11.BackColor = Color.LightGreen
            T11.BackColor = Color.LightGreen
            worksheet.Cells(12, 9).Value = "Processed"
        End If

        If Val(MeterCount.Text) >= Val(S12.Text) And Val(MeterCount.Text) <= Val(T12.Text) Then
            DC12.BackColor = Color.Orange
            DN12.BackColor = Color.Orange
            S12.BackColor = Color.Orange
            T12.BackColor = Color.Orange
            worksheet.Cells(13, 9).Value = "Incomplete"
        Else
            DC12.BackColor = Color.Transparent
            DN12.BackColor = Color.Transparent
            S12.BackColor = Color.Transparent
            T12.BackColor = Color.Transparent
        End If

        If Val(MeterCount.Text) >= Val(T12.Text) Then
            DC12.BackColor = Color.LightGreen
            DN12.BackColor = Color.LightGreen
            S12.BackColor = Color.LightGreen
            T12.BackColor = Color.LightGreen
            worksheet.Cells(13, 9).Value = "Processed"
        End If

        If Val(MeterCount.Text) >= Val(S13.Text) And Val(MeterCount.Text) <= Val(T13.Text) Then
            DC13.BackColor = Color.Orange
            DN13.BackColor = Color.Orange
            S13.BackColor = Color.Orange
            T13.BackColor = Color.Orange
            worksheet.Cells(14, 9).Value = "Incomplete"
        Else
            DC13.BackColor = Color.Transparent
            DN13.BackColor = Color.Transparent
            S13.BackColor = Color.Transparent
            T13.BackColor = Color.Transparent
        End If

        If Val(MeterCount.Text) >= Val(T13.Text) Then
            DC13.BackColor = Color.LightGreen
            DN13.BackColor = Color.LightGreen
            S13.BackColor = Color.LightGreen
            T13.BackColor = Color.LightGreen
            worksheet.Cells(14, 9).Value = "Processed"
        End If

        If Val(MeterCount.Text) >= Val(S14.Text) And Val(MeterCount.Text) <= Val(T14.Text) Then
            DC14.BackColor = Color.Orange
            DN14.BackColor = Color.Orange
            S14.BackColor = Color.Orange
            T14.BackColor = Color.Orange
            worksheet.Cells(15, 9).Value = "Incomplete"
        Else
            DC14.BackColor = Color.Transparent
            DN14.BackColor = Color.Transparent
            S14.BackColor = Color.Transparent
            T14.BackColor = Color.Transparent
        End If

        If Val(MeterCount.Text) >= Val(T14.Text) Then
            DC14.BackColor = Color.LightGreen
            DN14.BackColor = Color.LightGreen
            S14.BackColor = Color.LightGreen
            T14.BackColor = Color.LightGreen
            worksheet.Cells(15, 9).Value = "Processed"
        End If

        If Val(MeterCount.Text) >= Val(S15.Text) And Val(MeterCount.Text) <= Val(T15.Text) Then
            DC15.BackColor = Color.Orange
            DN15.BackColor = Color.Orange
            S15.BackColor = Color.Orange
            T15.BackColor = Color.Orange
            worksheet.Cells(16, 9).Value = "Incomplete"
        Else
            DC15.BackColor = Color.Transparent
            DN15.BackColor = Color.Transparent
            S15.BackColor = Color.Transparent
            T15.BackColor = Color.Transparent
        End If

        If Val(MeterCount.Text) >= Val(T15.Text) Then
            DC15.BackColor = Color.LightGreen
            DN15.BackColor = Color.LightGreen
            S15.BackColor = Color.LightGreen
            T15.BackColor = Color.LightGreen
            worksheet.Cells(16, 9).Value = "Processed"
        End If

        If Val(MeterCount.Text) >= Val(S16.Text) And Val(MeterCount.Text) <= Val(T16.Text) Then
            DC16.BackColor = Color.Orange
            DN16.BackColor = Color.Orange
            S16.BackColor = Color.Orange
            T16.BackColor = Color.Orange
            worksheet.Cells(17, 9).Value = "Incomplete"
        Else
            DC16.BackColor = Color.Transparent
            DN16.BackColor = Color.Transparent
            S16.BackColor = Color.Transparent
            T16.BackColor = Color.Transparent
        End If

        If Val(MeterCount.Text) >= Val(T16.Text) Then
            DC16.BackColor = Color.LightGreen
            DN16.BackColor = Color.LightGreen
            S16.BackColor = Color.LightGreen
            T16.BackColor = Color.LightGreen
            worksheet.Cells(17, 9).Value = "Processed"
        End If

        If Val(MeterCount.Text) >= Val(S17.Text) And Val(MeterCount.Text) <= Val(T17.Text) Then
            DC17.BackColor = Color.Orange
            DN17.BackColor = Color.Orange
            S17.BackColor = Color.Orange
            T17.BackColor = Color.Orange
            worksheet.Cells(18, 9).Value = "Incomplete"
        Else
            DC17.BackColor = Color.Transparent
            DN17.BackColor = Color.Transparent
            S17.BackColor = Color.Transparent
            T17.BackColor = Color.Transparent
        End If

        If Val(MeterCount.Text) >= Val(T17.Text) Then
            DC17.BackColor = Color.LightGreen
            DN17.BackColor = Color.LightGreen
            S17.BackColor = Color.LightGreen
            T17.BackColor = Color.LightGreen
            worksheet.Cells(18, 9).Value = "Processed"
        End If

        If Val(MeterCount.Text) >= Val(S18.Text) And Val(MeterCount.Text) <= Val(T18.Text) Then
            DC18.BackColor = Color.Orange
            DN18.BackColor = Color.Orange
            S18.BackColor = Color.Orange
            T18.BackColor = Color.Orange
            worksheet.Cells(19, 9).Value = "Incomplete"
        Else
            DC18.BackColor = Color.Transparent
            DN18.BackColor = Color.Transparent
            S18.BackColor = Color.Transparent
            T18.BackColor = Color.Transparent
        End If

        If Val(MeterCount.Text) >= Val(T18.Text) Then
            DC18.BackColor = Color.LightGreen
            DN18.BackColor = Color.LightGreen
            S18.BackColor = Color.LightGreen
            T18.BackColor = Color.LightGreen
            worksheet.Cells(19, 9).Value = "Processed"
        End If

        If Val(MeterCount.Text) >= Val(S19.Text) And Val(MeterCount.Text) <= Val(T19.Text) Then
            DC19.BackColor = Color.Orange
            DN19.BackColor = Color.Orange
            S19.BackColor = Color.Orange
            T19.BackColor = Color.Orange
            worksheet.Cells(20, 9).Value = "Incomplete"
        Else
            DC19.BackColor = Color.Transparent
            DN19.BackColor = Color.Transparent
            S19.BackColor = Color.Transparent
            T19.BackColor = Color.Transparent
        End If

        If Val(MeterCount.Text) >= Val(T19.Text) Then
            DC19.BackColor = Color.LightGreen
            DN19.BackColor = Color.LightGreen
            S19.BackColor = Color.LightGreen
            T19.BackColor = Color.LightGreen
            worksheet.Cells(20, 9).Value = "Processed"
        End If
    End Sub

    Private Sub StartButton_Click(sender As Object, e As EventArgs) Handles StartButton.Click
        plc.writeword("404217", 1)
        Threading.Thread.Sleep(1000)
        plc.writeword("404217", 0)
        StartButton.Enabled = False
        BrowseButton.Enabled = False
        PathTextBox.Enabled = False
        PathLabel.Enabled = False
    End Sub
End Class

' "404097" , "002071" etc are PLC's register numbers.

Thanks
 

I'm not familiar with VB, but sometimes it is quite usefull examine whether the error occurs exclusively at simulation environment or not. In some cases, a program that don't works at the Debug version, do not exhibits the same at the Release version. To confirm that, try executing the program outside IDE, just double-clicking the built .exe file.
 

if you do a web search for vb.net System.OverflowException you will get plenty of links, e.g.
**broken link removed**
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top