Answered Read or get cell value (Excel)

JohnH

VB.NET Forum Moderator
Staff member
Joined
Dec 17, 2005
Messages
15,431
Location
Norway
Programming Experience
10+
You can refactor that:
VB.NET:
Dim values As Object(,) = rg1.Value
For i = 1 To values.GetUpperBound(0) 'rows
    If values(i, 3) = value Then
        Invoke(Sub() UpdateUI(values))
        Exit For
    End If
Next

values = rg2.Value
For i = 1 To values.GetUpperBound(0) 'rows
    If values(i, 3) = value Then
        Invoke(Sub() UpdateUI(values))
        Exit For
    End If
Next

'same rg3,rg4,rg5
VB.NET:
Sub UpdateUI(values As Object(,))
    TextBox_RDIMS.Text = values(i, 19)
    TextBox_RSIG.Text = values(i, 18)
    TextBox_LocationNAME.Text = values(i, 4)
    TextBox_Type.Text = values(i, 6)
    TextBox_ABC.Text = values(i, 7)
    TextBox_Railway.Text = values(i, 5)
    TextBox_issue.Text = values(i, 8)
    TextBox_InspFROM.Text = values(i, 9)
    TextBox_InspTO.Text = values(i, 10)
    TextBox_Total_Insp.Text = values(i, 11)
    TextBox_Date.Text = values(i, 12)
    TextBox_Year.Text = values(i, 2)
    TextBox_Lead_RSI.Text = values(i, 15)
    TextBox_2nd_RSI.Text = values(i, 16)
    TextBox_Letterofconcern.Text = values(i, 21)
    TextBox_Prenotice.Text = values(i, 23)
    TextBox_notice_order.Text = values(i, 26)
    TextBox_NAIAT.Text = values(i, 28)
    TextBox_AMP.Text = values(i, 29)
    TextBox_letterofwarning.Text = values(i, 31)
    TextBox_Comments.Text = values(i, 32)
    TextBox_insp_type.Text = values(i, 17)
End Sub
Don't know what's with the "row = row + 1" part, doesn't appear used.

Now the question arise, why continue with next loop if a value has been found? Shouldn't "Exit For" actually be "Exit Sub" ?
 

freddyboy

Active member
Joined
Jun 18, 2020
Messages
27
Programming Experience
Beginner
A lot more clear when I can see it with my eyes.
As for the "row = row + 1", you are right, it's useless and I took it out.
I also changed Exit for for Exit Sub.
Makes more sense that when the value is found, no need to keep looping.

Shall I start showing what I had for the Clearalltext() part, I started something but ended up crying in the dark :p

