Solved

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

Posted on 2012-12-23
2
394 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

863 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

26 Experts available now in Live!

Get 1:1 Help Now