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
Thank you for the solution.
Victor