Solved

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

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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
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.
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.
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

809 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