Solved

Help with passing string variable to For Next Loop

Posted on 2013-11-04
5
236 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
Comment Utility
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
Comment Utility
Thanks, will try it and get back toy you.
0
 

Author Comment

by:vcharles
Comment Utility
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
Comment Utility
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
Comment Utility
Thank You.
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Suggested Solutions

Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

744 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now