Connecting Tech Pros Worldwide Forums | Help | Site Map

How to handle user input file name

Newbie
 
Join Date: Oct 2007
Posts: 1
#1: Oct 30 '07
Hi all,
I'm new to VB, using VB.Net express edition. I'm collecting data from a data acquisition card and writing the data to a .txt file. I have an input box for the user to input a file name. If the file already exists I want to warn the user and ask if they want to over write the file. I'm using MsgBox style YesNo. If they say yes, no problem. But if they say no, what do I do? I did a bit of searching but couldn't find a recommended way of handling this. I think I am digging a deeper hole....Any suggestions?
Thanks,

Code is below:

Dim LSVDAQ As String

'Read file name
LSVDAQ = FileNameBox.Text

'check here that filename box is not null
If LSVDAQ = "" Then
MsgBox("You must enter a filename")
End

ElseIf My.Computer.FileSystem.FileExists(LSVDAQ) Then
MsgBox("!!! File already exists, overwrite?", MsgBoxStyle.YesNo)
If MsgBoxResult.No Then
LSVDAQ = InputBox("Enter new filename", "", LSVDAQ, , )
MsgBox(LSVDAQ)

ElseIf MsgBoxResult.Yes Then
'no operation
End If

Else
MsgBox("File " & LSVDAQ & " will be created")
End If
Reply