I'm not sure I understand what 'The function on form1 needs a reference to
the current form2' means.
Ok, here is a portion of my code - The last if/else statement on Form1 is
where I assign a value to the listbox on Form2:
FORM2---------------------------------------
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button2.Click
Dim searchButton As String, textBoxString As String, deleteRecord As
Boolean
deleteRecord = True
searchButton = "SearchButton"
textBoxString = txtName.Text.ToUpper
Form1.FindMatch(searchButton, textBoxString, True)
End Sub
FORM1---------------------------------------
Public Function FindMatch(ByVal whatButton As String, Optional ByVal
SearchPar As String = "", Optional ByVal deleteRecord As Boolean = False)
'call sub to get record location.
openDatForRecordLocation()
' Clear the contents of the text box
TextBox1.Text = ""
' Open the file to read from and assign each line to string array called
readText()
Dim readText() As String
If closeApp = False Then
readText = File.ReadAllLines(pathToRecords)
'Use lineOfText in the For Each to iterate thru the string array
readText assigning matches to lineOfText.
Dim lineOfText As String
'matchesFound will be used to store matching results to display in
results text box or populate the combo box on form open
Dim matchesFound As String = ""
'countResults will be used to track the number of results found
Dim CountResults As Integer
'countRecords will be used to track the number of records in the
file
Dim countRecords As Integer
'Use a boolean variable to determine whether or not to process the
rest of the function if
'whatButton is equal to FormOpenCombo
Dim finishFunction As Boolean
For Each lineOfText In readText
'Count number of total records in the file
countRecords += 1
If lineOfText.ToUpper.Contains(SearchPar) Then
If Not lineOfText.StartsWith("[") And Not
lineOfText.EndsWith("]") Then
'Count the number of results found
CountResults += 1
'Sort the array
Array.Sort(readText)
If deleteRecord = False Then
' if not deleting a record do this
'For every match found, assign to matchesFound
variable with a carriage return.
matchesFound += lineOfText & vbCrLf
finishFunction = True
Else
'HERE IS WHERE I AM HAVING THE PROBLEM
'If deleting a record then do this
Form2.lstResults.Items.Add(lineOfText)
finishFunction = False
End If
End If
If i add change the above to this:
Form2.lstResults.Items.Add(lineOfText)
Form2.lstResults.Show()
finishFunction = False
Form2 will reopen with the original behind it, showing lstResults listbox
with the value of lineOfText.
Kerry Moorman said:
Rob,
The function on form1 needs a reference to the current form2.
I suspect that the function is creating a new instance of form2 and not
using the current instance.
You might want to post your code if you can't get it working.
Kerry Moorman