How do I do this? I want the user to be able to "save as" and not just save it to a file already specified.
Printable View
How do I do this? I want the user to be able to "save as" and not just save it to a file already specified.
Use the commondialog, you will find it in your components.
casey.
But what is the vb code I have to use for the command button?
try this
you could also set some flags with the commondialog, have a look in your help files.VB Code:
Dim str1 As String, i As Integer On Error GoTo errorhandler With CommonDialog1 .CancelError = True .DialogTitle = "Select Location to Save to" .Filter = "Text File (*.txt)|*.txt" .InitDir = App.Path .ShowSave str1 = .FileName End With Open str1 For Output As #1 For i = 0 To List1.ListCount - 1 Print #1, List1.List(i) Next i Close #1 Exit Sub errorhandler: End Sub
casey.
Command1 Loads you file to Listbox, Command2 Saves your file to text file..
You choose file to open and file to save
VB Code:
Private Function FileOpen() As String With CommonDialog1 On Error GoTo Err_Handler .Filter = ".TXT Files .txt|*.txt" .InitDir = App.Path .Flags = &H1000 Or &H4 Or &H2000 .CancelError = True .ShowOpen FileOpen = .FileName End With Exit Function Err_Handler: End Function Private Function FileSaveAs() As String On Error GoTo Err_Handler With CommonDialog1 .Filter = ".TXT Files .txt|*.txt" .InitDir = App.Path .Flags = &H2 Or &H4 Or &H2000 .CancelError = True .ShowSave FileSaveAs = .FileName End With Exit Function Err_Handler: End Function Private Sub Command1_Click() Dim lFile As String Dim lFileContent As String Dim lArrFile() As String Dim i As Long List1.Clear lFile = FileOpen If Trim$(lFile) <> vbNullString Then Open lFile For Binary As #1 lFileContent = Space(LOF(1)) Get #1, , lFileContent Close #1 lArrFile = Split(lFileContent, vbNewLine) For i = 0 To UBound(lArrFile) List1.AddItem lArrFile(i) Next End If lFileContent = Empty Erase lArrFile End Sub Private Sub Command2_Click() Dim lStrFile As String Dim i As Long lStrFile = FileSaveAs If Trim$(lStrFile) <> vbNullString Then Open lStrFile For Output As #1 For i = 0 To List1.ListCount - 1 Print #1, List1.List(i) Next Close #1 End If End Sub
Thanks!
How would I save a textbox? Nearly the same code, I assume. I just don't know what to change ListCount from
Help?VB Code:
For i = 0 To Text2.ListCount - 1
you wouldnt need the loop.
Print #1, Text1.Text
casey.
Textboxes doesn't have a listcount, save its value directly, like:
Print #1, Text2.Text
That works, thanks.
How would I clear three textboxes and two ListBoses with one click?
For textboxes:
Text1.Text = VbNullString
For Listboxes:
List1.Clear
Wonderful. That was my last question, I swear.
Thanks for all your help.