Hi,
got a little problem with XDocument. I use XDocument to get a value from an XML document. Everything is working fine but I get an error (Object reference not set to an instance of an object) when I try to debug the project...but it's working when I click next. This is my code:
I do assign the value from a combobox and I can display cbt so the value seems to be assigned correctly
Then I start the sub with XDocument
The error (Object ...) is pointing to "Dim ssk = correspondingValues.SpezSchnittkraft" but yeah, when I click on next and ignore the error everything is working
got a little problem with XDocument. I use XDocument to get a value from an XML document. Everything is working fine but I get an error (Object reference not set to an instance of an object) when I try to debug the project...but it's working when I click next. This is my code:
Code:
Dim cbt As String
Code:
cbt = ComboBox1.Text
Code:
Dim materialXDoc = XDocument.Load("C:\Test\Material.xml")
Dim groupXDoc = XDocument.Load("C:\Test\Zerspanungsgruppen.xml")
'Hard coded in this example you said you get it from a combobox selection
Dim searchValue = cbt
'Search for a specific name in materialXDoc and get the value of the Zerpspanungsgruppe node
'Will return Nothing if the search value is not found
Dim searchedgroup = (From n In materialXDoc...<Material>
Where n.@name = searchValue
Select n.<Zerspanungsgruppe>.Value).SingleOrDefault()
'Search the Zerpspanungsgruppe.xml file and return the spezSchnittkraft and AnstiegswerMc node values
'Will return nothing if the search value is not found
Dim correspondingValues = (From n In groupXDoc...<Zerspanungsgruppe>
Where n.@name = searchedgroup
Select New With {.SpezSchnittkraft = CInt(n.<spezSchnittkraft>.Value), .AnstiegswertMc = CDbl(n.<AnstiegswertMc>.Value)}).SingleOrDefault()
Dim ssk = correspondingValues.SpezSchnittkraft
Dim amc = correspondingValues.AnstiegswertMc
Label3.Text = ssk
Label4.Text = amc