Answered Read or get cell value (Excel)

Sheepings

Senior Programmer
Staff member
Joined
Mar 7, 2014
Messages
131
Location
UK
Programming Experience
10+
Small adjustment :
VB.NET:
    Private Sub TreeView1_AfterSelect(sender As Object, e As TreeViewEventArgs) Handles TreeView_Insp_Records.AfterSelect
        Dim thread As New Thread(Sub() ExecuteWork(e.Node.Text))
        thread.Start()
    End Sub
No more error. Sorry, I'm not currently using VS to write this.
 

freddyboy

Active member
Joined
Jun 18, 2020
Messages
27
Programming Experience
Beginner
VB.NET:
Imports System.Threading

Public Class RSIform

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

        Dim row As Long
        row = 1

        Dim Inspfred As Worksheet
        Dim Inspchris As Worksheet
        Dim Inspjr As Worksheet
        Dim Inspluc As Worksheet
        Dim Inspted As Worksheet
        Inspfred = Form1.xlWorkBook.Sheets("Inspfred")
        Inspchris = Form1.xlWorkBook.Sheets("Inspchris")
        Inspjr = Form1.xlWorkBook.Sheets("Inspjr")
        Inspluc = Form1.xlWorkBook.Sheets("Inspluc")
        Inspted = Form1.xlWorkBook.Sheets("Inspted")
        Dim rg1 As Range 'Range for fred
        Dim rg2 As Range 'Range for chris
        Dim rg3 As Range 'Range for jr
        Dim rg4 As Range 'Range for luc
        Dim rg5 As Range 'Range for ted
        rg1 = Inspfred.Range("C1").CurrentRegion
        rg2 = Inspchris.Range("C1").CurrentRegion
        rg3 = Inspjr.Range("C1").CurrentRegion
        rg4 = Inspluc.Range("C1").CurrentRegion
        rg5 = Inspted.Range("C1").CurrentRegion
        
         Dim s As String = "Testing Worker Method"
        For i = 1 To rg1.Rows.Count 'Range pour Inspfred
            Debug.Write(s)
            
            If rg1.Cells(i, 3).value = value Then
                TextBox_RDIMS.Invoke(New Callback(AddressOf UpdateUI), TextBox_RDIMS, rg1.Cells(i, 19).value)
                TextBox_RSIG.Invoke(New Callback(AddressOf UpdateUI), TextBox_RSIG, rg1.Cells(i, 18).value)
                TextBox_LocationNAME.Invoke(New Callback(AddressOf UpdateUI), TextBox_LocationNAME, rg1.Cells(i, 4).value)
                TextBox_Type.Invoke(New Callback(AddressOf UpdateUI), TextBox_Type, rg1.Cells(i, 6).value)
                TextBox_ABC.Invoke(New Callback(AddressOf UpdateUI), TextBox_ABC, rg1.Cells(i, 7).value)
                TextBox_Railway.Invoke(New Callback(AddressOf UpdateUI), TextBox_Railway, rg1.Cells(i, 5).value)
                TextBox_issue.Invoke(New Callback(AddressOf UpdateUI), TextBox_issue, rg1.Cells(i, 8).value)
                TextBox_InspFROM.Invoke(New Callback(AddressOf UpdateUI), TextBox_InspFROM, rg1.Cells(i, 9).value)
                TextBox_InspTO.Invoke(New Callback(AddressOf UpdateUI), TextBox_InspTO, rg1.Cells(i, 10).value)
                TextBox_Total_Insp.Invoke(New Callback(AddressOf UpdateUI), TextBox_Total_Insp, rg1.Cells(i, 11).value)
                TextBox_Date.Invoke(New Callback(AddressOf UpdateUI), TextBox_Date, rg1.Cells(i, 12).value)
                TextBox_Year.Invoke(New Callback(AddressOf UpdateUI), TextBox_Year, rg1.Cells(i, 2).value)
                TextBox_Lead_RSI.Invoke(New Callback(AddressOf UpdateUI), TextBox_Lead_RSI, rg1.Cells(i, 15).value)
                TextBox_2nd_RSI.Invoke(New Callback(AddressOf UpdateUI), TextBox_2nd_RSI, rg1.Cells(i, 16).value)
                TextBox_Letterofconcern.Invoke(New Callback(AddressOf UpdateUI), TextBox_Letterofconcern, rg1.Cells(i, 21).value)
                TextBox_Prenotice.Invoke(New Callback(AddressOf UpdateUI), TextBox_Prenotice, rg1.Cells(i, 23).value)
                TextBox_notice_order.Invoke(New Callback(AddressOf UpdateUI), TextBox_notice_order, rg1.Cells(i, 26).value)
                TextBox_NAIAT.Invoke(New Callback(AddressOf UpdateUI), TextBox_NAIAT, rg1.Cells(i, 28).value)
                TextBox_AMP.Invoke(New Callback(AddressOf UpdateUI), TextBox_AMP, rg1.Cells(i, 29).value)
                TextBox_letterofwarning.Invoke(New Callback(AddressOf UpdateUI), TextBox_letterofwarning, rg1.Cells(i, 31).value)
                TextBox_Comments.Invoke(New Callback(AddressOf UpdateUI), TextBox_Comments, rg1.Cells(i, 32).value)
                TextBox_insp_type.Invoke(New Callback(AddressOf UpdateUI), TextBox_insp_type, rg1.Cells(i, 17).value)
                row = row + 1
                Exit For
             End If
        Next
        
         For i = 1 To rg2.Rows.Count 'Range pour Inspchris
            If rg2.Cells(i, 3).value = value Then
                TextBox_RDIMS.Invoke(New Callback(AddressOf UpdateUI), TextBox_RDIMS, rg2.Cells(i, 19).value)
                TextBox_RSIG.Invoke(New Callback(AddressOf UpdateUI), TextBox_RSIG, rg2.Cells(i, 18).value)
                TextBox_LocationNAME.Invoke(New Callback(AddressOf UpdateUI), TextBox_LocationNAME, rg2.Cells(i, 4).value)
                TextBox_Type.Invoke(New Callback(AddressOf UpdateUI), TextBox_Type, rg2.Cells(i, 6).value)
                TextBox_ABC.Invoke(New Callback(AddressOf UpdateUI), TextBox_ABC, rg2.Cells(i, 7).value)
                TextBox_Railway.Invoke(New Callback(AddressOf UpdateUI), TextBox_Railway, rg2.Cells(i, 5).value)
                TextBox_issue.Invoke(New Callback(AddressOf UpdateUI), TextBox_issue, rg2.Cells(i, 8).value)
                TextBox_InspFROM.Invoke(New Callback(AddressOf UpdateUI), TextBox_InspFROM, rg2.Cells(i, 9).value)
                TextBox_InspTO.Invoke(New Callback(AddressOf UpdateUI), TextBox_InspTO, rg2.Cells(i, 10).value)
                TextBox_Total_Insp.Invoke(New Callback(AddressOf UpdateUI), TextBox_Total_Insp, rg2.Cells(i, 11).value)
                TextBox_Date.Invoke(New Callback(AddressOf UpdateUI), TextBox_Date, rg2.Cells(i, 12).value)
                TextBox_Year.Invoke(New Callback(AddressOf UpdateUI), TextBox_Year, rg2.Cells(i, 2).value)
                TextBox_Lead_RSI.Invoke(New Callback(AddressOf UpdateUI), TextBox_Lead_RSI, rg2.Cells(i, 15).value)
                TextBox_2nd_RSI.Invoke(New Callback(AddressOf UpdateUI), TextBox_2nd_RSI, rg2.Cells(i, 16).value)
                TextBox_Letterofconcern.Invoke(New Callback(AddressOf UpdateUI), TextBox_Letterofconcern, rg2.Cells(i, 21).value)
                TextBox_Prenotice.Invoke(New Callback(AddressOf UpdateUI), TextBox_Prenotice, rg2.Cells(i, 23).value)
                TextBox_notice_order.Invoke(New Callback(AddressOf UpdateUI), TextBox_notice_order, rg2.Cells(i, 26).value)
                TextBox_NAIAT.Invoke(New Callback(AddressOf UpdateUI), TextBox_NAIAT, rg2.Cells(i, 28).value)
                TextBox_AMP.Invoke(New Callback(AddressOf UpdateUI), TextBox_AMP, rg2.Cells(i, 29).value)
                TextBox_letterofwarning.Invoke(New Callback(AddressOf UpdateUI), TextBox_letterofwarning, rg2.Cells(i, 31).value)
                TextBox_Comments.Invoke(New Callback(AddressOf UpdateUI), TextBox_Comments, rg2.Cells(i, 32).value)
                TextBox_insp_type.Invoke(New Callback(AddressOf UpdateUI), TextBox_insp_type, rg2.Cells(i, 17).value)
                row = row + 1
                Exit For
            End If
            
        Next
         For i = 1 To rg3.Rows.Count 'Range pour Inspjr
            If rg3.Cells(i, 3).value = value Then
                TextBox_RDIMS.Invoke(New Callback(AddressOf UpdateUI), TextBox_RDIMS, rg3.Cells(i, 19).value)
                TextBox_RSIG.Invoke(New Callback(AddressOf UpdateUI), TextBox_RSIG, rg3.Cells(i, 18).value)
                TextBox_LocationNAME.Invoke(New Callback(AddressOf UpdateUI), TextBox_LocationNAME, rg3.Cells(i, 4).value)
                TextBox_Type.Invoke(New Callback(AddressOf UpdateUI), TextBox_Type, rg3.Cells(i, 6).value)
                TextBox_ABC.Invoke(New Callback(AddressOf UpdateUI), TextBox_ABC, rg3.Cells(i, 7).value)
                TextBox_Railway.Invoke(New Callback(AddressOf UpdateUI), TextBox_Railway, rg3.Cells(i, 5).value)
                TextBox_issue.Invoke(New Callback(AddressOf UpdateUI), TextBox_issue, rg3.Cells(i, 8).value)
                TextBox_InspFROM.Invoke(New Callback(AddressOf UpdateUI), TextBox_InspFROM, rg3.Cells(i, 9).value)
                TextBox_InspTO.Invoke(New Callback(AddressOf UpdateUI), TextBox_InspTO, rg3.Cells(i, 10).value)
                TextBox_Total_Insp.Invoke(New Callback(AddressOf UpdateUI), TextBox_Total_Insp, rg3.Cells(i, 11).value)
                TextBox_Date.Invoke(New Callback(AddressOf UpdateUI), TextBox_Date, rg3.Cells(i, 12).value)
                TextBox_Year.Invoke(New Callback(AddressOf UpdateUI), TextBox_Year, rg3.Cells(i, 2).value)
                TextBox_Lead_RSI.Invoke(New Callback(AddressOf UpdateUI), TextBox_Lead_RSI, rg3.Cells(i, 15).value)
                TextBox_2nd_RSI.Invoke(New Callback(AddressOf UpdateUI), TextBox_2nd_RSI, rg3.Cells(i, 16).value)
                TextBox_Letterofconcern.Invoke(New Callback(AddressOf UpdateUI), TextBox_Letterofconcern, rg3.Cells(i, 21).value)
                TextBox_Prenotice.Invoke(New Callback(AddressOf UpdateUI), TextBox_Prenotice, rg3.Cells(i, 23).value)
                TextBox_notice_order.Invoke(New Callback(AddressOf UpdateUI), TextBox_notice_order, rg3.Cells(i, 26).value)
                TextBox_NAIAT.Invoke(New Callback(AddressOf UpdateUI), TextBox_NAIAT, rg3.Cells(i, 28).value)
                TextBox_AMP.Invoke(New Callback(AddressOf UpdateUI), TextBox_AMP, rg3.Cells(i, 29).value)
                TextBox_letterofwarning.Invoke(New Callback(AddressOf UpdateUI), TextBox_letterofwarning, rg3.Cells(i, 31).value)
                TextBox_Comments.Invoke(New Callback(AddressOf UpdateUI), TextBox_Comments, rg3.Cells(i, 32).value)
                TextBox_insp_type.Invoke(New Callback(AddressOf UpdateUI), TextBox_insp_type, rg3.Cells(i, 17).value)
                row = row + 1
                Exit For
            End If
            
        Next
         For i = 1 To rg4.Rows.Count 'Range pour Inspluc
            If rg4.Cells(i, 3).value = value Then
                TextBox_RDIMS.Invoke(New Callback(AddressOf UpdateUI), TextBox_RDIMS, rg4.Cells(i, 19).value)
                TextBox_RSIG.Invoke(New Callback(AddressOf UpdateUI), TextBox_RSIG, rg4.Cells(i, 18).value)
                TextBox_LocationNAME.Invoke(New Callback(AddressOf UpdateUI), TextBox_LocationNAME, rg4.Cells(i, 4).value)
                TextBox_Type.Invoke(New Callback(AddressOf UpdateUI), TextBox_Type, rg4.Cells(i, 6).value)
                TextBox_ABC.Invoke(New Callback(AddressOf UpdateUI), TextBox_ABC, rg4.Cells(i, 7).value)
                TextBox_Railway.Invoke(New Callback(AddressOf UpdateUI), TextBox_Railway, rg4.Cells(i, 5).value)
                TextBox_issue.Invoke(New Callback(AddressOf UpdateUI), TextBox_issue, rg4.Cells(i, 8).value)
                TextBox_InspFROM.Invoke(New Callback(AddressOf UpdateUI), TextBox_InspFROM, rg4.Cells(i, 9).value)
                TextBox_InspTO.Invoke(New Callback(AddressOf UpdateUI), TextBox_InspTO, rg4.Cells(i, 10).value)
                TextBox_Total_Insp.Invoke(New Callback(AddressOf UpdateUI), TextBox_Total_Insp, rg4.Cells(i, 11).value)
                TextBox_Date.Invoke(New Callback(AddressOf UpdateUI), TextBox_Date, rg4.Cells(i, 12).value)
                TextBox_Year.Invoke(New Callback(AddressOf UpdateUI), TextBox_Year, rg4.Cells(i, 2).value)
                TextBox_Lead_RSI.Invoke(New Callback(AddressOf UpdateUI), TextBox_Lead_RSI, rg4.Cells(i, 15).value)
                TextBox_2nd_RSI.Invoke(New Callback(AddressOf UpdateUI), TextBox_2nd_RSI, rg4.Cells(i, 16).value)
                TextBox_Letterofconcern.Invoke(New Callback(AddressOf UpdateUI), TextBox_Letterofconcern, rg4.Cells(i, 21).value)
                TextBox_Prenotice.Invoke(New Callback(AddressOf UpdateUI), TextBox_Prenotice, rg4.Cells(i, 23).value)
                TextBox_notice_order.Invoke(New Callback(AddressOf UpdateUI), TextBox_notice_order, rg4.Cells(i, 26).value)
                TextBox_NAIAT.Invoke(New Callback(AddressOf UpdateUI), TextBox_NAIAT, rg4.Cells(i, 28).value)
                TextBox_AMP.Invoke(New Callback(AddressOf UpdateUI), TextBox_AMP, rg4.Cells(i, 29).value)
                TextBox_letterofwarning.Invoke(New Callback(AddressOf UpdateUI), TextBox_letterofwarning, rg4.Cells(i, 31).value)
                TextBox_Comments.Invoke(New Callback(AddressOf UpdateUI), TextBox_Comments, rg4.Cells(i, 32).value)
                TextBox_insp_type.Invoke(New Callback(AddressOf UpdateUI), TextBox_insp_type, rg4.Cells(i, 17).value)
                row = row + 1
                Exit For
            End If
            
        Next
        For i = 1 To rg5.Rows.Count 'Range pour Inspted
            If rg5.Cells(i, 3).value = value Then
                TextBox_RDIMS.Invoke(New Callback(AddressOf UpdateUI), TextBox_RDIMS, rg5.Cells(i, 19).value)
                TextBox_RSIG.Invoke(New Callback(AddressOf UpdateUI), TextBox_RSIG, rg5.Cells(i, 18).value)
                TextBox_LocationNAME.Invoke(New Callback(AddressOf UpdateUI), TextBox_LocationNAME, rg5.Cells(i, 4).value)
                TextBox_Type.Invoke(New Callback(AddressOf UpdateUI), TextBox_Type, rg5.Cells(i, 6).value)
                TextBox_ABC.Invoke(New Callback(AddressOf UpdateUI), TextBox_ABC, rg5.Cells(i, 7).value)
                TextBox_Railway.Invoke(New Callback(AddressOf UpdateUI), TextBox_Railway, rg5.Cells(i, 5).value)
                TextBox_issue.Invoke(New Callback(AddressOf UpdateUI), TextBox_issue, rg5.Cells(i, 8).value)
                TextBox_InspFROM.Invoke(New Callback(AddressOf UpdateUI), TextBox_InspFROM, rg5.Cells(i, 9).value)
                TextBox_InspTO.Invoke(New Callback(AddressOf UpdateUI), TextBox_InspTO, rg5.Cells(i, 10).value)
                TextBox_Total_Insp.Invoke(New Callback(AddressOf UpdateUI), TextBox_Total_Insp, rg5.Cells(i, 11).value)
                TextBox_Date.Invoke(New Callback(AddressOf UpdateUI), TextBox_Date, rg5.Cells(i, 12).value)
                TextBox_Year.Invoke(New Callback(AddressOf UpdateUI), TextBox_Year, rg5.Cells(i, 2).value)
                TextBox_Lead_RSI.Invoke(New Callback(AddressOf UpdateUI), TextBox_Lead_RSI, rg5.Cells(i, 15).value)
                TextBox_2nd_RSI.Invoke(New Callback(AddressOf UpdateUI), TextBox_2nd_RSI, rg5.Cells(i, 16).value)
                TextBox_Letterofconcern.Invoke(New Callback(AddressOf UpdateUI), TextBox_Letterofconcern, rg5.Cells(i, 21).value)
                TextBox_Prenotice.Invoke(New Callback(AddressOf UpdateUI), TextBox_Prenotice, rg5.Cells(i, 23).value)
                TextBox_notice_order.Invoke(New Callback(AddressOf UpdateUI), TextBox_notice_order, rg5.Cells(i, 26).value)
                TextBox_NAIAT.Invoke(New Callback(AddressOf UpdateUI), TextBox_NAIAT, rg5.Cells(i, 28).value)
                TextBox_AMP.Invoke(New Callback(AddressOf UpdateUI), TextBox_AMP, rg5.Cells(i, 29).value)
                TextBox_letterofwarning.Invoke(New Callback(AddressOf UpdateUI), TextBox_letterofwarning, rg5.Cells(i, 31).value)
                TextBox_Comments.Invoke(New Callback(AddressOf UpdateUI), TextBox_Comments, rg5.Cells(i, 32).value)
                TextBox_insp_type.Invoke(New Callback(AddressOf UpdateUI), TextBox_insp_type, rg5.Cells(i, 17).value)
                row = row + 1
                Exit For
            End If
        Next
    End Sub

