Solved

Help with passing string variable to For Next Loop

Posted on 2013-11-04
5
244 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Secure Your Active Directory - April 20, 2017

Active Directory plays a critical role in your company’s IT infrastructure and keeping it secure in today’s hacker-infested world is a must.
Microsoft published 300+ pages of guidance, but who has the time, money, and resources to implement? Register now to find an easier way.

Question has a verified solution.

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

Suggested Solutions

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
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 …
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…

726 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