|
-
Nov 21st, 2004, 03:59 PM
#1
Thread Starter
New Member
save open command
need help with the save & open command
have the following code
Private Sub Command1_Click()
CommonDialog1.Filter = "*.dat"
CommonDialog1.FilterIndex = 0
CommonDialog1.FileName = CommonDialog1.Filter
CommonDialog1.ShowSave
If CommonDialog1.FileName = "" Then Exit Sub
If InStr(CommonDialog1.FileName, "*") <> 0 Then Exit Sub
z$ = CommonDialog1.FileName
If InStrRev(z$, ".") = 0 Then z$ = z$ + ".dat"
If Dir(z$, vbArchive) <> "" Then
r = MsgBox("This file existe. Erase old data???", vbCritical Or vbYesNo, "File Existe")
If r <> 6 Then Exit Sub
End If
Close
Open z$ For Output As #1
For a = 1 To 6
Print #1, lblanswer(a)
Next
For a = 1 To 12
Print #1, txtdata(a)
Next
Close
please help
-
Nov 21st, 2004, 04:23 PM
#2
-
Nov 21st, 2004, 04:38 PM
#3
I can't find any obvious errors. You don't need to check if the file exists if you use. And you don't need to check the file extension either:
VB Code:
CommonDialog1.Flags = cdlOFNOverwritePrompt + _
cdlOFNPathMustExist
CommonDialog1.DefaultExt = "dat"
Keith
I've been programming with VB for 25 years. Started with VB4 16bit Pro, VB5 Pro, VB6 Pro/Enterprise and now VB3 Pro. But I'm no expert, I'm still learning.
-
Nov 23rd, 2004, 02:45 PM
#4
Thread Starter
New Member
nothing happens when i try to save
i am very knew to this have probably missed somthing dead simple
thanks for the replys
-
Nov 23rd, 2004, 04:14 PM
#5
Software Eng.
Why is the segment "Open Z$ for output..." enclosed in "Close?"
When happens when you print z$ to the immedaite window? Does it match whichever file you wanted it to?
What results do you expect to get?
-
Nov 23rd, 2004, 07:30 PM
#6
How are the variable array's declared and do they contain data?
-
Nov 23rd, 2004, 08:03 PM
#7
Looks like you just want to save info to a text file using the cdl and
basic file I/O Output statement. Something like this should suffice.
You filter was not setup correct and I'm not sure how you need
your text file, but...
VB Code:
Option Explicit
Private Sub Command1_Click()
On Error GoTo No_Bugs
Dim sStr As String
CommonDialog1.CancelError = True
CommonDialog1.Filter = "Data Files (*.dat)|*.dat"
CommonDialog1.FilterIndex = 0
CommonDialog1.Flags = cdlOFNOverwritePrompt Or cdlOFNPathMustExist Or cdlOFNHideReadOnly
CommonDialog1.DefaultExt = "dat"
CommonDialog1.ShowSave
sStr = CommonDialog1.FileName
Open sStr For Output As #1
For a = 1 To 6
Print #1, lblAnswer(a).Caption
Next
For a = 1 To 12
Print #1, txtData(a).Text
Next
Close #1
Exit Sub
No_Bugs:
If Err.Number = 32755 Then
'Canceled
Else
MsgBox Err.Number & " - " & Err.Description, vbOKOnly + vbExclamation
End If
End Sub
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Nov 23rd, 2004, 11:29 PM
#8
Note: the flages need to be Or'ed together and not +'ed.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|