Hey, i am working on a project that saves and load text files just so i can get the coding down for later projects. I am able to specify the location of the file to load eg. the Load File Dialog and the user specifies the location of the text file. What i needed help with is the the save file dialog, i want to be able to choose where the program saves too. This is the code i have for the save file dialog so far:
Private Sub SaveDoc()
Dim NameOfDoc As String = txtAcc.Text & ".txt" 'Takes a substring of the title bar, the name of the file to be saved
Dim FileNum As String = FreeFile()
If NameOfDoc = "Template.txt" Then 'If it's a template, then run the SaveAsDoc() routined
SaveAsDoc()
Else 'Otherwise save all the neccessary data into the text file.
FileOpen(FileNum, NameOfDoc, OpenMode.Output)
PrintLine(FileNum, "Account: " & txtAcc.Text & vbCrLf & "Username: " & txtUser.Text & vbCrLf & "Password: " & txtCheese.Text)
FileClose(FileNum)
MsgBox("Details Saved")
End If
End Sub
Private Sub SaveAsDoc()
dlgSave.FileName = txtAcc.Text 'Sets the filename for saving
If dlgSave.ShowDialog = Windows.Forms.DialogResult.OK Then
Me.Text = txtAcc.Text & " - " & txtUser.Text & ".txt" 'Sets the name of the form
SaveDoc() 'Runs the routine SaveDoc()
End If
End Sub