Problem with code

I have a listview that is filled with data and that data I export to XML with the code attached.

What I want to do is if I have no item in column 1 it does not write it to the XML but how can I also check column 2 & 3 also to see if that contains data if not then again do not export to XML.

So how can I check column 1,2,3 and if they contain data write it to out if not then do not export. I have got it to work for column 1 but cannot do it for any others.
Dim AppLog As New Logger
 
        Dim os As New StreamWriter(filename)
 
        os.Write("<!-- Generated By Gardiff Fourth Hospitaility Utility " & DateTime.Today.ToString("dd/MM/yyyy") & "-->")
        os.WriteLine()
        os.Write("<!-- Total Sales: " & Label1.Text & "-->")
        os.WriteLine()
        os.Write("<FourthHeader xmlns="""">")
        os.WriteLine()
        os.Write("<OrganisationID>" & FrmSettings.txtID.Text & "</OrganisationID>")
        os.WriteLine()
        os.Write("<UserName>" & FrmSettings.txtFourthUsername.Text & "</UserName>")
        os.WriteLine()
        os.Write("<Password>" & FrmSettings.txtFourthPassword.Text & "</Password>")
        os.WriteLine()
        os.Write("<SalesHeader>")
        os.WriteLine()
        os.Write("<SalesDate>" & DateTime.Today.ToString("dd/MM/yyyy") & "</SalesDate>")
        os.WriteLine()
 
        For i As Integer = 0 To lv.Items.Count - 1
            If lv.Items(i).SubItems(1).Text <> "" Then
 
                'End If
 
                'If lv.Items(i).SubItems(5).Text = "0.00" Then
 
                If FrmSettings.chkPrice1.CheckState = CheckState.Checked Then
 
                    'Price Level 1
                    os.Write("<SalesTransaction>")
                    os.WriteLine()
                    os.Write("<" & lv.Columns.Item(0).Text & ">")
                    os.Write(lv.Items(i).SubItems(0).Text)
                    os.Write("</" & lv.Columns.Item(0).Text & ">")
                    os.WriteLine()
                    os.Write("<" & lv.Columns.Item(1).Text & ">")
                    os.Write(lv.Items(i).SubItems(1).Text)
                    os.Write("</" & lv.Columns.Item(1).Text & ">")
                    os.WriteLine()
                    os.Write("<" & lv.Columns.Item(2).Text & ">")
                    os.Write(lv.Items(i).SubItems(2).Text)
                    os.Write("</" & lv.Columns.Item(2).Text & ">")
                    os.WriteLine()
                    os.Write("<" & lv.Columns.Item(5).Text & ">")
                    os.Write(lv.Items(i).SubItems(5).Text)
                    os.Write("</" & lv.Columns.Item(5).Text & ">")
                    os.WriteLine()
                    os.Write("<" & lv.Columns.Item(8).Text & ">")
                    os.Write(lv.Items(i).SubItems(8).Text)
                    os.Write("</" & lv.Columns.Item(8).Text & ">")
                    os.WriteLine()
                    os.Write("</SalesTransaction>")
                    os.WriteLine()
 
                    If FrmSettings.chkPrice2.CheckState = CheckState.Checked Then
 
                        'Price Level 2
                        os.Write("<SalesTransaction>")
                        os.WriteLine()
                        os.Write("<" & lv.Columns.Item(0).Text & ">")
                        os.Write(lv.Items(i).SubItems(0).Text)
                        os.Write("</" & lv.Columns.Item(0).Text & ">")
                        os.WriteLine()
                        os.Write("<" & lv.Columns.Item(1).Text & ">")
                        os.Write(lv.Items(i).SubItems(1).Text)
                        os.Write("</" & lv.Columns.Item(1).Text & ">")
                        os.WriteLine()
                        os.Write("<" & lv.Columns.Item(3).Text & ">")
                        os.Write(lv.Items(i).SubItems(3).Text)
                        os.Write("</" & lv.Columns.Item(3).Text & ">")
                        os.WriteLine()
                        os.Write("<" & lv.Columns.Item(6).Text & ">")
                        os.Write(lv.Items(i).SubItems(6).Text)
                        os.Write("</" & lv.Columns.Item(6).Text & ">")
                        os.WriteLine()
                        os.Write("<" & lv.Columns.Item(9).Text & ">")
                        os.Write(lv.Items(i).SubItems(9).Text)
                        os.Write("</" & lv.Columns.Item(9).Text & ">")
                        os.WriteLine()
                        os.Write("</SalesTransaction>")
                        os.WriteLine()
 
                        If FrmSettings.chkPrice3.CheckState = CheckState.Checked Then
 
                            'Price Level 3
                            os.Write("<SalesTransaction>")
                            os.WriteLine()
                            os.Write("<" & lv.Columns.Item(0).Text & ">")
                            os.Write(lv.Items(i).SubItems(0).Text)
                            os.Write("</" & lv.Columns.Item(0).Text & ">")
                            os.WriteLine()
                            os.Write("<" & lv.Columns.Item(1).Text & ">")
                            os.Write(lv.Items(i).SubItems(1).Text)
                            os.Write("</" & lv.Columns.Item(1).Text & ">")
                            os.WriteLine()
                            os.Write("<" & lv.Columns.Item(4).Text & ">")
                            os.Write(lv.Items(i).SubItems(4).Text)
                            os.Write("</" & lv.Columns.Item(4).Text & ">")
                            os.WriteLine()
                            os.Write("<" & lv.Columns.Item(7).Text & ">")
                            os.Write(lv.Items(i).SubItems(7).Text)
                            os.Write("</" & lv.Columns.Item(7).Text & ">")
                            os.WriteLine()
                            os.Write("<" & lv.Columns.Item(10).Text & ">")
                            os.Write(lv.Items(i).SubItems(10).Text)
                            os.Write("</" & lv.Columns.Item(10).Text & ">")
                            os.WriteLine()
                            os.Write("</SalesTransaction>")
                            os.WriteLine()
 
                        End If
                    End If
                End If
            End If
        Next
 
        os.Write("</SalesHeader>")
        os.WriteLine()
        os.Write("</FourthHeader>")
        os.WriteLine()
        os.Close()
 
        AppLog.WriteLog("Created XML File: " & filename)

Open in new window

richard_garAsked:
Who is Participating?
 
purplepomegraniteConnect With a Mentor Commented:
Note I've only added the check for three items.  You can use similar checks for all the items as you need.
0
 
Daniel ReynoldsSoftware Applications Developer / IntegratorCommented:
try something like the following
            If lv.Items(i).SubItems(1).Text <> "" Then
               If lv.Items(i+1).SubItems(1).Text <> "" Then
                 If lv.Items(i+2).SubItems(1).Text <> "" Then
                 ... process xml
                 End If
               End If
            End If
0
 
richard_garAuthor Commented:
no that ain't working
0
 
purplepomegraniteCommented:
You mean like the below?

Dim AppLog As New Logger
 
Dim os As New StreamWriter(filename)
 
os.Write("<!-- Generated By Gardiff Fourth Hospitaility Utility " & DateTime.Today.ToString("dd/MM/yyyy") & "-->")
os.WriteLine()
os.Write("<!-- Total Sales: " & Label1.Text & "-->")
os.WriteLine()
os.Write("<FourthHeader xmlns="""">")
os.WriteLine()
os.Write("<OrganisationID>" & FrmSettings.txtID.Text & "</OrganisationID>")
os.WriteLine()
os.Write("<UserName>" & FrmSettings.txtFourthUsername.Text & "</UserName>")
os.WriteLine()
os.Write("<Password>" & FrmSettings.txtFourthPassword.Text & "</Password>")
os.WriteLine()
os.Write("<SalesHeader>")
os.WriteLine()
os.Write("<SalesDate>" & DateTime.Today.ToString("dd/MM/yyyy") & "</SalesDate>")
os.WriteLine()
 