VB.NET:
  Dim i As long

        Dim values As Object(,) = rg1.Value
        For i = 1 To values.GetUpperBound(0) 'rows
            If values(i, 3) = value Then
                'update UI
                 TextBox_RDIMS.Invoke(New Callback(AddressOf UpdateUI), TextBox_RDIMS, values(i, 19))
                TextBox_RSIG.Invoke(New Callback(AddressOf UpdateUI), TextBox_RSIG, values(i, 18))
                TextBox_LocationNAME.Invoke(New Callback(AddressOf UpdateUI), TextBox_LocationNAME, values(i, 4))
                TextBox_Type.Invoke(New Callback(AddressOf UpdateUI), TextBox_Type, values(i, 6))
                TextBox_ABC.Invoke(New Callback(AddressOf UpdateUI), TextBox_ABC, values(i, 7))
                TextBox_Railway.Invoke(New Callback(AddressOf UpdateUI), TextBox_Railway, values(i, 5))
                TextBox_issue.Invoke(New Callback(AddressOf UpdateUI), TextBox_issue, values(i, 8))
                TextBox_InspFROM.Invoke(New Callback(AddressOf UpdateUI), TextBox_InspFROM, values(i, 9))
                TextBox_InspTO.Invoke(New Callback(AddressOf UpdateUI), TextBox_InspTO, values(i, 10))
                TextBox_Total_Insp.Invoke(New Callback(AddressOf UpdateUI), TextBox_Total_Insp, values(i, 11))
                TextBox_Date.Invoke(New Callback(AddressOf UpdateUI), TextBox_Date, values(i, 12))
                TextBox_Year.Invoke(New Callback(AddressOf UpdateUI), TextBox_Year, values(i, 2))
                TextBox_Lead_RSI.Invoke(New Callback(AddressOf UpdateUI), TextBox_Lead_RSI, values(i, 15))
                TextBox_2nd_RSI.Invoke(New Callback(AddressOf UpdateUI), TextBox_2nd_RSI, values(i, 16))
                TextBox_Letterofconcern.Invoke(New Callback(AddressOf UpdateUI), TextBox_Letterofconcern, values(i, 21))
                TextBox_Prenotice.Invoke(New Callback(AddressOf UpdateUI), TextBox_Prenotice, values(i, 23))
                TextBox_notice_order.Invoke(New Callback(AddressOf UpdateUI), TextBox_notice_order, values(i, 26))
                TextBox_NAIAT.Invoke(New Callback(AddressOf UpdateUI), TextBox_NAIAT, values(i, 28))
                TextBox_AMP.Invoke(New Callback(AddressOf UpdateUI), TextBox_AMP, values(i, 29))
                TextBox_letterofwarning.Invoke(New Callback(AddressOf UpdateUI), TextBox_letterofwarning, values(i, 31))
                TextBox_Comments.Invoke(New Callback(AddressOf UpdateUI), TextBox_Comments, values(i, 32))
                TextBox_insp_type.Invoke(New Callback(AddressOf UpdateUI), TextBox_insp_type, values(i, 17))
                Exit Sub
                'We call the control we MUST invoke, create a new delegate, send it the method to update from, and provide the control to that method, with the new value.
                'See on updating values from cells : https://stackoverflow.com/questions/23004274/vb-net-excel-worksheet-cells-value
            End If
        Next

        values = rg2.Value
        For i = 1 To values.GetUpperBound(0) 'rows
            If values(i, 3) = value Then

                TextBox_RDIMS.Invoke(New Callback(AddressOf UpdateUI), TextBox_RDIMS, values(i, 19))
                TextBox_RSIG.Invoke(New Callback(AddressOf UpdateUI), TextBox_RSIG, values(i, 18))
                TextBox_LocationNAME.Invoke(New Callback(AddressOf UpdateUI), TextBox_LocationNAME, values(i, 4))
                TextBox_Type.Invoke(New Callback(AddressOf UpdateUI), TextBox_Type, values(i, 6))
                TextBox_ABC.Invoke(New Callback(AddressOf UpdateUI), TextBox_ABC, values(i, 7))
                TextBox_Railway.Invoke(New Callback(AddressOf UpdateUI), TextBox_Railway, values(i, 5))
                TextBox_issue.Invoke(New Callback(AddressOf UpdateUI), TextBox_issue, values(i, 8))
                TextBox_InspFROM.Invoke(New Callback(AddressOf UpdateUI), TextBox_InspFROM, values(i, 9))
                TextBox_InspTO.Invoke(New Callback(AddressOf UpdateUI), TextBox_InspTO, values(i, 10))
                TextBox_Total_Insp.Invoke(New Callback(AddressOf UpdateUI), TextBox_Total_Insp, values(i, 11))
                TextBox_Date.Invoke(New Callback(AddressOf UpdateUI), TextBox_Date, values(i, 12))
                TextBox_Year.Invoke(New Callback(AddressOf UpdateUI), TextBox_Year, values(i, 2))
                TextBox_Lead_RSI.Invoke(New Callback(AddressOf UpdateUI), TextBox_Lead_RSI, values(i, 15))
                TextBox_2nd_RSI.Invoke(New Callback(AddressOf UpdateUI), TextBox_2nd_RSI, values(i, 16))
                TextBox_Letterofconcern.Invoke(New Callback(AddressOf UpdateUI), TextBox_Letterofconcern, values(i, 21))
                TextBox_Prenotice.Invoke(New Callback(AddressOf UpdateUI), TextBox_Prenotice, values(i, 23))
                TextBox_notice_order.Invoke(New Callback(AddressOf UpdateUI), TextBox_notice_order, values(i, 26))
                TextBox_NAIAT.Invoke(New Callback(AddressOf UpdateUI), TextBox_NAIAT, values(i, 28))
                TextBox_AMP.Invoke(New Callback(AddressOf UpdateUI), TextBox_AMP, values(i, 29))
                TextBox_letterofwarning.Invoke(New Callback(AddressOf UpdateUI), TextBox_letterofwarning, values(i, 31))
                TextBox_Comments.Invoke(New Callback(AddressOf UpdateUI), TextBox_Comments, values(i, 32))
                TextBox_insp_type.Invoke(New Callback(AddressOf UpdateUI), TextBox_insp_type, values(i, 17))
                Exit Sub
            End If
        Next

        values = rg3.Value
        For i = 1 To values.GetUpperBound(0) 'rows
            If values(i, 3) = value Then

                TextBox_RDIMS.Invoke(New Callback(AddressOf UpdateUI), TextBox_RDIMS, values(i, 19))
                TextBox_RSIG.Invoke(New Callback(AddressOf UpdateUI), TextBox_RSIG, values(i, 18))
                TextBox_LocationNAME.Invoke(New Callback(AddressOf UpdateUI), TextBox_LocationNAME, values(i, 4))
                TextBox_Type.Invoke(New Callback(AddressOf UpdateUI), TextBox_Type, values(i, 6))
                TextBox_ABC.Invoke(New Callback(AddressOf UpdateUI), TextBox_ABC, values(i, 7))
                TextBox_Railway.Invoke(New Callback(AddressOf UpdateUI), TextBox_Railway, values(i, 5))
                TextBox_issue.Invoke(New Callback(AddressOf UpdateUI), TextBox_issue, values(i, 8))
                TextBox_InspFROM.Invoke(New Callback(AddressOf UpdateUI), TextBox_InspFROM, values(i, 9))
                TextBox_InspTO.Invoke(New Callback(AddressOf UpdateUI), TextBox_InspTO, values(i, 10))
                TextBox_Total_Insp.Invoke(New Callback(AddressOf UpdateUI), TextBox_Total_Insp, values(i, 11))
                TextBox_Date.Invoke(New Callback(AddressOf UpdateUI), TextBox_Date, values(i, 12))
                TextBox_Year.Invoke(New Callback(AddressOf UpdateUI), TextBox_Year, values(i, 2))
                TextBox_Lead_RSI.Invoke(New Callback(AddressOf UpdateUI), TextBox_Lead_RSI, values(i, 15))
                TextBox_2nd_RSI.Invoke(New Callback(AddressOf UpdateUI), TextBox_2nd_RSI, values(i, 16))
                TextBox_Letterofconcern.Invoke(New Callback(AddressOf UpdateUI), TextBox_Letterofconcern, values(i, 21))
                TextBox_Prenotice.Invoke(New Callback(AddressOf UpdateUI), TextBox_Prenotice, values(i, 23))
                TextBox_notice_order.Invoke(New Callback(AddressOf UpdateUI), TextBox_notice_order, values(i, 26))
                TextBox_NAIAT.Invoke(New Callback(AddressOf UpdateUI), TextBox_NAIAT, values(i, 28))
                TextBox_AMP.Invoke(New Callback(AddressOf UpdateUI), TextBox_AMP, values(i, 29))
                TextBox_letterofwarning.Invoke(New Callback(AddressOf UpdateUI), TextBox_letterofwarning, values(i, 31))
                TextBox_Comments.Invoke(New Callback(AddressOf UpdateUI), TextBox_Comments, values(i, 32))
                TextBox_insp_type.Invoke(New Callback(AddressOf UpdateUI), TextBox_insp_type, values(i, 17))
                Exit Sub
            End If
        Next

        values = rg4.Value
        For i = 1 To values.GetUpperBound(0) 'rows
            If values(i, 3) = value Then

                TextBox_RDIMS.Invoke(New Callback(AddressOf UpdateUI), TextBox_RDIMS, values(i, 19))
                TextBox_RSIG.Invoke(New Callback(AddressOf UpdateUI), TextBox_RSIG, values(i, 18))
                TextBox_LocationNAME.Invoke(New Callback(AddressOf UpdateUI), TextBox_LocationNAME, values(i, 4))
                TextBox_Type.Invoke(New Callback(AddressOf UpdateUI), TextBox_Type, values(i, 6))
                TextBox_ABC.Invoke(New Callback(AddressOf UpdateUI), TextBox_ABC, values(i, 7))
                TextBox_Railway.Invoke(New Callback(AddressOf UpdateUI), TextBox_Railway, values(i, 5))
                TextBox_issue.Invoke(New Callback(AddressOf UpdateUI), TextBox_issue, values(i, 8))
                TextBox_InspFROM.Invoke(New Callback(AddressOf UpdateUI), TextBox_InspFROM, values(i, 9))
                TextBox_InspTO.Invoke(New Callback(AddressOf UpdateUI), TextBox_InspTO, values(i, 10))
                TextBox_Total_Insp.Invoke(New Callback(AddressOf UpdateUI), TextBox_Total_Insp, values(i, 11))
                TextBox_Date.Invoke(New Callback(AddressOf UpdateUI), TextBox_Date, values(i, 12))
                TextBox_Year.Invoke(New Callback(AddressOf UpdateUI), TextBox_Year, values(i, 2))
                TextBox_Lead_RSI.Invoke(New Callback(AddressOf UpdateUI), TextBox_Lead_RSI, values(i, 15))
                TextBox_2nd_RSI.Invoke(New Callback(AddressOf UpdateUI), TextBox_2nd_RSI, values(i, 16))
                TextBox_Letterofconcern.Invoke(New Callback(AddressOf UpdateUI), TextBox_Letterofconcern, values(i, 21))
                TextBox_Prenotice.Invoke(New Callback(AddressOf UpdateUI), TextBox_Prenotice, values(i, 23))
                TextBox_notice_order.Invoke(New Callback(AddressOf UpdateUI), TextBox_notice_order, values(i, 26))
                TextBox_NAIAT.Invoke(New Callback(AddressOf UpdateUI), TextBox_NAIAT, values(i, 28))
                TextBox_AMP.Invoke(New Callback(AddressOf UpdateUI), TextBox_AMP, values(i, 29))
                TextBox_letterofwarning.Invoke(New Callback(AddressOf UpdateUI), TextBox_letterofwarning, values(i, 31))
                TextBox_Comments.Invoke(New Callback(AddressOf UpdateUI), TextBox_Comments, values(i, 32))
                TextBox_insp_type.Invoke(New Callback(AddressOf UpdateUI), TextBox_insp_type, values(i, 17))
                Exit Sub
            End If
        Next

        values = rg5.Value
        For i = 1 To values.GetUpperBound(0) 'rows
            If values(i, 3) = value Then

                TextBox_RDIMS.Invoke(New Callback(AddressOf UpdateUI), TextBox_RDIMS, values(i, 19))
                TextBox_RSIG.Invoke(New Callback(AddressOf UpdateUI), TextBox_RSIG, values(i, 18))
                TextBox_LocationNAME.Invoke(New Callback(AddressOf UpdateUI), TextBox_LocationNAME, values(i, 4))
                TextBox_Type.Invoke(New Callback(AddressOf UpdateUI), TextBox_Type, values(i, 6))
                TextBox_ABC.Invoke(New Callback(AddressOf UpdateUI), TextBox_ABC, values(i, 7))
                TextBox_Railway.Invoke(New Callback(AddressOf UpdateUI), TextBox_Railway, values(i, 5))
                TextBox_issue.Invoke(New Callback(AddressOf UpdateUI), TextBox_issue, values(i, 8))
                TextBox_InspFROM.Invoke(New Callback(AddressOf UpdateUI), TextBox_InspFROM, values(i, 9))
                TextBox_InspTO.Invoke(New Callback(AddressOf UpdateUI), TextBox_InspTO, values(i, 10))
                TextBox_Total_Insp.Invoke(New Callback(AddressOf UpdateUI), TextBox_Total_Insp, values(i, 11))
                TextBox_Date.Invoke(New Callback(AddressOf UpdateUI), TextBox_Date, values(i, 12))
                TextBox_Year.Invoke(New Callback(AddressOf UpdateUI), TextBox_Year, values(i, 2))
                TextBox_Lead_RSI.Invoke(New Callback(AddressOf UpdateUI), TextBox_Lead_RSI, values(i, 15))
                TextBox_2nd_RSI.Invoke(New Callback(AddressOf UpdateUI), TextBox_2nd_RSI, values(i, 16))
                TextBox_Letterofconcern.Invoke(New Callback(AddressOf UpdateUI), TextBox_Letterofconcern, values(i, 21))
                TextBox_Prenotice.Invoke(New Callback(AddressOf UpdateUI), TextBox_Prenotice, values(i, 23))
                TextBox_notice_order.Invoke(New Callback(AddressOf UpdateUI), TextBox_notice_order, values(i, 26))
                TextBox_NAIAT.Invoke(New Callback(AddressOf UpdateUI), TextBox_NAIAT, values(i, 28))
                TextBox_AMP.Invoke(New Callback(AddressOf UpdateUI), TextBox_AMP, values(i, 29))
                TextBox_letterofwarning.Invoke(New Callback(AddressOf UpdateUI), TextBox_letterofwarning, values(i, 31))
                TextBox_Comments.Invoke(New Callback(AddressOf UpdateUI), TextBox_Comments, values(i, 32))
                TextBox_insp_type.Invoke(New Callback(AddressOf UpdateUI), TextBox_insp_type, values(i, 17))
                Exit Sub
            End If
        Next
    End Sub
 

