Solved

Help with passing string variable to For Next Loop

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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

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…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.

810 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