For i As Integer = 0 To lv.Items.Count - 1
	If lv.Items(i).SubItems(1).Text <> "" Then
		If FrmSettings.chkPrice1.CheckState = CheckState.Checked Then
 
		'Price Level 1
		os.Write("<SalesTransaction>")
		os.WriteLine()
		if lv.Items(i).SubItems(0)<>"" then
			os.Write("<" & lv.Columns.Item(0).Text & ">")
			os.Write(lv.Items(i).SubItems(0).Text)
			os.Write("</" & lv.Columns.Item(0).Text & ">")
			os.WriteLine()
		end if
		if lv.Items(i).SubItems(1).Text<>"" then
			os.Write("<" & lv.Columns.Item(1).Text & ">")
			os.Write(lv.Items(i).SubItems(1).Text)
			os.Write("</" & lv.Columns.Item(1).Text & ">")
			os.WriteLine()
		end if
		if lv.Items(i).SubItems(2).Text<>"" then
			os.Write("<" & lv.Columns.Item(2).Text & ">")
			os.Write(lv.Items(i).SubItems(2).Text)
			os.Write("</" & lv.Columns.Item(2).Text & ">")
			os.WriteLine()
		end if
		os.Write("<" & lv.Columns.Item(5).Text & ">")
		os.Write(lv.Items(i).SubItems(5).Text)
		os.Write("</" & lv.Columns.Item(5).Text & ">")
		os.WriteLine()
		os.Write("<" & lv.Columns.Item(8).Text & ">")
		os.Write(lv.Items(i).SubItems(8).Text)
		os.Write("</" & lv.Columns.Item(8).Text & ">")
		os.WriteLine()
		os.Write("</SalesTransaction>")
		os.WriteLine()
 
		If FrmSettings.chkPrice2.CheckState = CheckState.Checked Then
			'Price Level 2
			os.Write("<SalesTransaction>")
			os.WriteLine()
			os.Write("<" & lv.Columns.Item(0).Text & ">")
			os.Write(lv.Items(i).SubItems(0).Text)
			os.Write("</" & lv.Columns.Item(0).Text & ">")
			os.WriteLine()
			os.Write("<" & lv.Columns.Item(1).Text & ">")
			os.Write(lv.Items(i).SubItems(1).Text)
			os.Write("</" & lv.Columns.Item(1).Text & ">")
			os.WriteLine()
			os.Write("<" & lv.Columns.Item(3).Text & ">")
			os.Write(lv.Items(i).SubItems(3).Text)
			os.Write("</" & lv.Columns.Item(3).Text & ">")
			os.WriteLine()
			os.Write("<" & lv.Columns.Item(6).Text & ">")
			os.Write(lv.Items(i).SubItems(6).Text)
			os.Write("</" & lv.Columns.Item(6).Text & ">")
			os.WriteLine()
			os.Write("<" & lv.Columns.Item(9).Text & ">")
			os.Write(lv.Items(i).SubItems(9).Text)
			os.Write("</" & lv.Columns.Item(9).Text & ">")
			os.WriteLine()
			os.Write("</SalesTransaction>")
			os.WriteLine()
 
			If FrmSettings.chkPrice3.CheckState = CheckState.Checked Then
				'Price Level 3
				os.Write("<SalesTransaction>")
				os.WriteLine()
				os.Write("<" & lv.Columns.Item(0).Text & ">")
				os.Write(lv.Items(i).SubItems(0).Text)
				os.Write("</" & lv.Columns.Item(0).Text & ">")
				os.WriteLine()
				os.Write("<" & lv.Columns.Item(1).Text & ">")
				os.Write(lv.Items(i).SubItems(1).Text)
				os.Write("</" & lv.Columns.Item(1).Text & ">")
				os.WriteLine()
				os.Write("<" & lv.Columns.Item(4).Text & ">")
				os.Write(lv.Items(i).SubItems(4).Text)
				os.Write("</" & lv.Columns.Item(4).Text & ">")
				os.WriteLine()
				os.Write("<" & lv.Columns.Item(7).Text & ">")
				os.Write(lv.Items(i).SubItems(7).Text)
				os.Write("</" & lv.Columns.Item(7).Text & ">")
				os.WriteLine()
				os.Write("<" & lv.Columns.Item(10).Text & ">")
				os.Write(lv.Items(i).SubItems(10).Text)
				os.Write("</" & lv.Columns.Item(10).Text & ">")
				os.WriteLine()
				os.Write("</SalesTransaction>")
				os.WriteLine()
 
				End If
			End If
		End If
	End If
Next
 
os.Write("</SalesHeader>")
os.WriteLine()
os.Write("</FourthHeader>")
os.WriteLine()
os.Close()
 
AppLog.WriteLog("Created XML File: " & filename)

Open in new window

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.