do you have any idea how i can save contents of list box by a common dialogue?
I know how to di it when I have a rich text box;
Code:
With CommonDialog1 'use this because we will have a lot of code with the box
.DialogTitle = "Open" 'this sets the caption for the title bar on the dialog
.InitDir = "C:\" 'this sets the initial director for the dialog box
.Filter = "Text Files (*.txt)|*.txt|All Files (*.*)|*.*"
'the filter property is what specifies which file types to display. The
'(*.txt) is not necessary.
'as you can see, the file name comes first then the *.type comes
'next after the |. This is important
.ShowOpen 'this event actually displays the open dialog box
End With 'Close the with statement
RTB1.LoadFile CommonDialog1.FileName
Private Sub Command2_Click()
Dim filenum As Integer, i As Long
CommonDialog1.Filter = "Text File|*.txt"
CommonDialog1.DefaultExt = ".txt"
CommonDialog1.FileName = "*.txt"
CommonDialog1.ShowSave
FileName = CommonDialog1.FileName
If CommonDialog1.CancelError = True Then Exit Sub
filenum = FreeFile
On Error GoTo FileError
Open FileName For Output As filenum
For i = 0 To List1.ListCount - 1
Print #filenum, List1.List(i)
Next i
Close filenum
Exit Sub
FileError:
MsgBox Err.Description, vbCritical, "Error Number: " & Err.Number
Exit Sub
End Sub
Or you can call these with the common dialogue i.e
Code:
Private Sub Command2_Click()
Dim filenum As Integer, i As Long
CommonDialog1.Filter = "Text File|*.txt"
CommonDialog1.DefaultExt = ".txt"
CommonDialog1.FileName = "*.txt"
CommonDialog1.ShowSave
FileName = CommonDialog1.FileName
If CommonDialog1.CancelError = True Then Exit Sub
On Error GoTo FileError
SaveListBox "C:/TheList.txt", List1
'OR
Loadlistbox "C:/TheList.txt", List1
Exit Sub
FileError:
MsgBox Err.Description, vbCritical, "Error Number: " & Err.Number
End Sub
Public Sub SaveListBox(theFile As String, TheList As ListBox)
Dim i As Long, fNum As Integer
On Error Resume Next
fNum = FreeFile
Open theFile$ For Output As #fNum
For i = 0 To TheList.ListCount - 1
Print #fNum, TheList.List(savelist&)
Next i
Close #fNum
End Sub
Public Sub Loadlistbox(theFile As String, TheList As ListBox)
Dim MyString As String, fNum As Integer
On Error Resume Next
fNum = FreeFile
Open theFile$ For Input As #fNum
While Not EOF(1)
Input #fNum, MyString$
DoEvents
TheList.AddItem MyString$
Wend
Close #fNum
End Sub
.
The answer to your question is Here
And here
C:\Program Files\Microsoft Visual Studio\MSDN98\98VSa\1033\SAMPLES\VB98
Please go to the "Thread Tools" menu at the top of this Thread, and click "Mark Thread Resolved" when you have your answer.
So I can fine the answer when I need it.
So please install VB6 service pack 6 as its the latest and last supported service pack MS will ever make. http://support.microsoft.com/kb/q198880/ I'm sure this will fix your issue
The only reason some people get lost in thought is because it’s unfamiliar territory. —Paul Fix
No prob!
Here's a little more about the CommonDialog, from (MSDN)
ShowColor, ShowFont, ShowHelp, ShowOpen, ShowPrinter, ShowSave Methods Example
This example uses the CommonDialog control and the ShowColor, ShowFont, ShowHelp, ShowOpen, ShowPrinter, and ShowSave methods to display the common dialog boxes. To try this example, paste the code into the Declarations section of a form with CommandButton, OptionButton (set the option button's Index property to 0), and CommonDialog controls. Press F5 and select the option button for the common dialog box you want and choose the command button.
Code:
Private Sub Form_Paint ()
Static FlagFormPainted As Integer
' When form is painting for first time,
If FlagFormPainted <> True Then
For i = 1 To 5
Load Option1(i) ' Add five option buttons to array.
Option1(i).Top = Option1(i - 1).Top + 350
Option1(i).Visible = True
Next i
Option1(0).Caption = "Open" ' Put caption on each option button.
Option1(1).Caption = "Save"
Option1(2).Caption = "Color"
Option1(3).Caption = "Font"
Option1(4).Caption = "Printer"
Option1(5).Caption = "Help"
Command1.Caption = "Show Dlg" ' Label command button.
FlagFormPainted = True ' Form is done painting.
End If
End Sub
Private Sub Command1_Click ()
If Option1(0).Value Then ' If Open option button selected,
CommonDialog1.ShowOpen ' display Open common dialog box.
ElseIf Option1(1).Value Then ' Or,
CommonDialog1.ShowSave ' display Save common dialog box.
ElseIf Option1(2).Value Then ' Or,
CommonDialog1.ShowColor ' display Color common dialog box.
ElseIf Option1(3).Value Then ' Or,
CommonDialog1.Flags = cdlCFBoth ' Flags property must be set
' to cdlCFBoth, ' cdlCFPrinterFonts,
' or cdlCFScreenFonts before ' using ShowFont method.
CommonDialog1.ShowFont ' Display Font common dialog box.
ElseIf Option1(4).Value Then ' Or,
CommonDialog1.ShowPrinter ' display Printer common dialog box.
ElseIf Option1(5).Value Then ' Or,
CommonDialog1.HelpFile = "VB5.hlp"
CommonDialog1.HelpCommand = cdlHelpContents
CommonDialog1.ShowHelp ' Display Visual Basic Help contents topic.
End If
End Sub