I've made a rudimentary program that combines multiple files into one single file. Currently if I combine two .csv files together the output comes out correctly for what I need, which is a coma delimited file. When I try to combine two .csv files into a .xls file it doesn't format correctly (I get all the data separated by commas, but thrown into one column in the .xls file). For this reason I believe I need to add a delimiter.I'll post my code below.
I've tried adding a delimiter using the split method, however Vb Express tells me that I can't (Value of type 'String' cannot be converted to '1-dimensional array of String'). I'm still really new to VB and I'm not sure about the best course of action. I'll gladly accept any constructive criticism and help with this problem and the program in general. Thank you.
Public Class frmMain 'Sets up array as read only. Public ReadOnly Property FileNames() As String Get Return FileNames End Get End Property Private Sub btnAppendData_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAppendData.Click 'Sets up the dialog boxes Dim ResultOFD As DialogResult Dim ResultSFD As DialogResult ' Allow the user to select multiple files. ofdMain.Multiselect = True ofdMain.Title = "Please Select Multiple Files" sfdMain.Title = "Please Choose New File Name" ' Set the file dialog to filter for text files. ofdMain.Filter = "Text Files (*.txt)|*.txt|CSV Files (*.csv)|*.csv|Excel Files (*.xls)|*.xls|All Files (*.*)|*.*" sfdMain.Filter = "Text Files (*.txt)|*.txt|CSV Files (*.csv)|*.csv|Excel Files (*.xls)|*.xls|All Files (*.*)|*.*" Dim FileNameWrite As String Dim sw As StreamWriter Dim File, FileContents As String ' Display the dialog box. ofdMain.FileName = "" ResultOFD = ofdMain.ShowDialog() If ResultOFD = Windows.Forms.DialogResult.OK Then ResultSFD = sfdMain.ShowDialog() ' Display the dialog box. FileNameWrite = sfdMain.FileName If ResultSFD = Windows.Forms.DialogResult.OK Then 'For Each loop For Each File In ofdMain.FileNames Dim sr As New System.IO.StreamReader(File) 'Sets up StreamReader to read new "File" for each run File = ofdMain.FileName 'Holds file name FileContents = sr.ReadToEnd 'Reads content to end of file and stores data in FileContents sr.Close() 'Close StreamReader sw = New StreamWriter(FileNameWrite, True) 'write file to path given sw.Write(FileContents) 'Writes contents of variable to file sw.Close() 'Close StreamWriter Next File MessageBox.Show(FileNameWrite + " Written Successfully!") 'File status End If End If End Sub Private Sub btnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExit.Click Me.Close() End Sub End Class