15,891,184 members
Sign in
Sign in
Email
Password
Forgot your password?
Sign in with
home
articles
Browse Topics
>
Latest Articles
Top Articles
Posting/Update Guidelines
Article Help Forum
Submit an article or tip
Import GitHub Project
Import your Blog
quick answers
Q&A
Ask a Question
View Unanswered Questions
View All Questions
View C# questions
View C++ questions
View Javascript questions
View Visual Basic questions
View Python questions
discussions
forums
CodeProject.AI Server
All Message Boards...
Application Lifecycle
>
Running a Business
Sales / Marketing
Collaboration / Beta Testing
Work Issues
Design and Architecture
Artificial Intelligence
ASP.NET
JavaScript
Internet of Things
C / C++ / MFC
>
ATL / WTL / STL
Managed C++/CLI
C#
Free Tools
Objective-C and Swift
Database
Hardware & Devices
>
System Admin
Hosting and Servers
Java
Linux Programming
Python
.NET (Core and Framework)
Android
iOS
Mobile
WPF
Visual Basic
Web Development
Site Bugs / Suggestions
Spam and Abuse Watch
features
features
Competitions
News
The Insider Newsletter
The Daily Build Newsletter
Newsletter archive
Surveys
CodeProject Stuff
community
lounge
Who's Who
Most Valuable Professionals
The Lounge
The CodeProject Blog
Where I Am: Member Photos
The Insider News
The Weird & The Wonderful
help
?
What is 'CodeProject'?
General FAQ
Ask a Question
Bugs and Suggestions
Article Help Forum
About Us
Search within:
Articles
Quick Answers
Messages
Comments by stopete82 (Top 25 by date)
stopete82
23-May-11 13:36pm
View
Thanks this is what I was looking for.
stopete82
13-May-11 14:43pm
View
Thanks for your help, this is the code that worked for me:
Private Sub TreeView1_AfterCheck(ByVal sender As System.Object, ByVal e As System.Windows.Forms.TreeViewEventArgs) Handles TreeView1.AfterCheck
Dim Pnode As TreeNode = e.Node
Dim PPnode As TreeNode = Pnode.Parent
If Pnode.Checked = True Then
While PPnode IsNot Nothing
RemoveHandler PPnode.TreeView.AfterCheck, AddressOf TreeView1_AfterCheck
PPnode.Checked = True
AddHandler PPnode.TreeView.AfterCheck, AddressOf TreeView1_AfterCheck
PPnode = PPnode.Parent
End While
Else
UncheckParent(PPnode)
End If
End Sub
stopete82
13-May-11 13:17pm
View
Syntax problem:
Dim nodes As TreeNodeCollection
For each node as treenode in nodes
If childrennode.checked = True Then
Parentnode.check = True
End If
Next
with this code I get childrennode not declared and parentnode change to Treenode.
stopete82
13-May-11 10:52am
View
Your totally right; thanks for the advice. This worked for me:
This code gave me the leader and the controlfields nodes:
For Each Record As XElement In doc...<record>
recordNode = TreeView1.Nodes.Add(Record.Name.ToString)
For Each Leader As XElement In Record...<leader>
leaderNode = recordNode.Nodes.Add(Leader.Name.ToString)
For Each Controlfield As XElement In Record...<controlfield>
controlfieldNode = recordNode.Nodes.Add(Controlfield.@tag.ToString)
Next
Next
Next
This code gave me the datafield nodes:
For Each Record As XElement In doc...<record>
recordNode = TreeView1.TopNode
For Each Datafield As XElement In Record...<datafield>
datafielNode = recordNode.Nodes.Add(Datafield.@tag.ToString)
For Each Subfield As XElement In Datafield...<subfield>
datafielNode.Nodes.Add(Subfield.@code.ToString)
Next
Next
Next
stopete82
11-May-11 13:05pm
View
Thanks Fabio V Silva for the great idea. This is the code that worked for me. Thanks again
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
For Each n As TreeNode In GetCheck(TreeView1.Nodes)
MsgBox(n.Text)
Next
End Sub
Private Function GetCheck(ByVal node As TreeNodeCollection) As List(Of TreeNode)
Dim lN As New List(Of TreeNode)
For Each n As TreeNode In node
If n.Checked Then lN.Add(n)
lN.AddRange(GetCheck(n.Nodes))
Next
Return lN
End Function
stopete82
11-May-11 12:04pm
View
Once my treeview1 gets loaded from the XML file; I checked some checks boxes and then click on the fallowing button so I can output the name of the node that was checked. However, I get empty strings. Appreciate your help.
Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
Dim list As New List(Of String)
GetSelectedNodes(TreeView1.Nodes, list)
End Sub
Private Sub GetSelectedNodes(ByVal nodes As TreeNodeCollection, ByRef list As List(Of String))
For Each node As TreeNode In nodes
If node.Checked Then list.Add(node.Name.ToString)
GetSelectedNodes(node.Nodes, list)
Next
' Loop through list with a for to loop.
Dim i As Integer
For i = 0 To list.Count - 1
MsgBox(list.Item(i))
Next i
End Sub
stopete82
6-May-11 15:02pm
View
I did and the button turned red "Reject solution". I hope that's correct.
stopete82
6-May-11 14:56pm
View
To accept the answer, do I click on the green "Accept Solution" button?
stopete82
6-May-11 14:39pm
View
Sorry I missed that but that worked.
Code that worked:
Dim Num090 = (From datafield In ser.Descendants("datafield") Where (datafield.Attribute("tag").Value = "090")
Select datafield.Elements.ElementAt(0))
If IsNothing(Num090) Then
Num090.Value = String.Empty
MsgBox(Num090.Value)
Else
MsgBox(Num090.Value)
End If
Thanks
stopete82
6-May-11 14:16pm
View
yes that's what I am having problems. I would like to check if Num090 is null first. How can I dot that? Thanks again.
stopete82
6-May-11 13:01pm
View
For the fallowing code I want to capture the value for Num090 but sometimes it won't have a value.
with value xml file:
<datafield tag="090" ind1="1" ind2="0">
<subfield code="a">Control over the Nile
No value xml :
<datafield tag="245" ind1="1" ind2="0">
<subfield code="a">
or sometimes it won't exist:
stopete82
6-May-11 12:53pm
View
Thanks for the response but that won't worked because the fallowing code if their is now value for Num090 I get a exception error. This variable doesn't return an string.
Dim Num090 = (From datafield In ser.Descendants("datafield") Where (datafield.Attribute("tag").Value = "090")
Select datafield.Elements.ElementAt(0))
stopete82
26-Apr-11 12:25pm
View
Thanks that worked. However, I need to go back to your suggestion about using string-builder class. My code works great when manipulating a small XML file, however if I use a large XML file it drags and eventually errors out. I going to work on it, do you think I should open a new Question if I am having problems with string-builder? again thanks for all your help.
stopete82
26-Apr-11 11:27am
View
The fallowing code I finally see the progress bar getting filled. However it doesn’t go to the end. I being playing with it and I can’t figured out how to tell the progress bar when it has reach the last record count.
This is an example(its works) that I think explains my problem. It has a loop with a counter once the counter reaches 10000 stops and the progress bar is field :
Dim intValue As Integer
progressBar1.Maximum = 100000
Do While Not intValue = 100000
progressBar1.Value = intValue
intValue = intValue + 1
' MsgBox(intValue)
Loop
My code that shows were I put my values:
Dim Records = (From datafields In xd.Descendants("record")
Select datafields)
Dim value As Integer = 0
totalrecords = Records.Count
ProgressBar1.Maximum = totalrecords
For Each ser As XElement In Records
Dim BytesWritten As Integer
ProgressBar1.Value = BytesWritten
objWriter.WriteLine()
BytesWritten += 1
Catch ex As Exception
stopete82
25-Apr-11 16:04pm
View
Thanks for the tips, I will look into it.
stopete82
25-Apr-11 15:38pm
View
After father testing what’s going on with the original code is that the Progress bar goes from empty progress bar to full progress bar. In another words there are no progress bar increments. One thing I know that my progressbar1.max will my final strFinalSring.Length.
What I am having problems is setting up the fallowing variables:
ProgressBar1.Min = 0
Progressbar.Max = ? (final value until file finished written)
ProgressBar1.value = ?
With the code I provided using a small file, it writes three records and the values I get are as fallow:
BytesWritten += strFinalString.Length first record I get 485
BytesWritten += strFinalString.Length second record I get 912
BytesWritten += strFinalString.Length last record which it will be my max value is 1837
Again thanks for all your help
stopete82
25-Apr-11 12:44pm
View
Thanks for the great suggestion; however it works great with a small size xml file (tried 21kb and 331 byes worked); however, if I try a large xml file (102mb) I don’t see the progress bar progress. Is there a way I can refresh the progress bar when using a large xml file? Appreciate your help.
Code:
strFilename = browsetofile()
If IsNothing(strFilename) Then
MsgBox("No XML file was selected", vbCritical, "No XML file was selected")
Exit Sub
End If
Dim xd As XDocument = XDocument.Load(strFilename)
Dim FILE_NAME As String = "C:\Temp\test.txt"
Dim objWriter As New System.IO.StreamWriter(FILE_NAME)
Dim strPipe As String = Chr(124)
Dim strSpace As String = Chr(10)
Dim strFinalString As String = ""
'prgreebar()
Dim value As Integer = 0
Dim BytesWritten As Integer = ProgressBar1.Maximum
BytesWritten += Value
ProgressBar1.Value = BytesWritten
Dim Records = (From datafields In xd.Descendants("record")
Select datafields)
'Me.Cursor = Cursors.WaitCursor
For Each ser As XElement In Records
Try
Dim Num090 = (From datafield In ser.Descendants("datafield") Where (datafield.Attribute("tag").Value = "090")
Select datafield.Elements.ElementAt(0))
Dim DTIC856 = (From datafield In ser.Descendants("datafield") Where (datafield.Attribute("tag").Value = "856")
Select datafield).Skip(1).First()
Dim Edocs856 = (From datafield In ser.Descendants("datafield") Where (datafield.Attribute("tag").Value = "856")
Select datafield)
Dim Title245_A = (From datafield In ser.Descendants("datafield") Where (datafield.Attribute("tag").Value = "245")
Select datafield.Elements.ElementAt(0))
Dim Title245_B = (From datafield In ser.Descendants("datafield") Where (datafield.Attribute("tag").Value = "245") And datafield.Elements.Count >= 2
Select datafield.Elements.ElementAt(1))
Dim Author100 = (From datafield In ser.Descendants("datafield") Where (datafield.Attribute("tag").Value = "100")
Select datafield.Elements.ElementAt(0))
Dim ADAnum037 = (From datafield In ser.Descendants("datafield") Where (datafield.Attribute("tag").Value = "037")
Select datafield.Elements.ElementAt(0))
Dim CoAuthor500 = (From datafield In ser.Descendants("datafield") Where (datafield.Attribute("tag").Value = "500")
Select datafield).Skip(2).First()
Dim Quater500 = (From datafield In ser.Descendants("datafield") Where (datafield.Attribute("tag").Value = "500")
Select datafield).Skip(1).First()
Dim BOSUNnum001 = (From controlfield In ser.Descendants("controlfield") Where (controlfield.Attribute("tag").Value = "001")
Select controlfield)
Dim Type999 = (From datafield In ser.Descendants("datafield") Where (datafield.Attribute("tag").Value = "999")
Select datafield.Elements.ElementAt(2)) '.Skip(0).First()
strFinalString = Num090.Value & " " & strPipe & " " & DTIC856.Value & " " & strPipe & " " & Edocs856.Value & " " & strPipe & " " & Title245_A.Value _
& " " & Title245_B.Value & " " & strPipe & " " & Author100.Value & " " & strPipe & " " & ADAnum037.Value & " " & strPipe & " " & CoAuthor500.Value & _
" " & strPipe & " " & Quater500.Value & " " & strPipe & " " & BOSUNnum001.Value & " " & strPipe & " " & Type999.Value
objWriter.WriteLine(strFinalString)
BytesWritten += strFinalString.Length
Catch ex As Exception
stopete82
20-Apr-11 15:02pm
View
Sorry I am new to this forum, I thought I needed to click on the green "Accept Solution" label.
stopete82
20-Apr-11 11:52am
View
Count() is does the trick, thanks for all your help.
stopete82
20-Apr-11 11:52am
View
It's works, thanks for your help.
stopete82
15-Apr-11 18:10pm
View
Yes, it did help. Thanks for all your help.
stopete82
15-Apr-11 17:48pm
View
I found the problem, VB.Net doesn't like e here is the code in vb.net that works.
Dim xd As XDocument = XDocument.Load("C:\Users\stopete\Desktop\Marc_convertxml.xml")
Dim records = (From datafields In xd.Descendants("record")
Select datafields)
For Each ser As XElement In records
Dim data = (From datafield In ser.Descendants("datafield") Where (datafield.Attribute("tag").Value = "500")
Select datafield).Skip(1).First()
MsgBox(data.Value)
Next
stopete82
15-Apr-11 17:43pm
View
Sorry, for some reason I didn't see your code. However, I converted the code to VB.net but I get a syntax error Variable 'e' hides a variable in an enclosing block. Maybe somebody can see what I am missing in code. Apprciate your help.
Code:
Dim xd As XDocument = XDocument.Load("C:\Users\stopete\Desktop\Marc_convertxml.xml")
Dim records = (From datafields In xd.Descendants("record")
Select datafields)
For Each e As XElement In records
Dim data = (From datafield In e.Descendants("datafield") Where (datafield.Attribute("tag").Value = "500")
Select datafield).Skip(0).First()
MsgBox(data.Value)
Next
stopete82
15-Apr-11 14:34pm
View
Thanks for the reply Skip(0) works it gives me the right result for the first record. However; the problem now is that it stops at first record, do you know what I need to add so it will traverse the whole xml document.
stopete82
15-Apr-11 13:36pm
View
Thanks for the quick response. With your help I think I am in the right track. However; the sample you send I get the right output for the first record but then it doesn't go to next record. Do you know what I need to add to go to the next record?
Code:
Dim xd As XDocument = XDocument.Load("C:\Users\stopete\Desktop\Marc_convertxml.xml")
If xd IsNot Nothing Then
Dim datafields = (From datafield In xd.Descendants("datafield")
Where (datafield.Attribute("tag").Value = "500")
Select datafield).Skip(0).First()
For Each xEle In datafields.Elements
MsgBox(xEle)
Next
End If
Ouput:
Thesis Advisor(s): Borer, Douglas A. ; Second Reader: Chatterjee, Anshu.
Disire output:
First record
Thesis Advisor(s): Borer, Douglas A. ; Second Reader: Chatterjee, Anshu.
Second record
Thesis Advisor(s): Olsen, Richard C. ; Second Reader: Trask, David M.
Thanks for all your help.
Show More