[02/03] File.AppendText problem
Hi folks. Can't seem to understand why there is an extra line created with my appendtext code at the end. This creates empty records at the top of the listbox after every new phone list added.
I also have a problem with the inputbox message display where there are a number of "," appearing!
The (brief) pseudocode is:-
Open file with Phone Dir's
Display Ph Dir for use to choose via input box
If PD not exist ask if user wants to create it
If yes then create file & add to PD list
BTW I have a Dim sw As Streamwriter at the top. (I may put it with the actual AppendText code for clarity later on.)
VB Code:
SortData(temp, counter) 'sort data
lstOutput.Items.Clear() 'Clear listbox
'Display PhDir List
For i = 1 To counter
lstOutput.Items.Add(temp(i))
Next
'Create list for input box for user to choose/create phonelist
For i = 1 To counter
dirList = dirList & ", " & temp(i)
Next
'prompt user for phonelist
prompt = "Enter phone directory: " & dirList
fn = InputBox(prompt).ToUpper
'search for name
'Search for file
If File.Exists(f & fn) Then
sw = File.AppendText(f & fn)
sw.WriteLine(name)
sw.WriteLine(number)
sw.Close()
Else 'If file does not exist ask user if they want to create it
r = MsgBox("File Not Found! Do you want create a new phonelist?", MsgBoxStyle.YesNoCancel, vbYesNoCancel)
If r = vbYes Then
sw = File.AppendText(f & fn)
sw.WriteLine(name)
sw.WriteLine(number)
sw.Close()
End If
Dim exists As Boolean = False
For i = 1 To counter
If fn = temp(i) Then
exists = True
End If
Next
If exists = False Then 'Write new PhDir to PhDir file list
sw = File.AppendText(f & pL)
sw.WriteLine(fn)
sw.Close()
Else
End If
End If