?
Solved

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

Posted on 2012-12-23
2
Medium Priority
?
399 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
[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
2 Comments
 
LVL 1

Accepted Solution

by:
igordevelop earned 2000 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Suggested Courses

800 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