Referring to form objects within a subroutine?

FuturShoc

Active member
Joined
Jul 28, 2006
Messages
27
Location
Hot Springs, Arkansas
Programming Experience
3-5
I'm new to Windows development and .NET, but not completely new to this sort of programming and IDE.

I've written a subroutine and need to alter a form label within that subroutine. Thing is, whenever I try and write this, Visual studio flags me that it doesn't understand (ie. the blue squiggly line under my code line.)

So, I'm certain my label reference is out of scope. I need to be more explicit when I reference this label object within the subroutine.

I'm sure the answer is very simple, but can't seem to come up with the right question when I search forums/Google.
 
Is the sub in the same form that you are trying to manipulate? If not, where is it? What does the sub look like?

-tg
 
I should have said so in the first place. D'oh. Be gentle, my VB.net ego is fragile. lol

The subroutine is in its own module. I've been storing my own custom subroutines in a file called simply, "Subroutines.vb".

Here is the sub.
Line 6 is where i wanted to display the workstation name (in this case "VMBLAB9902") in a label object to reflect progress of the subroutine.

VB.NET:
Public Sub replace_store_num_in_custom_lists(ByVal oldStore, ByVal newStore)
        Dim allUsers() As String = {"VLMLAB9902"}
        Dim item As String
        For Each item In allUsers
            Dim myCustomLists() As String

            myCustomLists = Directory.GetFiles("\\" & item & "\d$\content\custom list\")
            Dim list As String
            For Each list In myCustomLists
                Dim Reader As StreamReader = File.OpenText(list)
                Dim listContents As String
                Try
                    listContents = Reader.ReadToEnd
                    If listContents.IndexOf(oldStore) > -1 Then
                        Dim newContents As String
                        If newStore = "" Then
                            newContents = listContents.Replace("<TreeNodeData><Text>" & oldStore & "</Text><ImageIndex>0</ImageIndex><SelectedImageIndex>0</SelectedImageIndex><Checked>false</Checked><Expanded>false</Expanded></TreeNodeData>", "")
                        Else
                            newContents = listContents.Replace("<TreeNodeData><Text>" & oldStore & "</Text><ImageIndex>0</ImageIndex><SelectedImageIndex>0</SelectedImageIndex><Checked>false</Checked><Expanded>false</Expanded></TreeNodeData>", "<TreeNodeData><Text>" & newStore & "</Text><ImageIndex>0</ImageIndex><SelectedImageIndex>0</SelectedImageIndex><Checked>false</Checked><Expanded>false</Expanded></TreeNodeData>")
                        End If
                        ' Write new XML contents to the custom list and replace the old contents
                        Reader.Close()
                        Dim writer = New StreamWriter(list)
                        writer.write(newContents)
                        writer.close()
                    End If
                    Reader.Close()
                Finally
                    Reader.Close()
                End Try
            Next
        Next
    End Sub
 
Bottom line, the sub knows nothing about your form.... you could have instanciated 15 copies of the same form... it would have no idea which one to update.

You could pass in a reference to the form..... then use that to update the label... or make it a part of the form itself in the first place.

-tg
 
Back
Top