Solved

Help with passing string variable to For Next Loop

Posted on 2013-11-04
5
243 Views
Last Modified: 2013-11-08
Hi,

How do I modify the code in Part A below to pass values such as NSN, NSC to replace Row?  For example, when I press button_Row I use the code below in Part A, but when I press button_NSC, I would like to pass NSC to the code in part B where XXX is located

Part A

 Dim dtlink As New DataTable
        dtlink.Columns.Add("BM")
        Dim linker As XElement = XElement.Load(Application.StartupPath + "\Row.xml")
        For Each item As XElement In linker.Elements("Row")
            Dim NSNIDA As String = item.Element("BM").Value
            Dim drLink As DataRow = dtlink.NewRow()
            drLink("BM") = NSNIDA
            dtlink.Rows.Add(drLink)
        Next
        Dim DV As New DataView(dtlink, "BM not like ''", Nothing, DataViewRowState.CurrentRows)
        Dim FilteredDT As DataTable
        FilteredDT = DV.ToTable
        C1TrueDBGrid3.DataSource = dtlink.DefaultView.ToTable(True, New String() {"BM"})


Part B

Private Sub SearchFile()
 Dim dtlink As New DataTable
        dtlink.Columns.Add("XXX")
        Dim linker As XElement = XElement.Load(Application.StartupPath + "\XXX.xml")
        For Each item As XElement In linker.Elements("XXX")
            Dim NSNIDA As String = item.Element("XXX").Value
            Dim drLink As DataRow = dtlink.NewRow()
            drLink("XXX") = NSNIDA
            dtlink.Rows.Add(drLink)
        Next
        Dim DV As New DataView(dtlink, "XXX not like ''", Nothing, DataViewRowState.CurrentRows)
        Dim FilteredDT As DataTable
        FilteredDT = DV.ToTable
        C1TrueDBGrid3.DataSource = dtlink.DefaultView.ToTable(True, New String() {"BM"})
End Sub


Dim XXX as string

ButtonRow click event

XXX = "Row"
SearchFile()


ButtonNSC click event

XXX = "NSC"
SearchFile()


Thanks


Victor
0
Comment
Question by:vcharles
  • 3
  • 2
5 Comments
 
LVL 9

Accepted Solution

by:
dustock earned 500 total points
ID: 39622487
change your searchfile subroutine to accept a string.

Private Sub SearchFile(strValue As String)
    dtlink.Columns.Add(strValue)
End Sub

buttonNSC Click event
SeachFile("NSC")

Open in new window

0
 

Author Comment

by:vcharles
ID: 39631734
Thanks, will try it and get back toy you.
0
 

Author Comment

by:vcharles
ID: 39631999
Hi,

In two locations in my code below I also need to pass values of another variable, (i.e. YYY), how do I modify the code to also include values for YYY?

Private Sub SearchFile()
 Dim dtlink As New DataTable
        dtlink.Columns.Add("XXX")
        Dim linker As XElement = XElement.Load(Application.StartupPath + "\YYY.xml")
        For Each item As XElement In linker.Elements("YYY")
            Dim NSNIDA As String = item.Element("XXX").Value
            Dim drLink As DataRow = dtlink.NewRow()
            drLink("XXX") = NSNIDA
            dtlink.Rows.Add(drLink)
        Next
        Dim DV As New DataView(dtlink, "XXX not like ''", Nothing, DataViewRowState.CurrentRows)
        Dim FilteredDT As DataTable
        FilteredDT = DV.ToTable
        C1TrueDBGrid3.DataSource = dtlink.DefaultView.ToTable(True, New String() {XXX})
End Sub



Thanks,

Victor
0
 
LVL 9

Expert Comment

by:dustock
ID: 39633216
You can do the same thing.  You can pass multiple values into a subroutine

SearchFile(strValue1 As String, strValue2 As String)

SeachFile("XXX","YYY")

Open in new window

0
 

Author Closing Comment

by:vcharles
ID: 39633303
Thank You.
0

Featured Post

Webinar: Aligning, Automating, Winning

Join Dan Russo, Senior Manager of Operations Intelligence, for an in-depth discussion on how Dealertrack, leading provider of integrated digital solutions for the automotive industry, transformed their DevOps processes to increase collaboration and move with greater velocity.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes relatively difficult and non-obvious issues that are likely to arise when creating COM class in Visual Studio and deploying it by professional MSI-authoring tools. It is assumed that the reader is already familiar with the cla…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

832 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question