Private Sub Rangeloops()

Clearalltextbox()   'Make sure all fields are empty while switching form child to child
TextBox_selectednodes.Text = TreeView_Insp_Records.SelectedNode.Text
Ping_network()
        
'All my loops that you've seen before

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

Alright so here is my code now. EVERYTHING is working fine! I would have never made it that far without your help. Thank you.
When I move in the Treeview from one node to another, the textbox are filled in a more dynamic way. Its much better.
Tho I still need to ask, would it be better to make a Thread or delegate with one loop in each ? Or having 5 would be consider a bit overkill for this?
And finaly, should I make a Thread for clearing all textbox when it comes to clear all their content?
When I move from one childnodes to another in the Treeview ( this is when all textbox = "" ), I can feel like it's still a bit demanding for the program to keep up.
But other then that, I feel I'm almost done.
 

freddyboy

Active member
Joined
Jun 18, 2020
Messages
27
Programming Experience
Beginner
i have seen post 11. I did not ignored it. I tried but im confused on where and what to change exacly. It doesnt take much as you can see. Could you just show me an exemple with my code in my last post by applying to rg1 ?
 

JohnH

VB.NET Forum Moderator
Staff member
Joined
Dec 17, 2005
Messages
15,431
Location
Norway
Programming Experience
10+
I did in post 11. I showed you how to get the values array from rg1, and I showed you how to get a value from the values array. There's nothing more to it. Instead of rg1.Cells(i, 31).value do values(i, 31)
 