freddyboy

Active member
Joined
Jun 18, 2020
Messages
27
Programming Experience
Beginner
VB.NET:
This was my 2cent worth of try:

Public Class RSIform

 Dim MonThread As New Thread(AddressOf Rangeloops)
    Public Delegate Sub Callback(ByVal s As Control, ByVal v As Object)
    
     'Dim MonThread2 As New Thread(AddressOf Clearalltxtboxthread)
    
      Private Sub TreeView_Insp_Records_AfterSelect(sender As System.Object, e As System.Windows.Forms.TreeViewEventArgs) Handles TreeView_Insp_Records.AfterSelect
        'Dim thread2 As New Thread(Sub() Clearalltxtboxthread(Text))
        'thread2.Start()

        Clearalltextbox() 'Make sure all fields are empty while switching form child to child
        TextBox_selectednodes.Text = TreeView_Insp_Records.SelectedNode.Text
        Ping_network()

        Dim thread As New Thread(Sub() ExecuteWork(e.Node.Text))
        thread.Start()
    End Sub
     'Not sure if its ( .Text = "" instead of = .Text = text  ) I tried both with errors.
    'Private Sub Clearalltxtboxthread(ByVal text As String)

    '    txtNodeTextSearch.Invoke(New Callback(AddressOf UpdateUI), txtNodeTextSearch.Text = text)
    '    TextBox_RDIMS.Invoke(New Callback(AddressOf UpdateUI), TextBox_RDIMS.Text = text)
    '    TextBox_RSIG.Invoke(New Callback(AddressOf UpdateUI), TextBox_RSIG.Text = text)
    '    TextBox_LocationNAME.Invoke(New Callback(AddressOf UpdateUI), TextBox_LocationNAME.Text = text)
    '    TextBox_Railway.Invoke(New Callback(AddressOf UpdateUI), TextBox_Railway.Text = text)
    '    TextBox_Type.Invoke(New Callback(AddressOf UpdateUI), TextBox_Type.Text = text)
    '    TextBox_ABC.Invoke(New Callback(AddressOf UpdateUI), TextBox_ABC.Text = text)
    '    TextBox_issue.Invoke(New Callback(AddressOf UpdateUI), TextBox_issue.Text = text)
    '    TextBox_InspFROM.Invoke(New Callback(AddressOf UpdateUI), TextBox_issue.Text = text)
    '    TextBox_InspTO.Invoke(New Callback(AddressOf UpdateUI), TextBox_InspTO.Text = text)
    '    TextBox_Total_Insp.Invoke(New Callback(AddressOf UpdateUI), TextBox_Total_Insp.Text = text)
    '    TextBox_Date.Invoke(New Callback(AddressOf UpdateUI), TextBox_Date.Text = text)
    '    TextBox_Year.Invoke(New Callback(AddressOf UpdateUI), TextBox_Year.Text = text)
    '    TextBox_Lead_RSI.Invoke(New Callback(AddressOf UpdateUI), TextBox_Lead_RSI.Text = text)
    '    TextBox_2nd_RSI.Invoke(New Callback(AddressOf UpdateUI), TextBox_2nd_RSI.Text = Text)
    '    TextBox_Letterofconcern.Invoke(New Callback(AddressOf UpdateUI), TextBox_Letterofconcern.Text = text)
    '    TextBox_Prenotice.Invoke(New Callback(AddressOf UpdateUI), TextBox_Prenotice.Text = text)
    '    TextBox_notice_order.Invoke(New Callback(AddressOf UpdateUI), TextBox_notice_order.Text = text)
    '    TextBox_AMP.Invoke(New Callback(AddressOf UpdateUI), TextBox_AMP.Text = text)
    '    TextBox_NAIAT.Invoke(New Callback(AddressOf UpdateUI), TextBox_NAIAT.Text = text)
    '    TextBox_letterofwarning.Invoke(New Callback(AddressOf UpdateUI), TextBox_letterofwarning.Text = text)
    '    TextBox_Comments.Invoke(New Callback(AddressOf UpdateUI), TextBox_Comments.Text = text)
    '    TextBox_selectednodes.Invoke(New Callback(AddressOf UpdateUI), TextBox_selectednodes.Text = text)
    '    TextBox_insp_type.Invoke(New Callback(AddressOf UpdateUI), TextBox_insp_type.Text = text)

    'End Sub
      Private Sub Clearalltextbox()

        txtNodeTextSearch.Text = ""
        TextBox_RDIMS.Text = ""
        TextBox_RSIG.Text = ""
        TextBox_LocationNAME.Text = ""
        TextBox_Railway.Text = ""
        TextBox_Type.Text = ""
        TextBox_ABC.Text = ""
        TextBox_issue.Text = ""
        TextBox_InspFROM.Text = ""
        TextBox_InspTO.Text = ""
        TextBox_Total_Insp.Text = ""
        TextBox_Date.Text = ""
        TextBox_Year.Text = ""
        TextBox_Lead_RSI.Text = ""
        TextBox_2nd_RSI.Text = ""
        TextBox_Letterofconcern.Text = ""
        TextBox_Prenotice.Text = ""
        TextBox_notice_order.Text = ""
        TextBox_AMP.Text = ""
        TextBox_NAIAT.Text = ""
        TextBox_letterofwarning.Text = ""
        TextBox_Comments.Text = ""
        TextBox_selectednodes.Text = ""
        TextBox_insp_type.Text = ""

    End Sub
 

