Hi @LA RC ,
In your code , sheetTest accesses global variables, while NavButton1 accesses local variables.
You can make global variables public, and then initialize and assign values to them when you use them.
Here are my test result and test code which you can refer to.
Public writerC As XmlTextWriter
Private Sub NavButton1_Click(sender As Object, e As EventArgs) Handles NavButton1.Click
Dim pathRoot As String = "C:\Users\lijiachenl\source\repos\Case22.4.1\WindowsApp2\"
Dim strPathC As String = pathRoot & "\" & "e" & TextBox1.Text & ".XML"
writerC = New XmlTextWriter(strPathC, System.Text.Encoding.UTF8)
writerC.WriteStartDocument(True)
writerC.Formatting = Formatting.Indented
writerC.Indentation = 2
writerC.WriteStartElement("PageCollection") '---PageCollection---
'If i = 0 Then
sheetTest("A", "B", "C", "D")
'End If
writerC.WriteEndElement() '---PageCollection/---
writerC.Close() '---CLOSING XML FILE/---
pathRoot = pathRoot & "\" & "SentFiles"
Directory.CreateDirectory(pathRoot)
MsgBox("Successfully generated files.", MsgBoxStyle.Information + MessageBoxButtons.OK, "TEST")
Dim fs As New FileStream(strPathC, FileMode.Open, FileAccess.Read)
Dim data(fs.Length) As Byte
fs.Read(data, 0, fs.Length)
Console.WriteLine(Encoding.UTF8.GetChars(data))
End Sub
Public Function sheetTest(firstParameter As String, secondParameter As String, thirdParameter As String, fourthParameter As String)
writerC.WriteStartElement("Page") '---Page---
writerC.WriteStartElement("Collection") '---Collection---
writerC.WriteEndElement() '---Collection/---
writerC.WriteEndElement() '---Page/---
End Function
Hope these could be helpful.
Best Regards.
Jiachen Li
----------
If the answer is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.