Sheepings

Senior Programmer
Staff member
Joined
Mar 7, 2014
Messages
131
Location
UK
Programming Experience
10+
should I make a Thread for clearing all textbox when it comes to clear all their content?
Yes you should. Because you shouldn't be updating your UI from any method running on your UI thread. That's what makes your app become unresponsive. But I'm afraid threading only takes you so far. It's just the correct way to work with UI controls from another thread or task. Ideally, you should be using a model of data (a class) to track all your objects on your UI and work with that model. It would be your model which would keep your UI updated....anyway, the way you are doing it now is fine for now. After-all, you're still only learning, and I don't want to throw to much at you, as that would just be overwhelming.

Threading is only one small step for added improvements. Real performance will only happen when you start tweaking your code to reduce execution time. Now you know how you should be updating your UI, don't go back to the lazy way of doing it by executing code in your UI thread. This is when you develop a better understanding of code in general and learn the mathematical equations for finding the fastest running syntax...(it comes with experience) But its also important that you understand what the code I gave you does and why it helps. It's discouraging to help you any further because you're not asking how it works or why. When you say :
would it be better to make a Thread or delegate with one loop in each ?
It's important to know what each one does and why one of those is dependent on the other (thread, and delegate). Your misunderstanding becomes clear when you add the word "or" in there.