Sheepings

Senior Programmer
Staff member
Joined
Mar 7, 2014
Messages
131
Location
UK
Programming Experience
10+
Where are you pulling text from? Get some rest, you've been at this all day.

And I can't look at it right now either, as my eyes are burning from signing contracts all day. Maybe through the night, JohnH might help you straighten out some of your code, providing he's feeling generous. 😜

If you want to pass in a parameter to clear your textboxes. Set it with String.Empty or "" not "text".

Good night for now.

PS. doing a code dump on p/43 isn't very helpful. I don't know how far you've come. So explain where you are at and what your current problem is with the code you have.
 

freddyboy

Active member
Joined
Jun 18, 2020
Messages
27
Programming Experience
Beginner
VB.NET:
VB.NET:
Alright, so before I head to bed; this is where I'm at.
No rush for any answers, get some rest and we'll exploit your brain tomorrow!
Until then, this is what I did, I tried making a Thread for Clearalltext and it gave me an error at line 31 and probably all the other lines underneath as showed on the picture attached.
It's still not clear for me if a delegates always require a thread of their own, or I can have 1 main thread with 2 delegates ?   Plz don't throw rocks at me!

Because of the error, I tried another way and I don't get any error.

Public Class RSIform

    Dim MonThread As New Thread(AddressOf Rangeloops)
    Public Delegate Sub Callback(ByVal s As Control, ByVal v As Object)

    Dim Thread2 As New Thread(AddressOf Clearalltxtboxthread)
    Public Delegate Sub CallbackClearalltext(ByVal s As String)

     Private Sub TreeView_Insp_Records_AfterSelect(sender As System.Object, e As System.Windows.Forms.TreeViewEventArgs) Handles TreeView_Insp_Records.AfterSelect

        Dim thread As New Thread(Sub() ExecuteWork(e.Node.Text))
        thread.Start()

        Dim thread2 As New Thread(Sub() Clearalltxtboxthread(e.Node.Text))
        Thread2.Start()

     Clearalltextbox() 'Make sure all fields are empty while switching form child to child
        TextBox_selectednodes.Text = TreeView_Insp_Records.SelectedNode.Text
        Ping_network()

     Private Sub Clearalltxtboxthread(ByVal text As String)


        'txtNodeTextSearch.Invoke(New CallbackClearalltext(AddressOf Clearalltxtboxthread), txtNodeTextSearch.Text, String.Empty)
        'TextBox_RDIMS.Invoke(New CallbackClearalltext(AddressOf Clearalltxtboxthread), TextBox_RDIMS.Text = String.Empty)
        'TextBox_RSIG.Invoke(New CallbackClearalltext(AddressOf Clearalltxtboxthread), TextBox_RSIG.Text = String.Empty)
        'TextBox_LocationNAME.Invoke(New CallbackClearalltext(AddressOf Clearalltxtboxthread), TextBox_LocationNAME.Text = String.Empty)
        'TextBox_Railway.Invoke(New CallbackClearalltext(AddressOf Clearalltxtboxthread), TextBox_Railway.Text = String.Empty)
        'TextBox_Type.Invoke(New CallbackClearalltext(AddressOf Clearalltxtboxthread), TextBox_Type.Text = String.Empty)
        'TextBox_ABC.Invoke(New CallbackClearalltext(AddressOf Clearalltxtboxthread), TextBox_ABC.Text = String.Empty)
        'TextBox_issue.Invoke(New CallbackClearalltext(AddressOf Clearalltxtboxthread), TextBox_issue.Text = String.Empty)
        'TextBox_InspFROM.Invoke(New CallbackClearalltext(AddressOf Clearalltxtboxthread), TextBox_issue.Text = String.Empty)
        'TextBox_InspTO.Invoke(New CallbackClearalltext(AddressOf Clearalltxtboxthread), TextBox_InspTO.Text = String.Empty)
        'TextBox_Total_Insp.Invoke(New CallbackClearalltext(AddressOf Clearalltxtboxthread), TextBox_Total_Insp.Text = String.Empty)
        'TextBox_Date.Invoke(New CallbackClearalltext(AddressOf Clearalltxtboxthread), TextBox_Date.Text = String.Empty)
        'TextBox_Year.Invoke(New CallbackClearalltext(AddressOf Clearalltxtboxthread), TextBox_Year.Text = String.Empty)
        'TextBox_Lead_RSI.Invoke(New CallbackClearalltext(AddressOf Clearalltxtboxthread), TextBox_Lead_RSI.Text = String.Empty)
        'TextBox_2nd_RSI.Invoke(New CallbackClearalltext(AddressOf Clearalltxtboxthread), TextBox_2nd_RSI.Text = String.Empty)
        'TextBox_Letterofconcern.Invoke(New CallbackClearalltext(AddressOf Clearalltxtboxthread), TextBox_Letterofconcern.Text = String.Empty)
        'TextBox_Prenotice.Invoke(New CallbackClearalltext(AddressOf Clearalltxtboxthread), TextBox_Prenotice.Text = String.Empty)
        'TextBox_notice_order.Invoke(New CallbackClearalltext(AddressOf Clearalltxtboxthread), TextBox_notice_order.Text = String.Empty)
        'TextBox_AMP.Invoke(New CallbackClearalltext(AddressOf Clearalltxtboxthread), TextBox_AMP.Text = String.Empty)
        'TextBox_NAIAT.Invoke(New CallbackClearalltext(AddressOf Clearalltxtboxthread), TextBox_NAIAT.Text = String.Empty)
        'TextBox_letterofwarning.Invoke(New CallbackClearalltext(AddressOf Clearalltxtboxthread), TextBox_letterofwarning.Text = String.Empty)
        'TextBox_Comments.Invoke(New CallbackClearalltext(AddressOf Clearalltxtboxthread), TextBox_Comments.Text = String.Empty)
        'TextBox_selectednodes.Invoke(New CallbackClearalltext(AddressOf Clearalltxtboxthread), TextBox_selectednodes.Text = String.Empty)
        'TextBox_insp_type.Invoke(New CallbackClearalltext(AddressOf Clearalltxtboxthread), TextBox_insp_type.Text = String.Empty)

        'I comment the above code because I was getting error and tried this instead:

 
  Me.Invoke(Sub()
                      Me.txtNodeTextSearch.Text = ""
                      Me.TextBox_RDIMS.Text = ""
                      Me.TextBox_RSIG.Text = ""
                      Me.TextBox_LocationNAME.Text = ""
                      Me.TextBox_Railway.Text = ""
                      Me.TextBox_Type.Text = ""
                      Me.TextBox_ABC.Text = ""
                      Me.TextBox_issue.Text = ""
                      Me.TextBox_InspFROM.Text = ""
                      Me.TextBox_InspTO.Text = ""
                      Me.TextBox_Total_Insp.Text = ""
                      Me.TextBox_Date.Text = ""
                      Me.TextBox_Year.Text = ""
                      Me.TextBox_Lead_RSI.Text = ""
                      Me.TextBox_2nd_RSI.Text = ""
                      Me.TextBox_Letterofconcern.Text = ""
                      Me.TextBox_Prenotice.Text = ""
                      Me.TextBox_AMP.Text = ""
                      Me.TextBox_NAIAT.Text = ""
                      Me.TextBox_letterofwarning.Text = ""
                      Me.TextBox_Comments.Text = ""
                      Me.TextBox_selectednodes.Text = ""
                      Me.TextBox_insp_type.Text = ""
                  End Sub)
     End Sub

      Private Sub Clearalltextbox()

        txtNodeTextSearch.Text = ""
        TextBox_RDIMS.Text = ""
        TextBox_RSIG.Text = ""
        TextBox_LocationNAME.Text = ""
        TextBox_Railway.Text = ""
        TextBox_Type.Text = ""
        TextBox_ABC.Text = ""
        TextBox_issue.Text = ""
        TextBox_InspFROM.Text = ""
        TextBox_InspTO.Text = ""
        TextBox_Total_Insp.Text = ""
        TextBox_Date.Text = ""
        TextBox_Year.Text = ""
        TextBox_Lead_RSI.Text = ""
        TextBox_2nd_RSI.Text = ""
        TextBox_Letterofconcern.Text = ""
        TextBox_Prenotice.Text = ""
        TextBox_notice_order.Text = ""
        TextBox_AMP.Text = ""
        TextBox_NAIAT.Text = ""
        TextBox_letterofwarning.Text = ""
        TextBox_Comments.Text = ""
        TextBox_selectednodes.Text = ""
        TextBox_insp_type.Text = ""

    End Sub
