在不同的线程中使用文本框文本填充数组

时间:2017-01-28 12:13:07

标签: vb.net multithreading

我是vb.net和多线程的新手。我正在尝试使用文本框中位于不同线程中的所有行填充位于模块中的数组。

开始一个新主题>调用Extract_All_0>填充BaseArray>运行剩下的代码。

    Imports System.Threading

    Public Class Form1

    Private Sub Button35_Click(sender As Object, e As EventArgs) Handles Button35.Click

            'Call Extract_All_0
            TextBox19.ResetText
            Dim Thread_Extract_All As New System.Threading.Thread(AddressOfExtract_All_0)

            Thread_Extract_All.IsBackground = True
            Thread_Extract_All.Start()

        End Sub

    End Class


   Option Explicit On


Imports VBScript_RegExp_55

Module ExtractAll

    Dim BaseToResult()
    Dim BaseArray()
    Dim Result_array(0) As String

    Sub Extract_All_0()

        Dim ResultVal As String = vbNullString


        Dim Regex As RegExp
        Dim Matches As MatchCollection
        Dim Match As Match

        Dim SearchPattern

        Dim Q As Long, w As Long, e As Long, r As Long, i As Long

        Dim lastRow As Long



        On Error GoTo ERR_HANDLER


        If Form1.TextBox21.Text <> vbNullString Then
            ReDim BaseArray(Form1.TextBox21.Lines.Count - 1)
            BaseArray = Form1.TextBox21.Lines

        Else
            MsgBox("No source data provided. Provide source data and try again.", vbCritical, "Error Manager")
            GoTo exit1
        End If


        If Form1.TextBox20.Text <> vbNullString Then
            Call Loadpatterns_Searchwhat_EA()
        Else
            MsgBox("Patterns not provided. Provide patterns and try again.", vbCritical, "Error Manager")
            GoTo exit1
        End If

        Form1.CheckBox6.Enabled = False
        Form1.CheckBox5.Enabled = False
        Form1.Button35.Enabled = False

        With Regex
                    .IgnoreCase = true
                    .Global = True
                    .Multiline = True
                End With


        On Error Resume Next


            ReDim Result_array(UBound(BaseArray))


        Regex = New RegExp

        For Q = LBound(BaseArray, 1) To UBound(BaseArray, 1)

            For w = LBound(BaseToResult) To UBound(BaseToResult)

                SearchPattern = BaseToResult(w)

                regex.Pattern = SearchPattern

                If Regex.Test(BaseArray(Q)) Then
                    Matches = Regex.Execute(BaseArray(Q))

                    For Each Match In Matches
                        If ResultVal = vbNullString Then
                            ResultVal = Match.Value
                        Else
                            ResultVal = ResultVal & vbTab & Match.Value
                        End If
                    Next
                End If

            Next w

            ResultVal = vbNullString

        Next Q

                   Form1.TextBox19.Text = Join(Result_array, vbNewLine)



        MsgBox("Extraction Complete", vbInformation, "ADMT")

        Exit Sub

    ERR_HANDLER:

        End Sub

    End Module

非常感谢任何帮助。感谢..

1 个答案:

答案 0 :(得分:0)

您的问题非常不明确,我会尝试填写我可以收集的内容可能是您的问题吗?

将“Sub Extract_All_0()”更改为“Sub Extract_All_0(strText As String)

在方法中 -

If Form1.TextBox21.Text <> vbNullString Then
        ReDim BaseArray(Form1.TextBox21.Lines.Count - 1)
''''  Can't read the the lines from the textbox evne when it contains text.
        strText= Form1.TextBox21.Linesenter code here

然后在button35 -

TextBox19.Text = Extract_All_0(strText)

看起来很草率,但很难弄清楚你想要达到的目标......