I see a lot of room for improvement in your above code. To bring post 11 forward for convenience, so we don't have to keep bouncing between pages and to recoup on what was said. What exactly do you not understand here :
Getting values from a sheet range once as array is as fast as getting a single cell value, so if you get 20 values from a range speed can be improved 20 times... or so :)
VB.NET:
Dim values As Object(,) = rg1.Value
Then you can get each one value from array:
VB.NET:
Dim value = values(row, column)
Have you tried to adapt what was being described? How many times does the below loop cycle compared to picking a one time variable object form an array?
For i = 1 To rg1.Rows.Count
 

freddyboy

Active member
Joined
Jun 18, 2020
Messages
27
Programming Experience
Beginner
I'm confuse as do I need to make those changes in the " Private Sub Rangeloops() " where all my orginal loops are, or the " Private Sub ExecuteWork(byval value as string) " which is the thread, or both of them ?

I've adapted like this to try but I don't see any significant changes in term of speed, it does seem to behave differently when it fills the textbox but other than filling my code of Dim and making it look heavier, I don't think it's improving it?

VB.NET:
 Private Sub Rangeloops()

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

        Dim row As Long
        row = 1
        Dim Inspfred As Worksheet
        Dim Inspchris As Worksheet
        Dim Inspjr As Worksheet
        Dim Inspluc As Worksheet
        Dim Inspted As Worksheet
        Inspfred = Form1.xlWorkBook.Sheets("Inspfred")
        Inspchris = Form1.xlWorkBook.Sheets("Inspchris")
        Inspjr = Form1.xlWorkBook.Sheets("Inspjr")
        Inspluc = Form1.xlWorkBook.Sheets("Inspluc")
        Inspted = Form1.xlWorkBook.Sheets("Inspted")
        Dim rg1 As Range 'Range pour fred
        Dim rg2 As Range 'Range pour chris
        Dim rg3 As Range 'Range pour jr
        Dim rg4 As Range 'Range pour luc
        Dim rg5 As Range 'Range pour ted
        rg1 = Inspfred.Range("C1").CurrentRegion
        rg2 = Inspchris.Range("C1").CurrentRegion
        rg3 = Inspjr.Range("C1").CurrentRegion
        rg4 = Inspluc.Range("C1").CurrentRegion
        rg5 = Inspted.Range("C1").CurrentRegion
       
         Dim i As Long
     
        For i = 1 To rg1.Rows.Count 'Range for Inspfred

            Dim RDIMS_fred As Object(,) = rg1.Value
            Dim RSIG_fred As Object(,) = rg1.Value
            Dim LocationNAME_fred As Object(,) = rg1.Value
            Dim Type_fred As Object(,) = rg1.Value
            Dim ABC_fred As Object(,) = rg1.Value
            Dim Railway_fred As Object(,) = rg1.Value
            Dim issue_fred As Object(,) = rg1.Value
            Dim InspFROM_fred As Object(,) = rg1.Value
            Dim InspTO_fred As Object(,) = rg1.Value
            Dim Total_Insp_fred As Object(,) = rg1.Value
            Dim Date_fred As Object(,) = rg1.Value
            Dim Year_fred As Object(,) = rg1.Value
            Dim Lead_RSI_fred As Object(,) = rg1.Value
            Dim RSI2_fred As Object(,) = rg1.Value
            Dim Letterofconcern_fred As Object(,) = rg1.Value
            Dim Prenotice_fred As Object(,) = rg1.Value
            Dim notice_order_fred As Object(,) = rg1.Value
            Dim NAIAT_fred As Object(,) = rg1.Value
            Dim AMP_fred As Object(,) = rg1.Value
            Dim letterofwarning_fred As Object(,) = rg1.Value
            Dim Comments_fred As Object(,) = rg1.Value
            Dim insp_type_fred As Object(,) = rg1.Value
       
            Dim RDIMS = RDIMS_fred(i, 19)
            Dim RSIG = RSIG_fred(i, 18)
            Dim LocationNAME = LocationNAME_fred(i, 4)
            Dim Type = Type_fred(i, 6)
            Dim ABC = ABC_fred(i, 7)
            Dim Railway = Railway_fred(i, 5)
            Dim issue = issue_fred(i, 8)
            Dim InspFROM = InspFROM_fred(i, 9)
            Dim InspTO = InspTO_fred(i, 10)
            Dim Total_Insp = Total_Insp_fred(i, 11)
            Dim freddate = Date_fred(i, 12)
            Dim Year = Year_fred(i, 2)
            Dim Lead_RSI = Lead_RSI_fred(i, 15)
            Dim RSI2 = RSI2_fred(i, 16)
            Dim Letterofconcern = Letterofconcern_fred(i, 21)
            Dim Prenotice = Prenotice_fred(i, 23)
            Dim notice_order = notice_order_fred(i, 26)
            Dim NAIAT = NAIAT_fred(i, 28)
            Dim AMP = AMP_fred(i, 29)
            Dim letterofwarning = letterofwarning_fred(i, 31)
            Dim Comments = Comments_fred(i, 32)
            Dim insp_type = insp_type_fred(i, 17)

