EDN Admin
Well-known member
Hi Reed
I decided to rewrite my project. Hit another snag. How do I write the contents from a datagrid to a file and back into the datagrid again later????? (Actually, Ive done the writing ok - but for the life of me cant get the data back into a blank datagrid.
The MS help on readline is about as much use as a chocolate fireguard.
Again, the problem is somehwere near the bottom of the listing.
Allan
Heres what I done so far:
<div style="color:Black;background-color:White; <pre>
<span style="color:Blue; Imports System
<span style="color:Blue; Imports System.IO
<span style="color:Blue; Imports System.Text
<span style="color:Blue; Public <span style="color:Blue; Class frmKAOS
<span style="color:Blue; Private <span style="color:Blue; Sub frmKAOS_FormClosing(<span style="color:Blue; ByVal sender <span style="color:Blue; As <span style="color:Blue; Object, <span style="color:Blue; ByVal e <span style="color:Blue; As System.Windows.Forms.FormClosingEventArgs) <span style="color:Blue; Handles <span style="color:Blue; Me.FormClosing
<span style="color:Blue; If MessageBox.Show(<span style="color:#A31515; "Are you sure that you want to exit KAOS5?", <span style="color:#A31515; "Exit KAOS5", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question) = DialogResult.Yes <span style="color:Blue; Then
e.Cancel = <span style="color:Blue; False
<span style="color:Blue; Else
e.Cancel = <span style="color:Blue; True
<span style="color:Blue; End <span style="color:Blue; If
<span style="color:Blue; End <span style="color:Blue; Sub
<span style="color:Blue; Private <span style="color:Blue; Sub Form1_Load(<span style="color:Blue; ByVal sender <span style="color:Blue; As System.Object, <span style="color:Blue; ByVal e <span style="color:Blue; As System.EventArgs) <span style="color:Blue; Handles <span style="color:Blue; MyBase.Load
<span style="color:Blue; Dim drvs() <span style="color:Blue; As <span style="color:Blue; String = System.IO.Directory.GetLogicalDrives()
<span style="color:Blue; Dim i <span style="color:Blue; As <span style="color:Blue; Long
<span style="color:Blue; Me.Text = <span style="color:#A31515; "KAOS5"
<span style="color:Blue; Me.StartPosition = FormStartPosition.CenterScreen
<span style="color:Green; Me.WindowState = FormWindowState.Maximized
OpenToolStripMenuItem.Enabled = <span style="color:Blue; False
PlayToolStripMenuItem.Enabled = <span style="color:Blue; False
PauseToolStripMenuItem.Enabled = <span style="color:Blue; False
ResumeToolStripMenuItem.Enabled = <span style="color:Blue; False
StopToolStripMenuItem.Enabled = <span style="color:Blue; False
CloseToolStripMenuItem.Enabled = <span style="color:Blue; False
SaveToolStripMenuItem.Enabled = <span style="color:Blue; False
songsDataGridView1.SelectionMode = DataGridViewSelectionMode.FullRowSelect
songsDataGridView1.MultiSelect = <span style="color:Blue; False
tbVolume.Enabled = 0
tbVolume.Minimum = 0
tbVolume.Maximum = 1000
tbVolume.Value = 0
lblVolume.Text = <span style="color:#A31515; "0"
tbVolume.TickFrequency = 100
Timer1.Interval = 900 <span style="color:Green; Roughly every sec (even though its in millisecs I prefer using 900 to 1000)
Timer1.Enabled = <span style="color:Blue; False
lblNoOfFiles.Text = <span style="color:#A31515; "0"
lblProgress.Text = <span style="color:#A31515; "0"
songsDataGridView1.ScrollBars = ScrollBars.Both
songsDataGridView1.Size = <span style="color:Blue; New Size(<span style="color:Blue; Me.Width - 50, <span style="color:Blue; Me.Height - (ProgressBar1.Height + 230))
songsDataGridView1.ColumnCount = 12 <span style="color:Green; not 13 as Im not showing the tag - nothing to do with being superstitious about 13
songsDataGridView1.Columns(0).Width = 30 * 16
songsDataGridView1.Columns(1).Width = 30 * 16
songsDataGridView1.Columns(2).Width = 30 * 16
<span style="color:Green; songsDataGridView1.Columns(3).Width = 4 * 16
songsDataGridView1.Columns(4).Width = 30 * 16
<span style="color:Green; songsDataGridView1.Columns(5).Width = 1 * 16
songsDataGridView1.Columns(6).Width = 3 * 16
<span style="color:Green; songsDataGridView1.Columns(7).Width = 1 * 16
songsDataGridView1.Columns(8).Width = 30 * 16
songsDataGridView1.Columns(9).Width = 256 * 16
<span style="color:Green; The column widths are in pixels - Ive allowed 16 pixels per character
<span style="color:Green; songsDataGridView1.Columns(0).Name = "TAG" Not showing the tag
songsDataGridView1.Columns(0).Name = <span style="color:#A31515; "Title"
songsDataGridView1.Columns(1).Name = <span style="color:#A31515; "Artist"
songsDataGridView1.Columns(2).Name = <span style="color:#A31515; "Album"
songsDataGridView1.Columns(3).Name = <span style="color:#A31515; "Year"
songsDataGridView1.Columns(4).Name = <span style="color:#A31515; "Comment"
songsDataGridView1.Columns(5).Name = <span style="color:#A31515; "Zero Byte"
songsDataGridView1.Columns(6).Name = <span style="color:#A31515; "#"
songsDataGridView1.Columns(7).Name = <span style="color:#A31515; "Genre Byte"
songsDataGridView1.Columns(8).Name = <span style="color:#A31515; "Genre String"
songsDataGridView1.Columns(9).Name = <span style="color:#A31515; "Path"
songsDataGridView1.Columns(10).Name = <span style="color:#A31515; "Size (in bytes)"
songsDataGridView1.Columns(11).Name = <span style="color:#A31515; "Playing time"
<span style="color:Green; Populate the drive combobox with a list of logical drives
<span style="color:Blue; For i = drvs.GetLowerBound(0) <span style="color:Blue; To drvs.GetUpperBound(0)
cmbDrives.Items.Add(drvs(i))
<span style="color:Blue; Next i
cmbDrives.SelectedIndex = 0
txtFileExtension.Text = <span style="color:#A31515; "mp3" <span style="color:Green; Default extension
<span style="color:Blue; End <span style="color:Blue; Sub
<span style="color:Blue; Private <span style="color:Blue; Sub btnExit_Click(<span style="color:Blue; ByVal sender <span style="color:Blue; As System.Object, <span style="color:Blue; ByVal e <span style="color:Blue; As System.EventArgs) <span style="color:Blue; Handles btnExit.Click
Application.<span style="color:Blue; Exit()
<span style="color:Blue; End <span style="color:Blue; Sub
<span style="color:Blue; Private <span style="color:Blue; Sub btnSearch_Click(<span style="color:Blue; ByVal sender <span style="color:Blue; As System.Object, <span style="color:Blue; ByVal e <span style="color:Blue; As System.EventArgs) <span style="color:Blue; Handles btnSearch.Click
<span style="color:Blue; Me.DialogResult = System.Windows.Forms.DialogResult.OK
<span style="color:Blue; Dim tags <span style="color:Blue; As List(Of <span style="color:Blue; String), datarow() <span style="color:Blue; As <span style="color:Blue; String
<span style="color:Blue; Dim PlayingTimeColIndex <span style="color:Blue; As <span style="color:Blue; Integer = 11, CurrentRowIndex <span style="color:Blue; As <span style="color:Blue; Integer = 0
<span style="color:Blue; Dim filename <span style="color:Blue; As <span style="color:Blue; String, ret <span style="color:Blue; As <span style="color:Blue; Integer, lpStrReturnString <span style="color:Blue; As <span style="color:Blue; String = Space(128)
<span style="color:Green; <summary>
<span style="color:Green; Entry point that uses the recursive search directory function.
<span style="color:Green;
<span style="color:Green; Very important note:
<span style="color:Green; By design, this routine DOES NOT CLEAR the grid of found files BECAUSE the user may want to add
<span style="color:Green; files from multiple drive searches (or even want a list of duplicated files - who knows?)!
<span style="color:Green; There is a separate Clear list button to clear the datagrid of files - but its up to the user to
<span style="color:Green; choose to use it - or not.
<span style="color:Green; </summary>
<span style="color:Green; Get recursive List of all files starting in this directory.
<span style="color:Blue; Dim drv <span style="color:Blue; As <span style="color:Blue; String = cmbDrives.SelectedItem
<span style="color:Blue; Dim start <span style="color:Blue; As <span style="color:Blue; String = <span style="color:#A31515; ""
<span style="color:Blue; Dim ext <span style="color:Blue; As <span style="color:Blue; String = <span style="color:#A31515; ""
<span style="color:Blue; If drv = <span style="color:#A31515; "" <span style="color:Blue; Then
drv = <span style="color:#A31515; "c:"
<span style="color:Blue; End <span style="color:Blue; If
<span style="color:Blue; If Microsoft.VisualBasic.Right$(drv, 1) <> <span style="color:#A31515; "" <span style="color:Blue; Then
drv = drv & <span style="color:#A31515; ""
<span style="color:Blue; End <span style="color:Blue; If
<span style="color:Blue; Me.Cursor = Cursors.WaitCursor
lblSysMessage.Text = <span style="color:#A31515; "Searching...."
Application.DoEvents()
<span style="color:Green; Setup the debug window - remember to take out this code in the release version
Debug.Close()
Debugger.Launch()
Debug.Flush()
Debug.AutoFlush() = <span style="color:Blue; True
start = drv
<span style="color:Green; ToDo: I should validate the start folder here to see if its a valid one
<span style="color:Blue; If txtStartFolder.Text <> <span style="color:#A31515; "" <span style="color:Blue; Then
start = start & txtStartFolder.Text
<span style="color:Blue; End <span style="color:Blue; If
ext = txtFileExtension.Text
<span style="color:Blue; If Microsoft.VisualBasic.Left(ext, 2) <> <span style="color:#A31515; "*." <span style="color:Blue; Then
ext = <span style="color:#A31515; "*." & ext <span style="color:Green; Extension should really be validated here
<span style="color:Blue; End <span style="color:Blue; If
GC.Collect() <span style="color:Green; Force a garbage collection because we are potentially going to be doing a LOT of string handling
lblSysMessage.Text = <span style="color:#A31515; "Starting search of directory " & start
<span style="color:Blue; Dim list <span style="color:Blue; As List(Of <span style="color:Blue; String) = GetFilesRecursive(start, ext)
MsgBox(<span style="color:#A31515; "Search of " & start & <span style="color:#A31515; " done. Starting to process the found files.")
Application.DoEvents()
lblSysMessage.Text = <span style="color:#A31515; "Processing found files"
ProgressBar1.Minimum = 0
ProgressBar1.Maximum = list.<span style="color:Blue; Count
ProgressBar1.Value = 0
<span style="color:Blue; If list.<span style="color:Blue; Count = 0 <span style="color:Blue; Then
lblSysMessage.Text = <span style="color:#A31515; "No such start directory"
<span style="color:Blue; Me.Cursor = Cursors.<span style="color:Blue; Default
<span style="color:Blue; Exit <span style="color:Blue; Sub
<span style="color:Blue; End <span style="color:Blue; If
lblNoOfFiles.Text = list.<span style="color:Blue; Count
<span style="color:Blue; For <span style="color:Blue; Each path <span style="color:Blue; In list
tags = ReadTags(path)
ProgressBar1.Value = ProgressBar1.Value + 1
lblProgress.Text = Int((ProgressBar1.Value / ProgressBar1.Maximum) * 100)
datarow = tags.ToArray
<span style="color:Blue; If tags.<span style="color:Blue; Count > 0 <span style="color:Blue; Then
songsDataGridView1.Rows.Add(datarow)
<span style="color:Green; I find that getting the playing times makes the initial processing of the files
<span style="color:Green; waaaaaaay too long unfortunately
<span style="color:Green; (it increases the processing time per file by a factor of about 10x (my impression) which
<span style="color:Green; would normally be unacceptable, but its ok for a first time use and then the user has the
<span style="color:Green; option to save the processed list to a file or to read the list back from a file in the
<span style="color:Green; future.
<span style="color:Green; Surprisingly, although displaying the name of the file being processed slows things down
<span style="color:Green; a tad even more, psychologically it makes the wait more tolerable since the user actually sees
<span style="color:Green; that things are happening - and so the wait becomes a tad more tolerable.
<span style="color:Green;
filename = songsDataGridView1(9, CurrentRowIndex).Value
ret = mciSendString(<span style="color:#A31515; "Open " & Chr(34) & filename & Chr(34) & <span style="color:#A31515; " alias audio wait", <span style="color:Blue; CStr(0), 0, 0)
ret = mciSendString(<span style="color:#A31515; "set audio time milliseconds wait", <span style="color:Blue; CStr(0), 0, 0)
ret = mciSendString(<span style="color:#A31515; "status audio length wait", lpStrReturnString, Len(lpStrReturnString), 0)
<span style="color:Green; Note: the plaing time cannot be determeined for all files for some strange reason
<span style="color:Blue; If ret <> 0 <span style="color:Blue; Then
lblSysMessage.Text = <span style="color:#A31515; "Unable to set/get time format and playing time for " & filename
songsDataGridView1(PlayingTimeColIndex, CurrentRowIndex).Value = <span style="color:#A31515; "Unknown"
<span style="color:Blue; Else
<span style="color:Blue; Dim PT <span style="color:Blue; As <span style="color:Blue; String = ConvertToShortTime(Trim(lpStrReturnString))
songsDataGridView1(PlayingTimeColIndex, CurrentRowIndex).Value = PT
lblSysMessage.Text = <span style="color:#A31515; "Playing time for " & filename & <span style="color:#A31515; " is " & PT
<span style="color:Blue; End <span style="color:Blue; If
CurrentRowIndex = CurrentRowIndex + 1
ret = mciSendString(<span style="color:#A31515; "close audio wait", <span style="color:Blue; CStr(0), 0, 0)
<span style="color:Green; Im concerned that with thousands of files to process I have to try to keep the memory
<span style="color:Green; footprint/usage down. I wish that the ID3 v1.0 specification included a milliseconds playing
<span style="color:Green; time field in the ID3 frame - then getting the playing times initially wouldnt be a hassle.
<span style="color:Green; I know that one of the proposed extended ID3 tags specs. do - but so few MP3s use them (and
<span style="color:Green; it would require IF tests per file hence thousands of extra IFs being executed)
<span style="color:Green; that it isnt really worth checking for extended specification MP3 tags.
<span style="color:Green;
<span style="color:Green; Coding KAOS makes me appreciate wmp even more - despite its shortcomings!
<span style="color:Green;
Application.DoEvents()
<span style="color:Blue; End <span style="color:Blue; If
<span style="color:Blue; Next
<span style="color:Green; Write total number of paths found.
lblSysMessage.Text = <span style="color:#A31515; "Processing of found files done: " & songsDataGridView1.Rows.<span style="color:Blue; Count - 1 & <span style="color:#A31515; " files found. You are advised to save the list."
MsgBox(<span style="color:#A31515; "Processing of found files done: " & songsDataGridView1.Rows.<span style="color:Blue; Count - 1 & <span style="color:#A31515; " files found. You are advised to save the list.")
<span style="color:Blue; Me.Cursor = Cursors.<span style="color:Blue; Default
<span style="color:Green; MsgBox("Select a file with a left click, and then right click on that file to play it etc.", MsgBoxStyle.OkOnly, "Help") Hopefully, we wont need a left click now
MsgBox(<span style="color:#A31515; "Select a file with a right click to play it etc.", MsgBoxStyle.OkOnly, <span style="color:#A31515; "Help") <span style="color:Green; Hopefully, this will be true
Application.DoEvents()
OpenToolStripMenuItem.Enabled = <span style="color:Blue; True
PlayToolStripMenuItem.Enabled = <span style="color:Blue; False
PauseToolStripMenuItem.Enabled = <span style="color:Blue; False
ResumeToolStripMenuItem.Enabled = <span style="color:Blue; False
StopToolStripMenuItem.Enabled = <span style="color:Blue; False
CloseToolStripMenuItem.Enabled = <span style="color:Blue; False
SaveToolStripMenuItem.Enabled = <span style="color:Blue; False
Debug.Close()
<span style="color:Green; Update the files list
GC.Collect() <span style="color:Green; Force a garbage collection because we have likely done a LOT of string handling
<span style="color:Blue; End <span style="color:Blue; Sub
<span style="color:Blue; Private <span style="color:Blue; Sub SavePlaylistToolStripMenu_Click(<span style="color:Blue; ByVal sender <span style="color:Blue; As System.Object, <span style="color:Blue; ByVal e <span style="color:Blue; As System.EventArgs) <span style="color:Blue; Handles SavePlaylistToolStripMenu.Click
<span style="color:Green; Check if any files are in the datagrid
<span style="color:Blue; If songsDataGridView1.RowCount > 0 <span style="color:Blue; Then
GC.Collect() <span style="color:Green; Force a garbage collection because we are potentially going to be doing a LOT of string handling
<span style="color:Green; Save the datagrid
SaveFileDialog1.Filter = <span style="color:#A31515; "KAOS Playlist|*.kpl|Text|*.txt"
SaveFileDialog1.Title = <span style="color:#A31515; "Save a Playlist File"
SaveFileDialog1.CheckPathExists = <span style="color:Blue; True
SaveFileDialog1.DefaultExt = <span style="color:#A31515; "*.kpl"
SaveFileDialog1.InitialDirectory = Application.LocalUserAppDataPath
SaveFileDialog1.FileName = <span style="color:#A31515; ""
SaveFileDialog1.ShowDialog()
<span style="color:Green; If the file name is not an empty string open it for saving.
<span style="color:Blue; If SaveFileDialog1.FileName <> <span style="color:#A31515; "" <span style="color:Blue; Then
ProgressBar1.Minimum = 0
ProgressBar1.Maximum = songsDataGridView1.Rows.<span style="color:Blue; Count
ProgressBar1.Value = 0
<span style="color:Blue; Dim path <span style="color:Blue; As <span style="color:Blue; String = SaveFileDialog1.FileName
<span style="color:Green; Delete the current file if it exists.
<span style="color:Blue; If File.Exists(path) <span style="color:Blue; Then
File.Delete(path)
<span style="color:Blue; End <span style="color:Blue; If
<span style="color:Green; Create the new file -- note, saved as plain ASCII so that the user can view it in notepad, etc.
<span style="color:Blue; Dim NextLine <span style="color:Blue; As <span style="color:Blue; String = <span style="color:#A31515; ""
<span style="color:Blue; Dim fs <span style="color:Blue; As <span style="color:Blue; New FileStream(path, FileMode.Append, FileAccess.Write, FileShare.Write)
fs.Close()
<span style="color:Blue; Dim sw <span style="color:Blue; As <span style="color:Blue; New StreamWriter(path, <span style="color:Blue; True, Encoding.ASCII)
lblSysMessage.Text = <span style="color:#A31515; "Saving grid data..."
<span style="color:Blue; For rows = 0 <span style="color:Blue; To songsDataGridView1.Rows.<span style="color:Blue; Count - 1
NextLine = <span style="color:#A31515; "" <span style="color:Green; An extremely important line - do NOT forget to nullify this string
<span style="color:Green; each time in the loop before adding columns - otherwise the processing will really be VERY,
<span style="color:Green; VERY slow and the resultant file will likely be megabytes of text rather than a few kbs or 100s kbs.
<span style="color:Green; Get the column content values (separated by commas)
<span style="color:Blue; For column = 0 <span style="color:Blue; To 11
NextLine = NextLine & <span style="color:#A31515; "," & songsDataGridView1(column, rows).Value
<span style="color:Blue; Next
<span style="color:Green; Write the line of comma delineated values
lblSysMessage.Text = NextLine
sw.WriteLine(Microsoft.VisualBasic.Mid(NextLine, 2)) <span style="color:Green; Ignore 1st comma and use writeline to get LFCRs instead of write
ProgressBar1.Value = ProgressBar1.Value + 1
lblProgress.Text = Int((ProgressBar1.Value / ProgressBar1.Maximum) * 100)
Application.DoEvents()
<span style="color:Blue; Next
<span style="color:Green; Close the file
sw.Close()
lblSysMessage.Text = <span style="color:#A31515; "Grid data saved."
Application.DoEvents()
<span style="color:Blue; End <span style="color:Blue; If
<span style="color:Blue; End <span style="color:Blue; If
GC.Collect() <span style="color:Green; Force a garbage collection because we have likely done a LOT of string handling
<span style="color:Blue; End <span style="color:Blue; Sub
<span style="color:Blue; Private <span style="color:Blue; Sub OpenPlayListToolStripMenu_Click(<span style="color:Blue; ByVal sender <span style="color:Blue; As System.Object, <span style="color:Blue; ByVal e <span style="color:Blue; As System.EventArgs) <span style="color:Blue; Handles OpenPlayListToolStripMenu.Click
GC.Collect() <span style="color:Green; Force a garbage collection because we are potentially going to be doing a LOT of string handling
<span style="color:Blue; Dim myStream <span style="color:Blue; As Stream = <span style="color:Blue; Nothing, tags <span style="color:Blue; As List(Of <span style="color:Blue; String) = <span style="color:Blue; Nothing
<span style="color:Green; Open the datagrid
OpenFileDialog1.Title = <span style="color:#A31515; "Open a Playlist File"
OpenFileDialog1.CheckPathExists = <span style="color:Blue; True
OpenFileDialog1.DefaultExt = <span style="color:#A31515; "*.kpl"
OpenFileDialog1.InitialDirectory = Application.LocalUserAppDataPath
OpenFileDialog1.Filter = <span style="color:#A31515; "KAOS Playlist files (*.kpl)|*.kpl|All files (*.*)|*.*"
OpenFileDialog1.FilterIndex = 1
OpenFileDialog1.RestoreDirectory = <span style="color:Blue; True
OpenFileDialog1.FileName = <span style="color:#A31515; ""
<span style="color:Blue; If OpenFileDialog1.ShowDialog() = System.Windows.Forms.DialogResult.OK <span style="color:Blue; Then
<span style="color:Blue; Try
myStream = OpenFileDialog1.OpenFile()
<span style="color:Blue; If (myStream <span style="color:Blue; IsNot <span style="color:Blue; Nothing) <span style="color:Blue; Then
<span style="color:Blue; Dim sr <span style="color:Blue; As <span style="color:Blue; New StreamReader(OpenFileDialog1.FileName, detectEncodingFromByteOrderMarks:=<span style="color:Blue; True)
<span style="color:Blue; Dim line <span style="color:Blue; As <span style="color:Blue; String = <span style="color:#A31515; "", k <span style="color:Blue; As <span style="color:Blue; Integer = 0
<span style="color:Blue; Dim title <span style="color:Blue; As <span style="color:Blue; String = Space(30), Artist <span style="color:Blue; As <span style="color:Blue; String = Space(30), album <span style="color:Blue; As <span style="color:Blue; String = Space(30)
<span style="color:Blue; Do
line = sr.ReadLine()
lblSysMessage.Text = line <span style="color:Green; Display the line just read
<span style="color:Green; Parse and split the line here
<span style="color:Green; Wonder whats the best way to do in .net? Ask the forum
<span style="color:Green; For now, do this:
<span style="color:Green; title = Microsoft.VisualBasic.Left(line, 30)
<span style="color:Green; Artist = Microsoft.VisualBasic.Mid(line, 31, 30)
<span style="color:Green; album = Microsoft.VisualBasic.Mid(line, 61, 30)
<span style="color:Green; Ok the above lines work - but how on Earth do I add them to a blank data grid????
<span style="color:Green; Jesus, how do I read the damn file back into the gridarray?????
<span style="color:Green; Ive tried all sorts - but keep getting index exceptions or some such crap!
<span style="color:Green; Why have M$ made what used to be really tasks so damn hard?????
<span style="color:Green; Pulling my little remaining hair out here - this is why I keep geting fed up of .Net
<span style="color:Green; and go back to good ol VB6 or QB or whatever - using .Net is like being caught in
<span style="color:Green; a net - I guess its apply named!
<span style="color:Green; tags.Item(0).add = title
<span style="color:Green; tags.Item(1) = Artist
<span style="color:Green; tags.Item(2) = album
<span style="color:Green; Nope building up a List(Of strings) doont help either grrrrrrrrr
<span style="color:Green; songsDataGridView1.Rows.Add(tags)
<span style="color:Green; The following dont work either
<span style="color:Green; songsDataGridView1(k, 0).Value = title
<span style="color:Green; songsDataGridView1(k, 1).Value = Artist
<span style="color:Green; songsDataGridView1(k, 2).Value = album
<span style="color:Green; Watch it be something simple yet daft like songsDataGridView1(0,0).ReadFile
<span style="color:Green; or something
<span style="color:Green; Note: the grid is being written to the file just dandy - as notepad proves!
k = k + 1
Application.DoEvents()
<span style="color:Blue; Loop <span style="color:Blue; Until line <span style="color:Blue; Is <span style="color:Blue; Nothing
sr.Close()
<span style="color:Blue; End <span style="color:Blue; If
<span style="color:Blue; Catch Ex <span style="color:Blue; As Exception
MessageBox.Show(<span style="color:#A31515; "Cannot read file from disk. Original error: " & Ex.Message)
<span style="color:Blue; Finally
<span style="color:Green; Check this again, since we need to make sure we didnt throw an exception on open.
<span style="color:Blue; If (myStream <span style="color:Blue; IsNot <span style="color:Blue; Nothing) <span style="color:Blue; Then
myStream.Close()
<span style="color:Blue; End <span style="color:Blue; If
<span style="color:Blue; End <span style="color:Blue; Try
<span style="color:Blue; End <span style="color:Blue; If
<span style="color:Blue; End <span style="color:Blue; Sub
<span style="color:Blue; End <span style="color:Blue; Class
[/code]
<hr class="sig Big Al
View the full article
I decided to rewrite my project. Hit another snag. How do I write the contents from a datagrid to a file and back into the datagrid again later????? (Actually, Ive done the writing ok - but for the life of me cant get the data back into a blank datagrid.
The MS help on readline is about as much use as a chocolate fireguard.
Again, the problem is somehwere near the bottom of the listing.
Allan
Heres what I done so far:
<div style="color:Black;background-color:White; <pre>
<span style="color:Blue; Imports System
<span style="color:Blue; Imports System.IO
<span style="color:Blue; Imports System.Text
<span style="color:Blue; Public <span style="color:Blue; Class frmKAOS
<span style="color:Blue; Private <span style="color:Blue; Sub frmKAOS_FormClosing(<span style="color:Blue; ByVal sender <span style="color:Blue; As <span style="color:Blue; Object, <span style="color:Blue; ByVal e <span style="color:Blue; As System.Windows.Forms.FormClosingEventArgs) <span style="color:Blue; Handles <span style="color:Blue; Me.FormClosing
<span style="color:Blue; If MessageBox.Show(<span style="color:#A31515; "Are you sure that you want to exit KAOS5?", <span style="color:#A31515; "Exit KAOS5", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question) = DialogResult.Yes <span style="color:Blue; Then
e.Cancel = <span style="color:Blue; False
<span style="color:Blue; Else
e.Cancel = <span style="color:Blue; True
<span style="color:Blue; End <span style="color:Blue; If
<span style="color:Blue; End <span style="color:Blue; Sub
<span style="color:Blue; Private <span style="color:Blue; Sub Form1_Load(<span style="color:Blue; ByVal sender <span style="color:Blue; As System.Object, <span style="color:Blue; ByVal e <span style="color:Blue; As System.EventArgs) <span style="color:Blue; Handles <span style="color:Blue; MyBase.Load
<span style="color:Blue; Dim drvs() <span style="color:Blue; As <span style="color:Blue; String = System.IO.Directory.GetLogicalDrives()
<span style="color:Blue; Dim i <span style="color:Blue; As <span style="color:Blue; Long
<span style="color:Blue; Me.Text = <span style="color:#A31515; "KAOS5"
<span style="color:Blue; Me.StartPosition = FormStartPosition.CenterScreen
<span style="color:Green; Me.WindowState = FormWindowState.Maximized
OpenToolStripMenuItem.Enabled = <span style="color:Blue; False
PlayToolStripMenuItem.Enabled = <span style="color:Blue; False
PauseToolStripMenuItem.Enabled = <span style="color:Blue; False
ResumeToolStripMenuItem.Enabled = <span style="color:Blue; False
StopToolStripMenuItem.Enabled = <span style="color:Blue; False
CloseToolStripMenuItem.Enabled = <span style="color:Blue; False
SaveToolStripMenuItem.Enabled = <span style="color:Blue; False
songsDataGridView1.SelectionMode = DataGridViewSelectionMode.FullRowSelect
songsDataGridView1.MultiSelect = <span style="color:Blue; False
tbVolume.Enabled = 0
tbVolume.Minimum = 0
tbVolume.Maximum = 1000
tbVolume.Value = 0
lblVolume.Text = <span style="color:#A31515; "0"
tbVolume.TickFrequency = 100
Timer1.Interval = 900 <span style="color:Green; Roughly every sec (even though its in millisecs I prefer using 900 to 1000)
Timer1.Enabled = <span style="color:Blue; False
lblNoOfFiles.Text = <span style="color:#A31515; "0"
lblProgress.Text = <span style="color:#A31515; "0"
songsDataGridView1.ScrollBars = ScrollBars.Both
songsDataGridView1.Size = <span style="color:Blue; New Size(<span style="color:Blue; Me.Width - 50, <span style="color:Blue; Me.Height - (ProgressBar1.Height + 230))
songsDataGridView1.ColumnCount = 12 <span style="color:Green; not 13 as Im not showing the tag - nothing to do with being superstitious about 13
songsDataGridView1.Columns(0).Width = 30 * 16
songsDataGridView1.Columns(1).Width = 30 * 16
songsDataGridView1.Columns(2).Width = 30 * 16
<span style="color:Green; songsDataGridView1.Columns(3).Width = 4 * 16
songsDataGridView1.Columns(4).Width = 30 * 16
<span style="color:Green; songsDataGridView1.Columns(5).Width = 1 * 16
songsDataGridView1.Columns(6).Width = 3 * 16
<span style="color:Green; songsDataGridView1.Columns(7).Width = 1 * 16
songsDataGridView1.Columns(8).Width = 30 * 16
songsDataGridView1.Columns(9).Width = 256 * 16
<span style="color:Green; The column widths are in pixels - Ive allowed 16 pixels per character
<span style="color:Green; songsDataGridView1.Columns(0).Name = "TAG" Not showing the tag
songsDataGridView1.Columns(0).Name = <span style="color:#A31515; "Title"
songsDataGridView1.Columns(1).Name = <span style="color:#A31515; "Artist"
songsDataGridView1.Columns(2).Name = <span style="color:#A31515; "Album"
songsDataGridView1.Columns(3).Name = <span style="color:#A31515; "Year"
songsDataGridView1.Columns(4).Name = <span style="color:#A31515; "Comment"
songsDataGridView1.Columns(5).Name = <span style="color:#A31515; "Zero Byte"
songsDataGridView1.Columns(6).Name = <span style="color:#A31515; "#"
songsDataGridView1.Columns(7).Name = <span style="color:#A31515; "Genre Byte"
songsDataGridView1.Columns(8).Name = <span style="color:#A31515; "Genre String"
songsDataGridView1.Columns(9).Name = <span style="color:#A31515; "Path"
songsDataGridView1.Columns(10).Name = <span style="color:#A31515; "Size (in bytes)"
songsDataGridView1.Columns(11).Name = <span style="color:#A31515; "Playing time"
<span style="color:Green; Populate the drive combobox with a list of logical drives
<span style="color:Blue; For i = drvs.GetLowerBound(0) <span style="color:Blue; To drvs.GetUpperBound(0)
cmbDrives.Items.Add(drvs(i))
<span style="color:Blue; Next i
cmbDrives.SelectedIndex = 0
txtFileExtension.Text = <span style="color:#A31515; "mp3" <span style="color:Green; Default extension
<span style="color:Blue; End <span style="color:Blue; Sub
<span style="color:Blue; Private <span style="color:Blue; Sub btnExit_Click(<span style="color:Blue; ByVal sender <span style="color:Blue; As System.Object, <span style="color:Blue; ByVal e <span style="color:Blue; As System.EventArgs) <span style="color:Blue; Handles btnExit.Click
Application.<span style="color:Blue; Exit()
<span style="color:Blue; End <span style="color:Blue; Sub
<span style="color:Blue; Private <span style="color:Blue; Sub btnSearch_Click(<span style="color:Blue; ByVal sender <span style="color:Blue; As System.Object, <span style="color:Blue; ByVal e <span style="color:Blue; As System.EventArgs) <span style="color:Blue; Handles btnSearch.Click
<span style="color:Blue; Me.DialogResult = System.Windows.Forms.DialogResult.OK
<span style="color:Blue; Dim tags <span style="color:Blue; As List(Of <span style="color:Blue; String), datarow() <span style="color:Blue; As <span style="color:Blue; String
<span style="color:Blue; Dim PlayingTimeColIndex <span style="color:Blue; As <span style="color:Blue; Integer = 11, CurrentRowIndex <span style="color:Blue; As <span style="color:Blue; Integer = 0
<span style="color:Blue; Dim filename <span style="color:Blue; As <span style="color:Blue; String, ret <span style="color:Blue; As <span style="color:Blue; Integer, lpStrReturnString <span style="color:Blue; As <span style="color:Blue; String = Space(128)
<span style="color:Green; <summary>
<span style="color:Green; Entry point that uses the recursive search directory function.
<span style="color:Green;
<span style="color:Green; Very important note:
<span style="color:Green; By design, this routine DOES NOT CLEAR the grid of found files BECAUSE the user may want to add
<span style="color:Green; files from multiple drive searches (or even want a list of duplicated files - who knows?)!
<span style="color:Green; There is a separate Clear list button to clear the datagrid of files - but its up to the user to
<span style="color:Green; choose to use it - or not.
<span style="color:Green; </summary>
<span style="color:Green; Get recursive List of all files starting in this directory.
<span style="color:Blue; Dim drv <span style="color:Blue; As <span style="color:Blue; String = cmbDrives.SelectedItem
<span style="color:Blue; Dim start <span style="color:Blue; As <span style="color:Blue; String = <span style="color:#A31515; ""
<span style="color:Blue; Dim ext <span style="color:Blue; As <span style="color:Blue; String = <span style="color:#A31515; ""
<span style="color:Blue; If drv = <span style="color:#A31515; "" <span style="color:Blue; Then
drv = <span style="color:#A31515; "c:"
<span style="color:Blue; End <span style="color:Blue; If
<span style="color:Blue; If Microsoft.VisualBasic.Right$(drv, 1) <> <span style="color:#A31515; "" <span style="color:Blue; Then
drv = drv & <span style="color:#A31515; ""
<span style="color:Blue; End <span style="color:Blue; If
<span style="color:Blue; Me.Cursor = Cursors.WaitCursor
lblSysMessage.Text = <span style="color:#A31515; "Searching...."
Application.DoEvents()
<span style="color:Green; Setup the debug window - remember to take out this code in the release version
Debug.Close()
Debugger.Launch()
Debug.Flush()
Debug.AutoFlush() = <span style="color:Blue; True
start = drv
<span style="color:Green; ToDo: I should validate the start folder here to see if its a valid one
<span style="color:Blue; If txtStartFolder.Text <> <span style="color:#A31515; "" <span style="color:Blue; Then
start = start & txtStartFolder.Text
<span style="color:Blue; End <span style="color:Blue; If
ext = txtFileExtension.Text
<span style="color:Blue; If Microsoft.VisualBasic.Left(ext, 2) <> <span style="color:#A31515; "*." <span style="color:Blue; Then
ext = <span style="color:#A31515; "*." & ext <span style="color:Green; Extension should really be validated here
<span style="color:Blue; End <span style="color:Blue; If
GC.Collect() <span style="color:Green; Force a garbage collection because we are potentially going to be doing a LOT of string handling
lblSysMessage.Text = <span style="color:#A31515; "Starting search of directory " & start
<span style="color:Blue; Dim list <span style="color:Blue; As List(Of <span style="color:Blue; String) = GetFilesRecursive(start, ext)
MsgBox(<span style="color:#A31515; "Search of " & start & <span style="color:#A31515; " done. Starting to process the found files.")
Application.DoEvents()
lblSysMessage.Text = <span style="color:#A31515; "Processing found files"
ProgressBar1.Minimum = 0
ProgressBar1.Maximum = list.<span style="color:Blue; Count
ProgressBar1.Value = 0
<span style="color:Blue; If list.<span style="color:Blue; Count = 0 <span style="color:Blue; Then
lblSysMessage.Text = <span style="color:#A31515; "No such start directory"
<span style="color:Blue; Me.Cursor = Cursors.<span style="color:Blue; Default
<span style="color:Blue; Exit <span style="color:Blue; Sub
<span style="color:Blue; End <span style="color:Blue; If
lblNoOfFiles.Text = list.<span style="color:Blue; Count
<span style="color:Blue; For <span style="color:Blue; Each path <span style="color:Blue; In list
tags = ReadTags(path)
ProgressBar1.Value = ProgressBar1.Value + 1
lblProgress.Text = Int((ProgressBar1.Value / ProgressBar1.Maximum) * 100)
datarow = tags.ToArray
<span style="color:Blue; If tags.<span style="color:Blue; Count > 0 <span style="color:Blue; Then
songsDataGridView1.Rows.Add(datarow)
<span style="color:Green; I find that getting the playing times makes the initial processing of the files
<span style="color:Green; waaaaaaay too long unfortunately
<span style="color:Green; (it increases the processing time per file by a factor of about 10x (my impression) which
<span style="color:Green; would normally be unacceptable, but its ok for a first time use and then the user has the
<span style="color:Green; option to save the processed list to a file or to read the list back from a file in the
<span style="color:Green; future.
<span style="color:Green; Surprisingly, although displaying the name of the file being processed slows things down
<span style="color:Green; a tad even more, psychologically it makes the wait more tolerable since the user actually sees
<span style="color:Green; that things are happening - and so the wait becomes a tad more tolerable.
<span style="color:Green;
filename = songsDataGridView1(9, CurrentRowIndex).Value
ret = mciSendString(<span style="color:#A31515; "Open " & Chr(34) & filename & Chr(34) & <span style="color:#A31515; " alias audio wait", <span style="color:Blue; CStr(0), 0, 0)
ret = mciSendString(<span style="color:#A31515; "set audio time milliseconds wait", <span style="color:Blue; CStr(0), 0, 0)
ret = mciSendString(<span style="color:#A31515; "status audio length wait", lpStrReturnString, Len(lpStrReturnString), 0)
<span style="color:Green; Note: the plaing time cannot be determeined for all files for some strange reason
<span style="color:Blue; If ret <> 0 <span style="color:Blue; Then
lblSysMessage.Text = <span style="color:#A31515; "Unable to set/get time format and playing time for " & filename
songsDataGridView1(PlayingTimeColIndex, CurrentRowIndex).Value = <span style="color:#A31515; "Unknown"
<span style="color:Blue; Else
<span style="color:Blue; Dim PT <span style="color:Blue; As <span style="color:Blue; String = ConvertToShortTime(Trim(lpStrReturnString))
songsDataGridView1(PlayingTimeColIndex, CurrentRowIndex).Value = PT
lblSysMessage.Text = <span style="color:#A31515; "Playing time for " & filename & <span style="color:#A31515; " is " & PT
<span style="color:Blue; End <span style="color:Blue; If
CurrentRowIndex = CurrentRowIndex + 1
ret = mciSendString(<span style="color:#A31515; "close audio wait", <span style="color:Blue; CStr(0), 0, 0)
<span style="color:Green; Im concerned that with thousands of files to process I have to try to keep the memory
<span style="color:Green; footprint/usage down. I wish that the ID3 v1.0 specification included a milliseconds playing
<span style="color:Green; time field in the ID3 frame - then getting the playing times initially wouldnt be a hassle.
<span style="color:Green; I know that one of the proposed extended ID3 tags specs. do - but so few MP3s use them (and
<span style="color:Green; it would require IF tests per file hence thousands of extra IFs being executed)
<span style="color:Green; that it isnt really worth checking for extended specification MP3 tags.
<span style="color:Green;
<span style="color:Green; Coding KAOS makes me appreciate wmp even more - despite its shortcomings!
<span style="color:Green;
Application.DoEvents()
<span style="color:Blue; End <span style="color:Blue; If
<span style="color:Blue; Next
<span style="color:Green; Write total number of paths found.
lblSysMessage.Text = <span style="color:#A31515; "Processing of found files done: " & songsDataGridView1.Rows.<span style="color:Blue; Count - 1 & <span style="color:#A31515; " files found. You are advised to save the list."
MsgBox(<span style="color:#A31515; "Processing of found files done: " & songsDataGridView1.Rows.<span style="color:Blue; Count - 1 & <span style="color:#A31515; " files found. You are advised to save the list.")
<span style="color:Blue; Me.Cursor = Cursors.<span style="color:Blue; Default
<span style="color:Green; MsgBox("Select a file with a left click, and then right click on that file to play it etc.", MsgBoxStyle.OkOnly, "Help") Hopefully, we wont need a left click now
MsgBox(<span style="color:#A31515; "Select a file with a right click to play it etc.", MsgBoxStyle.OkOnly, <span style="color:#A31515; "Help") <span style="color:Green; Hopefully, this will be true
Application.DoEvents()
OpenToolStripMenuItem.Enabled = <span style="color:Blue; True
PlayToolStripMenuItem.Enabled = <span style="color:Blue; False
PauseToolStripMenuItem.Enabled = <span style="color:Blue; False
ResumeToolStripMenuItem.Enabled = <span style="color:Blue; False
StopToolStripMenuItem.Enabled = <span style="color:Blue; False
CloseToolStripMenuItem.Enabled = <span style="color:Blue; False
SaveToolStripMenuItem.Enabled = <span style="color:Blue; False
Debug.Close()
<span style="color:Green; Update the files list
GC.Collect() <span style="color:Green; Force a garbage collection because we have likely done a LOT of string handling
<span style="color:Blue; End <span style="color:Blue; Sub
<span style="color:Blue; Private <span style="color:Blue; Sub SavePlaylistToolStripMenu_Click(<span style="color:Blue; ByVal sender <span style="color:Blue; As System.Object, <span style="color:Blue; ByVal e <span style="color:Blue; As System.EventArgs) <span style="color:Blue; Handles SavePlaylistToolStripMenu.Click
<span style="color:Green; Check if any files are in the datagrid
<span style="color:Blue; If songsDataGridView1.RowCount > 0 <span style="color:Blue; Then
GC.Collect() <span style="color:Green; Force a garbage collection because we are potentially going to be doing a LOT of string handling
<span style="color:Green; Save the datagrid
SaveFileDialog1.Filter = <span style="color:#A31515; "KAOS Playlist|*.kpl|Text|*.txt"
SaveFileDialog1.Title = <span style="color:#A31515; "Save a Playlist File"
SaveFileDialog1.CheckPathExists = <span style="color:Blue; True
SaveFileDialog1.DefaultExt = <span style="color:#A31515; "*.kpl"
SaveFileDialog1.InitialDirectory = Application.LocalUserAppDataPath
SaveFileDialog1.FileName = <span style="color:#A31515; ""
SaveFileDialog1.ShowDialog()
<span style="color:Green; If the file name is not an empty string open it for saving.
<span style="color:Blue; If SaveFileDialog1.FileName <> <span style="color:#A31515; "" <span style="color:Blue; Then
ProgressBar1.Minimum = 0
ProgressBar1.Maximum = songsDataGridView1.Rows.<span style="color:Blue; Count
ProgressBar1.Value = 0
<span style="color:Blue; Dim path <span style="color:Blue; As <span style="color:Blue; String = SaveFileDialog1.FileName
<span style="color:Green; Delete the current file if it exists.
<span style="color:Blue; If File.Exists(path) <span style="color:Blue; Then
File.Delete(path)
<span style="color:Blue; End <span style="color:Blue; If
<span style="color:Green; Create the new file -- note, saved as plain ASCII so that the user can view it in notepad, etc.
<span style="color:Blue; Dim NextLine <span style="color:Blue; As <span style="color:Blue; String = <span style="color:#A31515; ""
<span style="color:Blue; Dim fs <span style="color:Blue; As <span style="color:Blue; New FileStream(path, FileMode.Append, FileAccess.Write, FileShare.Write)
fs.Close()
<span style="color:Blue; Dim sw <span style="color:Blue; As <span style="color:Blue; New StreamWriter(path, <span style="color:Blue; True, Encoding.ASCII)
lblSysMessage.Text = <span style="color:#A31515; "Saving grid data..."
<span style="color:Blue; For rows = 0 <span style="color:Blue; To songsDataGridView1.Rows.<span style="color:Blue; Count - 1
NextLine = <span style="color:#A31515; "" <span style="color:Green; An extremely important line - do NOT forget to nullify this string
<span style="color:Green; each time in the loop before adding columns - otherwise the processing will really be VERY,
<span style="color:Green; VERY slow and the resultant file will likely be megabytes of text rather than a few kbs or 100s kbs.
<span style="color:Green; Get the column content values (separated by commas)
<span style="color:Blue; For column = 0 <span style="color:Blue; To 11
NextLine = NextLine & <span style="color:#A31515; "," & songsDataGridView1(column, rows).Value
<span style="color:Blue; Next
<span style="color:Green; Write the line of comma delineated values
lblSysMessage.Text = NextLine
sw.WriteLine(Microsoft.VisualBasic.Mid(NextLine, 2)) <span style="color:Green; Ignore 1st comma and use writeline to get LFCRs instead of write
ProgressBar1.Value = ProgressBar1.Value + 1
lblProgress.Text = Int((ProgressBar1.Value / ProgressBar1.Maximum) * 100)
Application.DoEvents()
<span style="color:Blue; Next
<span style="color:Green; Close the file
sw.Close()
lblSysMessage.Text = <span style="color:#A31515; "Grid data saved."
Application.DoEvents()
<span style="color:Blue; End <span style="color:Blue; If
<span style="color:Blue; End <span style="color:Blue; If
GC.Collect() <span style="color:Green; Force a garbage collection because we have likely done a LOT of string handling
<span style="color:Blue; End <span style="color:Blue; Sub
<span style="color:Blue; Private <span style="color:Blue; Sub OpenPlayListToolStripMenu_Click(<span style="color:Blue; ByVal sender <span style="color:Blue; As System.Object, <span style="color:Blue; ByVal e <span style="color:Blue; As System.EventArgs) <span style="color:Blue; Handles OpenPlayListToolStripMenu.Click
GC.Collect() <span style="color:Green; Force a garbage collection because we are potentially going to be doing a LOT of string handling
<span style="color:Blue; Dim myStream <span style="color:Blue; As Stream = <span style="color:Blue; Nothing, tags <span style="color:Blue; As List(Of <span style="color:Blue; String) = <span style="color:Blue; Nothing
<span style="color:Green; Open the datagrid
OpenFileDialog1.Title = <span style="color:#A31515; "Open a Playlist File"
OpenFileDialog1.CheckPathExists = <span style="color:Blue; True
OpenFileDialog1.DefaultExt = <span style="color:#A31515; "*.kpl"
OpenFileDialog1.InitialDirectory = Application.LocalUserAppDataPath
OpenFileDialog1.Filter = <span style="color:#A31515; "KAOS Playlist files (*.kpl)|*.kpl|All files (*.*)|*.*"
OpenFileDialog1.FilterIndex = 1
OpenFileDialog1.RestoreDirectory = <span style="color:Blue; True
OpenFileDialog1.FileName = <span style="color:#A31515; ""
<span style="color:Blue; If OpenFileDialog1.ShowDialog() = System.Windows.Forms.DialogResult.OK <span style="color:Blue; Then
<span style="color:Blue; Try
myStream = OpenFileDialog1.OpenFile()
<span style="color:Blue; If (myStream <span style="color:Blue; IsNot <span style="color:Blue; Nothing) <span style="color:Blue; Then
<span style="color:Blue; Dim sr <span style="color:Blue; As <span style="color:Blue; New StreamReader(OpenFileDialog1.FileName, detectEncodingFromByteOrderMarks:=<span style="color:Blue; True)
<span style="color:Blue; Dim line <span style="color:Blue; As <span style="color:Blue; String = <span style="color:#A31515; "", k <span style="color:Blue; As <span style="color:Blue; Integer = 0
<span style="color:Blue; Dim title <span style="color:Blue; As <span style="color:Blue; String = Space(30), Artist <span style="color:Blue; As <span style="color:Blue; String = Space(30), album <span style="color:Blue; As <span style="color:Blue; String = Space(30)
<span style="color:Blue; Do
line = sr.ReadLine()
lblSysMessage.Text = line <span style="color:Green; Display the line just read
<span style="color:Green; Parse and split the line here
<span style="color:Green; Wonder whats the best way to do in .net? Ask the forum
<span style="color:Green; For now, do this:
<span style="color:Green; title = Microsoft.VisualBasic.Left(line, 30)
<span style="color:Green; Artist = Microsoft.VisualBasic.Mid(line, 31, 30)
<span style="color:Green; album = Microsoft.VisualBasic.Mid(line, 61, 30)
<span style="color:Green; Ok the above lines work - but how on Earth do I add them to a blank data grid????
<span style="color:Green; Jesus, how do I read the damn file back into the gridarray?????
<span style="color:Green; Ive tried all sorts - but keep getting index exceptions or some such crap!
<span style="color:Green; Why have M$ made what used to be really tasks so damn hard?????
<span style="color:Green; Pulling my little remaining hair out here - this is why I keep geting fed up of .Net
<span style="color:Green; and go back to good ol VB6 or QB or whatever - using .Net is like being caught in
<span style="color:Green; a net - I guess its apply named!
<span style="color:Green; tags.Item(0).add = title
<span style="color:Green; tags.Item(1) = Artist
<span style="color:Green; tags.Item(2) = album
<span style="color:Green; Nope building up a List(Of strings) doont help either grrrrrrrrr
<span style="color:Green; songsDataGridView1.Rows.Add(tags)
<span style="color:Green; The following dont work either
<span style="color:Green; songsDataGridView1(k, 0).Value = title
<span style="color:Green; songsDataGridView1(k, 1).Value = Artist
<span style="color:Green; songsDataGridView1(k, 2).Value = album
<span style="color:Green; Watch it be something simple yet daft like songsDataGridView1(0,0).ReadFile
<span style="color:Green; or something
<span style="color:Green; Note: the grid is being written to the file just dandy - as notepad proves!
k = k + 1
Application.DoEvents()
<span style="color:Blue; Loop <span style="color:Blue; Until line <span style="color:Blue; Is <span style="color:Blue; Nothing
sr.Close()
<span style="color:Blue; End <span style="color:Blue; If
<span style="color:Blue; Catch Ex <span style="color:Blue; As Exception
MessageBox.Show(<span style="color:#A31515; "Cannot read file from disk. Original error: " & Ex.Message)
<span style="color:Blue; Finally
<span style="color:Green; Check this again, since we need to make sure we didnt throw an exception on open.
<span style="color:Blue; If (myStream <span style="color:Blue; IsNot <span style="color:Blue; Nothing) <span style="color:Blue; Then
myStream.Close()
<span style="color:Blue; End <span style="color:Blue; If
<span style="color:Blue; End <span style="color:Blue; Try
<span style="color:Blue; End <span style="color:Blue; If
<span style="color:Blue; End <span style="color:Blue; Sub
<span style="color:Blue; End <span style="color:Blue; Class
[/code]
<hr class="sig Big Al
View the full article