Solved

Help with passing Textbox value to a variable (VS 2010 Windows Application)

Posted on 2012-12-23
2
393 Views
Last Modified: 2012-12-24
hi,

I am using the code below to loop through multiple controls and pass text entered to a variable Txt and save  its values to the xml files. However, eventhough I have data in my Manufacturer Textbox, Txt is still empty. How do I fix this problem?

  Dim xyz() As String = New String() {"NSN", "Manufacturer", "Date"}
         
For i = 1 To 2
            Dim curXYZ = xyz(i)
            Dim MyFix As XDocument = XDocument.Load((Application.StartupPath + "\App_DataA\" & curXYZ & ".xml"))

            Dim xid As String
            xid = curXYZ & "_ID"
            Dim LargestFixID = (From el In MyFix.Descendants(curXYZ & "Table") Select CInt(el.<xid>.Value)).ToList
            LargestFixID.Sort()
            Dim xtable As String
            xtable = curXYZ & "Table"

            Dim ctrl As Control = Screen1.Controls("C1" & curXYZ)

            Dim Txt As String = Nothing
            If TypeOf (ctrl) Is ListBox Then
                Txt = CType(ctrl, ListBox).Text
            ElseIf TypeOf (ctrl) Is TextBox Then
                Txt = CType(ctrl, TextBox).Text
            End If

  Dim CheckForItemFix = (From el In MyFix.Descendants(xtable).Elements(curXYZ) Select el.Value).ToList
            'Check if value is already in xml files, if not add it to the xml files
            If Not CheckForItemFix.Contains(Txt) Then
                Dim xNew As XElement = New XElement(xtable)
                xNew.Add(New XElement(xid, (LargestFixID.Count() + 1)))
                xNew.Add(New XElement(curXYZ, Txt))
                MyFix.Root.Add(xNew)
                If i = 1 Then
                    MsgBox("TXT" & Txt)
                End If
                MyFix.Save((Application.StartupPath + "\App_DataA\" & curXYZ & ".xml"))
Next


Thanks,

Victor
0
Comment
Question by:vcharles
2 Comments
 
LVL 1

Accepted Solution

by:
igordevelop earned 500 total points
ID: 38718046
Hi,

If I understood you well, you have problem in this code:

Dim Txt As String = Nothing
            If TypeOf (ctrl) Is ListBox Then
                Txt = CType(ctrl, ListBox).Text
            ElseIf TypeOf (ctrl) Is TextBox Then
                Txt = CType(ctrl, TextBox).Text
            End If


You can try to access the control value by this way:

Dim Txt As String = Nothing
Dim ctrl As Control
        For Each ctrl In Me.Controls
            If TypeOf ctrl Is TextBox Then
                Txt = ctrl.Text
            If .......
        Next

Let me know if anything.

Regards,
Igor
0
 

Author Comment

by:vcharles
ID: 38718093
Hi,

Thank you  for the solution.

Victor
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

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…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

743 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

12 Experts available now in Live!

Get 1:1 Help Now