If rg1.Cells(i, 3).value = TreeView_Insp_Records.SelectedNode.Text Then

                TextBox_RDIMS.Text = RDIMS
                TextBox_RSIG.Text = RSIG
                TextBox_LocationNAME.Text = LocationNAME
                TextBox_Type.Text = Type
                TextBox_ABC.Text = ABC
                TextBox_Railway.Text = Railway
                TextBox_issue.Text = issue
                TextBox_InspFROM.Text = InspFROM
                TextBox_InspTO.Text = InspTO
                TextBox_Total_Insp.Text = Total_Insp
                TextBox_Date.Text = freddate
                TextBox_Year.Text = Year
                TextBox_Lead_RSI.Text = Lead_RSI
                TextBox_2nd_RSI.Text = RSI2
                TextBox_Letterofconcern.Text = Letterofconcern
                TextBox_Prenotice.Text = Prenotice
                TextBox_notice_order.Text = notice_order
                TextBox_NAIAT.Text = NAIAT
                TextBox_AMP.Text = AMP
                TextBox_letterofwarning.Text = letterofwarning
                TextBox_Comments.Text = Comments
                TextBox_insp_type.Text = insp_type
                row = row + 1
                Exit For
            End If
        Next
       
      
 For i = 1 To rg2.Rows.Count 'Range for Inspchris