Capture.PNG
VB.NET:
 
Last edited:

Sheepings

Senior Programmer
Staff member
Joined
Mar 7, 2014
Messages
131
Location
UK
Programming Experience
10+
Don't change the code I gave you. After this, you need to read MSDN docs on how to pass parameters to methods. You are seriously lacking the basic understanding of the most simplest steps. Googling your way through a project is the worst way to learn programming. And I am not in a habit of helping copy/paste programmers, as it serves no purpose. I also have no idea if this is going to work, as your code is one awful mess. And this :
VB.NET:
        Dim thread2 As New Thread(Sub() Clearalltxtboxthread(String.Empty))
        thread2.Start()
does not belong in the after select event. Move it to a button. You are setting the values and then automatically clearing them. I'm done here.

VB.NET:
    Dim MonThread As New Thread(AddressOf Rangeloops)
    Public Delegate Sub Callback(ByVal s As Control, ByVal v As Object)
    Dim Thread2 As New Thread(AddressOf Clearalltxtboxthread)
    Private Sub UpdateUI(ByVal this_Control As Control, ByVal vRange As Object)
        this_Control.Text = CType(vRange, String)
    End Sub
    Private Sub TreeView_Insp_Records_AfterSelect(sender As System.Object, e As System.Windows.Forms.TreeViewEventArgs) Handles TreeView_Insp_Records.AfterSelect

        Dim thread As New Thread(Sub() ExecuteWork(e.Node.Text))
        thread.Start()

        Dim thread2 As New Thread(Sub() Clearalltxtboxthread(String.Empty))
        thread2.Start()
        Ping_network()
    End Sub

    Private Sub Clearalltxtboxthread(ByVal text As String)
        txtNodeTextSearch.Invoke(New Callback(AddressOf UpdateUI), txtNodeTextSearch, String.Empty)
        TextBox_RDIMS.Invoke(New Callback(AddressOf UpdateUI), TextBox_RDIMS, String.Empty)
        TextBox_RSIG.Invoke(New Callback(AddressOf UpdateUI), TextBox_RSIG, String.Empty)
        TextBox_LocationNAME.Invoke(New Callback(AddressOf UpdateUI), TextBox_LocationNAME, String.Empty)
        TextBox_Railway.Invoke(New Callback(AddressOf UpdateUI), TextBox_Railway, String.Empty)
        TextBox_Type.Invoke(New Callback(AddressOf UpdateUI), TextBox_Type, String.Empty)
        TextBox_ABC.Invoke(New Callback(AddressOf UpdateUI), TextBox_ABC, String.Empty)
        TextBox_issue.Invoke(New Callback(AddressOf UpdateUI), TextBox_issue, String.Empty)
        TextBox_InspFROM.Invoke(New Callback(AddressOf UpdateUI), TextBox_issue, String.Empty)
        TextBox_InspTO.Invoke(New Callback(AddressOf UpdateUI), TextBox_InspTO, String.Empty)
        TextBox_Total_Insp.Invoke(New Callback(AddressOf UpdateUI), TextBox_Total_Insp, String.Empty)
        TextBox_Date.Invoke(New Callback(AddressOf UpdateUI), TextBox_Date, String.Empty)
        TextBox_Year.Invoke(New Callback(AddressOf UpdateUI), TextBox_Year, String.Empty)
        TextBox_Lead_RSI.Invoke(New Callback(AddressOf UpdateUI), TextBox_Lead_RSI, String.Empty)
        TextBox_2nd_RSI.Invoke(New Callback(AddressOf UpdateUI), TextBox_2nd_RSI, String.Empty)
        TextBox_Letterofconcern.Invoke(New Callback(AddressOf UpdateUI), TextBox_Letterofconcern, String.Empty)
        TextBox_Prenotice.Invoke(New Callback(AddressOf UpdateUI), TextBox_Prenotice, String.Empty)
        TextBox_notice_order.Invoke(New Callback(AddressOf UpdateUI), TextBox_notice_order, String.Empty)
        TextBox_AMP.Invoke(New Callback(AddressOf UpdateUI), TextBox_AMP, String.Empty)
        TextBox_NAIAT.Invoke(New Callback(AddressOf UpdateUI), TextBox_NAIAT, String.Empty)
        TextBox_letterofwarning.Invoke(New Callback(AddressOf UpdateUI), TextBox_letterofwarning, String.Empty)
        TextBox_Comments.Invoke(New Callback(AddressOf UpdateUI), TextBox_Comments, String.Empty)
        TextBox_selectednodes.Invoke(New Callback(AddressOf UpdateUI), TextBox_selectednodes, String.Empty)
        TextBox_insp_type.Invoke(New Callback(AddressOf UpdateUI), TextBox_insp_type, String.Empty)
    End Sub
 
Top Bottom