Results 1 to 8 of 8

Thread: save open command

  1. #1

    Thread Starter
    New Member
    Join Date
    Nov 2004
    Posts
    6

    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

  2. #2
    Super Moderator manavo11's Avatar
    Join Date
    Nov 2002
    Location
    Around the corner from si_the_geek
    Posts
    7,171
    Where is the problem? What error occures?


    Has someone helped you? Then you can Rate their helpful post.

  3. #3
    PowerPoster Keithuk's Avatar
    Join Date
    Jan 2004
    Location
    Staffordshire, England
    Posts
    2,236
    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:
    1. CommonDialog1.Flags = cdlOFNOverwritePrompt + _
    2. cdlOFNPathMustExist
    3. 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.

  4. #4

    Thread Starter
    New Member
    Join Date
    Nov 2004
    Posts
    6
    nothing happens when i try to save
    i am very knew to this have probably missed somthing dead simple

    thanks for the replys

  5. #5
    Software Eng. Megatron's Avatar
    Join Date
    Mar 1999
    Location
    Canada
    Posts
    11,286
    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?

  6. #6
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901
    How are the variable array's declared and do they contain data?

  7. #7
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709
    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:
    1. Option Explicit
    2.  
    3. Private Sub Command1_Click()
    4.  
    5.     On Error GoTo No_Bugs
    6.    
    7.     Dim sStr As String
    8.    
    9.     CommonDialog1.CancelError = True
    10.     CommonDialog1.Filter = "Data Files (*.dat)|*.dat"
    11.     CommonDialog1.FilterIndex = 0
    12.     CommonDialog1.Flags = cdlOFNOverwritePrompt Or cdlOFNPathMustExist Or cdlOFNHideReadOnly
    13.     CommonDialog1.DefaultExt = "dat"
    14.     CommonDialog1.ShowSave
    15.     sStr = CommonDialog1.FileName
    16.    
    17.     Open sStr For Output As #1
    18.         For a = 1 To 6
    19.             Print #1, lblAnswer(a).Caption
    20.         Next
    21.         For a = 1 To 12
    22.             Print #1, txtData(a).Text
    23.         Next
    24.     Close #1
    25.     Exit Sub
    26.    
    27. No_Bugs:
    28.     If Err.Number = 32755 Then
    29.         'Canceled
    30.     Else
    31.         MsgBox Err.Number & " - " & Err.Description, vbOKOnly + vbExclamation
    32.     End If
    33. 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 PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI 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

  8. #8
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709
    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 PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI 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
  •  



Click Here to Expand Forum to Full Width