Dim RDIMS_chris As Object(,) = rg2.Value
Dim RSIG_chris As Object(,) = rg2.Value
Dim LocationNAME_chris As Object(,) = rg2.Value
Dim Type_chris As Object(,) = rg2.Value
Dim ABC_chris As Object(,) = rg2.Value
Dim Railway_chris As Object(,) = rg2.Value
Dim issue_chris As Object(,) = rg2.Value
Dim InspFROM_chris As Object(,) = rg2.Value
Dim InspTO_chris As Object(,) = rg2.Value
Dim Total_Insp_chris As Object(,) = rg2.Value
Dim Date_chris As Object(,) = rg2.Value
Dim Year_chris As Object(,) = rg2.Value
Dim Lead_RSI_chris As Object(,) = rg2.Value
Dim RSI2_chris As Object(,) = rg2.Value
Dim Letterofconcern_chris As Object(,) = rg2.Value
Dim Prenotice_chris As Object(,) = rg2.Value
Dim notice_order_chris As Object(,) = rg2.Value
Dim NAIAT_chris As Object(,) = rg2.Value
Dim AMP_chris As Object(,) = rg2.Value
Dim letterofwarning_chris As Object(,) = rg2.Value
Dim Comments_chris As Object(,) = rg2.Value
Dim insp_type_chris As Object(,) = rg2.Value
Dim RDIMS = RDIMS_chris(i, 19)
Dim RSIG = RSIG_chris(i, 18)
Dim LocationNAME = LocationNAME_chris(i, 4)

Dim Type = Type_chris(i, 6)
Dim ABC = ABC_chris(i, 7)
Dim Railway = Railway_chris(i, 5)
Dim issue = issue_chris(i, 8)
Dim InspFROM = InspFROM_chris(i, 9)
Dim InspTO = InspTO_chris(i, 10)
Dim Total_Insp = Total_Insp_chris(i, 11)
Dim freddate = Date_chris(i, 12)
Dim Year = Year_chris(i, 2)
Dim Lead_RSI = Lead_RSI_chris(i, 15)
Dim RSI2 = RSI2_chris(i, 16)
Dim Letterofconcern = Letterofconcern_chris(i, 21)
Dim Prenotice = Prenotice_chris(i, 23)
Dim notice_order = notice_order_chris(i, 26)
Dim NAIAT = NAIAT_chris(i, 28)
Dim AMP = AMP_chris(i, 29)
Dim letterofwarning = letterofwarning_chris(i, 31)
Dim Comments = Comments_chris(i, 32)
Dim insp_type = insp_type_chris(i, 17)

            If rg2.Cells(i, 3).value = TreeView_Insp_Records.SelectedNode.Text Then 

TextBox_RDIMS.Text = RDIMS
TextBox_RSIG.Text = RSIG
TextBox_LocationNAME.Text = LocationNAME
TextBox_Type.Text = Type
TextBox_ABC.Text = ABC
TextBox_Railway.Text = Railway
TextBox_issue.Text = issue
TextBox_InspFROM.Text = InspFROM
TextBox_InspTO.Text = InspTO
TextBox_Total_Insp.Text = Total_Insp
TextBox_Date.Text = freddate
TextBox_Year.Text = Year
TextBox_Lead_RSI.Text = Lead_RSI
TextBox_2nd_RSI.Text = RSI2
TextBox_Letterofconcern.Text = Letterofconcern
TextBox_Prenotice.Text = Prenotice
TextBox_notice_order.Text = notice_order
TextBox_NAIAT.Text = NAIAT
TextBox_AMP.Text = AMP
TextBox_letterofwarning.Text = letterofwarning
TextBox_Comments.Text = Comments
TextBox_insp_type.Text = insp_type

Exit For
End If
Next
 
Last edited:

JohnH

VB.NET Forum Moderator
Staff member
Joined
Dec 17, 2005
Messages
15,431
Location
Norway
Programming Experience
10+
No no no.
Dim values As Object(,) = rg1.Value
That's ALL values in the range. You get this once from spreadsheet for each of your CurrentRegions.

After that you can get each value from the array and put it into your controls.
 

freddyboy

Active member
Joined
Jun 18, 2020
Messages
27
Programming Experience
Beginner
Good coding comes with experience. Experience, well that comes with bad coding :p
Hope this is right:

VB.NET:
 Dim i As Long

        For i = 1 To rg1.Rows.Count 'Range for Inspfred

            Dim values As Object(,) = rg1.Value

            If rg1.Cells(i, 3).value = TreeView_Insp_Records.SelectedNode.Text Then ' Si les valeurs colonne C = node sélectionner dans treeview
                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)
                row = row + 1
                Exit For
            End If
        Next

        For i = 1 To rg2.Rows.Count 'Range for Inspchris

            Dim values As Object(,) = rg2.Value

            If rg2.Cells(i, 3).value = TreeView_Insp_Records.SelectedNode.Text Then ' Si les valeurs colonne C = node sélectionner dans treeview
                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)
                Exit For
            End If
        Next

        For i = 1 To rg3.Rows.Count 'Range for Inspjr

            Dim values As Object(,) = rg3.Value

            If rg3.Cells(i, 3).value = TreeView_Insp_Records.SelectedNode.Text Then ' Si les valeurs colonne C = node sélectionner dans treeview
                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)
                Exit For
            End If
        Next

        For i = 1 To rg4.Rows.Count 'Range for Inspluc

            Dim values As Object(,) = rg4.Value

            If rg4.Cells(i, 3).value = TreeView_Insp_Records.SelectedNode.Text Then ' Si les valeurs colonne C = node sélectionner dans treeview
                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)
                Exit For
            End If
        Next

        For i = 1 To rg5.Rows.Count 'Range for Inspted

            Dim values As Object(,) = rg5.Value

            If rg5.Cells(i, 3).value = TreeView_Insp_Records.SelectedNode.Text Then ' Si les valeurs colonne C = node sélectionner dans treeview
                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)
                Exit For
            End If
 

