Solved

Help with passing string variable to For Next Loop

Posted on 2013-11-04
5
247 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

Turn Insights Into Action

You’ve already invested in ITSM tools, chat applications, automation utilities, and more. Fortify these solutions with intelligent communications so you can drive business processes forward.

With xMatters, you'll never miss a beat.

Question has a verified solution.

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

This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …

691 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