JohnH

VB.NET Forum Moderator
Staff member
Joined
Dec 17, 2005
Messages
15,431
Location
Norway
Programming Experience
10+
No, you still get values from sheet many times inside the loop. It can also be greatly improved by using the array in lookup:
VB.NET:
Dim values As Object(,) = rg1.Value
For i = 1 To values.GetUpperBound(0) 'rows
    If values(i, 3) = TreeView_Insp_Records.SelectedNode.Text Then
        TextBox_RDIMS.Text = values(i, 19)
Notice rg1.value is the last time to talk to sheet, inside loop just use the array.
 

freddyboy

Active member
Joined
Jun 18, 2020
Messages
27
Programming Experience
Beginner
I got rid of all the other loops and kept:

VB.NET:
 Private Sub Rangeloops()

        Clearalltextbox()   'Make sure all fields are empty while switching form child to child
        TextBox_selectednodes.Text = TreeView_Insp_Records.SelectedNode.Text
        Ping_network()
        
         Dim row As Long
        row = 1
        Dim Inspfred As Worksheet
         Inspfred = Form1.xlWorkBook.Sheets("Inspfred")
          Dim rg1 As Range 'Range pour fred
           rg1 = Inspfred.Range("C1").CurrentRegion
          
           Dim i As Long

        Dim values As Object(,) = rg1.Value

        For i = 1 To values.GetUpperBound(0) 'rows

            If values(i, 3) = TreeView_Insp_Records.SelectedNode.Text Then ' Si les valeurs colonne C = node sélectionner dans treeview
                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)
                row = row + 1
                Exit For
            End If
        Next
            End Select
    End Sub
 

freddyboy

Active member
Joined
Jun 18, 2020
Messages
27
Programming Experience
Beginner
I am trying to adjust the thread and I'm having a cross thread error with line 19

VB.NET:
Private Sub ExecuteWork(ByVal value As String)

        Dim row As Long
        row = 1
        Dim Inspfred As Worksheet
        Inspfred = Form1.xlWorkBook.Sheets("Inspfred") 
        Dim rg1 As Range 'Range pour fred
        rg1 = Inspfred.Range("C1").CurrentRegion
        
          Dim s As String = "Testing Worker Method"
          
          Dim i as long
          
           Dim values As Object(,) = rg1.Value
                    
          For i = 1 To values.GetUpperBound(0) 'rows
           Debug.Write(s) 'This is running on non-ui thread
            
            If values(i, 3) = TreeView_Insp_Records.SelectedNode.Text Then
               ' If rg1.Cells(i, 3).value = 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))
                    row = row + 1
                    Exit For
                    '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
 

Sheepings

Senior Programmer
Staff member
Joined
Mar 7, 2014
Messages
131
Location
UK
Programming Experience
10+
If you are following the advice i am giving you, then use
value instead of : TreeView_Insp_Records.SelectedNode.Text

Your biggest problem is your lack of understanding of the code you already have.
 

Sheepings

Senior Programmer
Staff member
Joined
Mar 7, 2014
Messages
131
Location
UK
Programming Experience
10+
You're close but still missing the point JohnH is making. Since JohnH already answered the bit about the array.

I'll conclude with a simple diagram :
ThreadUI.png
Your UI has its own thread. When you do "work" on that thread, including changing your UI values from within the UI thread, you are deadlocking the UI thread into a state where it can't respond to new requests, or user input because that thread is already occupied/BUSY with the work you told it to do. So unless you setup a new thread from your UI thread, start that new thread, and execute a method from that new thread which involves updating controls on your UI, then you will need to call invoke on every control which requires updating. The Invoker takes an action or delegate, and in our case it was a delegate. That delegate takes two parameters. One for the control being invoked, and one for the value which is the last selected node. The update UI method is already able to communicate with the UI controls through the delegation we just did. Essentially, the delegate lets us cross-talk to our UI through the UI update method. At no point have we returned to the UI thread until the update has completed.

Being armed with this much, can you now understand why you can't call TreeView_Insp_Records.SelectedNode.Text directly from the working thread? Given this much information, you should also know where and when to place new threads when you want to update your UI. Where are you updating your UI/Controls from? Is that specific method running independent VIA a new thread to your UI or on your UI thread? Because unless you start a new thread, and update your UI from the new thread that executed whatever method that updates your controls, you are likely still running it on your UI thread.
 

Sheepings

Senior Programmer
Staff member
Joined
Mar 7, 2014
Messages
131
Location
UK
Programming Experience
10+

freddyboy

Active member
Joined
Jun 18, 2020
Messages
27
Programming Experience
Beginner
Good Sir,

Please note that this is not my first language to start with. It adds in the complexity of things. Also, "Threads" are completely new to me and I have to admit that just reading what it does is making me dizzy. It has nothing to do with the way you are explaining it. You are very good at it. You can keep telling me that I do not understand what I have right under my nose as much as you want... If it pleases you... Or to tell me to look up because it was already answered. I'm just trying my best with what I know so far, or what I was able to understand for a father of 4 who tries to focus on one thing at the time. I was able to code the rest of my program by searching the web and pasting stuff together. No, I do not undestand all of it. I am trying, I already know much more than I did 2 weeks ago. I like learning stuff, especially coding. But I don't expect to become a pro anytime soon. I am just a track inspector who is trying to make a small handy program for my work. You can enjoy flying without having to become a pilote!

Now I have to admit, I am a bit lost with all the information that was given to me.
I think that my "Private Sub Rangeloops()" is ok (now that it only has 1 loop instead of 5), but I don't know how to apply all the changes in the " Private Sub ExecuteWork(ByVal value As String)" in order to have only one loop too without getting lost.

I need to catch my breath.
 

Sheepings

Senior Programmer
Staff member
Joined
Mar 7, 2014
Messages
131
Location
UK
Programming Experience
10+
You seem to be getting a little frustrated. Don't kick yourself. You're getting there, so just relax. Some light reading on threads might help : Thread Class (System.Threading) You can find additional info on their docs from that page covering this subject.

You had on post 32 :
VB.NET:
If rg1.Cells(i, 3).value = value Then
Then you made the mistake of changing it to :
VB.NET:
If values(i, 3) = TreeView_Insp_Records.SelectedNode.Text Then
You can't access : TreeView_Insp_Records.SelectedNode.Text because it was created by your UI thread.
The parameter in : Private Sub ExecuteWork(ByVal value As String) which is "value", is the same as TreeView_Insp_Records.SelectedNode.Text because we are passing this to the thread when we select a new node. So don't call : TreeView_Insp_Records.SelectedNode.Text and use the parameter ( "value" ) instead.

As for : Private Sub Rangeloops() - you are also updating multiple controls, and again in your Clearalltextbox() method. These should all by right be updated with an entirely new thread. But before you go worrying about them, first work on getting your current method working : ExecuteWork
 

freddyboy

Active member
Joined
Jun 18, 2020
Messages
27
Programming Experience
Beginner
This is where I am :

VB.NET:
Private Sub ExecuteWork(ByVal value As String)
        Dim row As Long
        row = 1
        Dim Inspfred As Worksheet
Dim Inspchris As Worksheet
Dim Inspjr As Worksheet
Dim Inspluc As Worksheet
Dim Inspted As Worksheet
Inspfred = Form1.xlWorkBook.Sheets("Inspfred")
Inspchris = Form1.xlWorkBook.Sheets("Inspchris")
Inspjr = Form1.xlWorkBook.Sheets("Inspjr")
Inspluc = Form1.xlWorkBook.Sheets("Inspluc")
Inspted = Form1.xlWorkBook.Sheets("Inspted")
Dim rg1 As Range 'Range pour fred
Dim rg2 As Range 'Range pour chris
Dim rg3 As Range 'Range pour jr
Dim rg4 As Range 'Range pour luc
Dim rg5 As Range 'Range pour ted
rg1 = Inspfred.Range("C1").CurrentRegion
rg2 = Inspchris.Range("C1").CurrentRegion
rg3 = Inspjr.Range("C1").CurrentRegion
rg4 = Inspluc.Range("C1").CurrentRegion
rg5 = Inspted.Range("C1").CurrentRegion

  Dim s As String = "Testing Worker Method"
        For i = 1 To rg1.Rows.Count
 Debug.Write(s) 'This is running on non-ui thread
 Dim values As Object(,) = rg1.Value
            If rg1.Cells(i, 3).value = 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))
                row = row + 1
                Exit For
                '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

        For i = 1 To rg2.Rows.Count 'Range pour Inspchris

            Dim values As Object(,) = rg2.Value

            If rg2.Cells(i, 3).value = 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))
                row = row + 1
                Exit For
            End If
        Next

        For i = 1 To rg3.Rows.Count 'Range pour Inspjr
            If rg3.Cells(i, 3).value = value Then

                Dim values As Object(,) = rg3.Value

                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))
                row = row + 1
                Exit For
            End If
        Next

        For i = 1 To rg4.Rows.Count 'Range pour Inspluc
            If rg4.Cells(i, 3).value = value Then

                Dim values As Object(,) = rg4.Value

                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))
                row = row + 1
                Exit For
            End If
        Next

        For i = 1 To rg5.Rows.Count 'Range pour Inspted
            If rg5.Cells(i, 3).value = value Then

                Dim values As Object(,) = rg5.Value

                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))
                row = row + 1
                Exit For
            End If
        Next
    End Sub
 

JohnH

VB.NET Forum Moderator
Staff member
Joined
Dec 17, 2005
Messages
15,431
Location
Norway
Programming Experience
10+
VB.NET:
Dim values As Object(,) = rg1.Value
For i = 1 To values.GetUpperBound(0) 'rows
    If values(i, 3) = value Then
        'update UI
 

freddyboy

Active member
Joined
Jun 18, 2020
Messages
27
Programming Experience
Beginner
VB.NET:
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))
row = row + 1
Exit For
'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
        For i = 1 To rg2.Rows.Count 'Range pour Inspchris
            ' Dim values As Object(,) = rg2.Value
            If rg2.Cells(i, 3).value = 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))
row = row + 1
Exit For
End If
        Next
        For i = 1 To rg3.Rows.Count 'Range pour Inspjr
            If rg3.Cells(i, 3).value = value Then
                '  Dim values As Object(,) = rg3.Value
                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))
row = row + 1
Exit For
End If
        Next
        For i = 1 To rg4.Rows.Count 'Range pour Inspluc
            If rg4.Cells(i, 3).value = value Then
                '  Dim values As Object(,) = rg4.Value
                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))
row = row + 1
Exit For
End If
        Next
        For i = 1 To rg5.Rows.Count 'Range pour Inspted
            If rg5.Cells(i, 3).value = value Then
                '   Dim values As Object(,) = rg5.Value
                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))
row = row + 1
Exit For
End If
Next
End Sub
 
Top Bottom