Results 1 to 15 of 15

Thread: [RESOLVED] common dialog box problem

  1. #1

    Thread Starter
    Lively Member chxxangie's Avatar
    Join Date
    Feb 2007
    Location
    Malaysia
    Posts
    79

    Resolved [RESOLVED] common dialog box problem

    VB Code:
    1. If opt_txt.Value = True Then
    2.                 CommonDialog1.DialogTitle = "Save Log File"
    3.                 CommonDialog1.Flags = cdlOFNHideReadOnly
    4.                 CommonDialog1.Filter = "Text Files (*.txt)|*.txt|"
    5.                 CommonDialog1.FilterIndex = 1
    6.                 CommonDialog1.ShowSave
    7.                 file_inidir = "C:\Program Files\FYP System\Log File\" & user_reg.txt_username
    8.                 CommonDialog1.InitDir = file_inidir
    9.                 If CommonDialog1.FileName = "" Then
    10.                     Timer1.Enabled = False
    11.                     Exit Sub
    12.                 Else
    13.                 show_dir = CommonDialog1.FileName
    14.                 End If
    15.         end if

    when i choose the CANCEL button, suppose it do not do anything.....
    but it still save the data into a file!!!
    so, how to settle this problem?

  2. #2
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: common dialog box problem

    Use the CancelError property to trap for when they click theCancel button.
    VB Code:
    1. On Error GoTo MyError
    2.  
    3. If opt_txt.Value = True Then
    4.     CommonDialog1.CancelError = True
    5.     CommonDialog1.DialogTitle = "Save Log File"
    6.     CommonDialog1.Flags = cdlOFNHideReadOnly
    7.     CommonDialog1.Filter = "Text Files (*.txt)|*.txt|"
    8.     CommonDialog1.FilterIndex = 1
    9.     CommonDialog1.InitDir = "C:\Program Files\FYP System\Log File\" & user_reg.txt_username
    10.     CommonDialog1.ShowSave
    11.     If CommonDialog1.FileName = "" Then
    12.         Timer1.Enabled = False
    13.         Exit Sub
    14.     Else
    15.         show_dir = CommonDialog1.FileName
    16.     End If
    17. End If
    18. Exit Sub
    19. MyError:
    20. If Err.Number <> cdlCancel Then
    21.     MsgBox Err.Number & " - " & Err.Description
    22. End If
    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

  3. #3
    I don't do your homework! opus's Avatar
    Join Date
    Jun 2000
    Location
    Good Old Europe
    Posts
    3,863

    Re: common dialog box problem

    The prblem must be in the code that runs after the lines you posted.
    Your Commondialog has bee shown and you left (using whatever button), which code is running then? The actual saving is done there, so the unwanted behaviour will be encoded in there!
    You're welcome to rate this post!
    If your problem is solved, please use the Mark thread as resolved button


    Wait, I'm too old to hurry!

  4. #4

    Thread Starter
    Lively Member chxxangie's Avatar
    Join Date
    Feb 2007
    Location
    Malaysia
    Posts
    79

    Re: common dialog box problem

    i tried the code, but when i press SAVE button, it do nothing.....
    press CANCEL Button, it do the saving data......

  5. #5
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: common dialog box problem

    CommonDialog1.ShowSave displays the modal dialog box. If the user clicks Cancel it will jump to the Error Handler. Did you add the .CancelError = True part too like I posted?
    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

  6. #6

    Thread Starter
    Lively Member chxxangie's Avatar
    Join Date
    Feb 2007
    Location
    Malaysia
    Posts
    79

    Re: common dialog box problem

    yup....i had already added the .CancelError = True ........

  7. #7
    I don't do your homework! opus's Avatar
    Join Date
    Jun 2000
    Location
    Good Old Europe
    Posts
    3,863

    Re: common dialog box problem

    The code you posted will SHOW the Commondialog. After pressing any button, this commondialog will be hidden again and you have set a value for "CommonDialog1.FileName". In your case you put that value into "show_dir".

    What are you doing with "show_dir", there has to be a code-line where "show_dir" is used to save the file! Please post this part!
    You're welcome to rate this post!
    If your problem is solved, please use the Mark thread as resolved button


    Wait, I'm too old to hurry!

  8. #8
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: common dialog box problem

    And the "On Error GoTo MyError" and the Error handler sub too?
    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

  9. #9

    Thread Starter
    Lively Member chxxangie's Avatar
    Join Date
    Feb 2007
    Location
    Malaysia
    Posts
    79

    Re: common dialog box problem

    had added.....

  10. #10

    Thread Starter
    Lively Member chxxangie's Avatar
    Join Date
    Feb 2007
    Location
    Malaysia
    Posts
    79

    Re: common dialog box problem

    VB Code:
    1. Private Sub Command1_Click()
    2.            
    3.     If opt_Cus_log1.Value = True Or ans = 6 Then
    4.             If opt_txt.Value = True Then
    5.                 CommonDialog1.DialogTitle = "Save Log File"
    6.                 CommonDialog1.Flags = cdlOFNHideReadOnly
    7.                 CommonDialog1.Filter = "Text Files (*.txt)|*.txt|"
    8.                 CommonDialog1.FilterIndex = 1
    9.                 CommonDialog1.InitDir = "C:\Program Files\FYP System\Log File\" & user_reg.txt_username
    10.                 CommonDialog1.ShowSave
    11.                 If CommonDialog1.FileName = "" Then
    12.                     Timer1.Enabled = False
    13.                     Exit Sub
    14.                 Else
    15.                 show_dir = CommonDialog1.FileName
    16.                 End If
    17.             End If
    18.     End If
    19.  
    20.     com2 = 1
    21.  
    22.     Timer1.Enabled = True
    23.     Shape1.BackColor = vbGreen
    24.     lbl_Status.Caption = "Scanning..."
    25.     lbl_Status.ForeColor = vbGreen
    26.     cmd_scan.Caption = "Scan OFF"
    27.     start_datetime = Now
    28.  
    29. Else
    30.     com2 = 0
    31.    
    32.     Timer1.Enabled = False
    33.     Shape1.BackColor = vbRed
    34.     lbl_Status.Caption = "Stop"
    35.     lbl_Status.ForeColor = vbRed
    36.     cmd_scan.Caption = "Scan ON"
    37.     end_datetime = Now
    38.  
    39.     If com2 = 0 Then
    40.            
    41.     '******************************************************************************
    42.     'TXT Format
    43.     '******************************************************************************
    44.             If opt_txt.Value = True Then
    45.                 Open show_dir For Append As #1
    46.                     Print #1, "************************************************************************"
    47.                     Print #1, "Digital Curemeter Data Acqusition and Display System"
    48.                     Print #1, '""
    49.                     Print #1, "Experimenter..............", username
    50.                     Print #1, "Sampling Frequency........", TxtRate & " miliseconds"
    51.                     Print #1, "Start time................", start_datetime
    52.                     Print #1, "End time..................", end_datetime
    53.                     Print #1, "Total number of Data......", lbl_listcount.Caption
    54.                     Print #1, "Tag Name..................", Text2.Text
    55.                     Print #1, "Units.....................", Text7.Text
    56.                     Print #1, "************************************************************************"
    57.                     Print #1, '""
    58.                     Print #1, "COLLECTION OF DATA  (Analog Input of 8 Channel)"
    59.                     Print #1, ""
    60.                     Print #1, "   No   CHN 1   CHN 2   CHN 3   CHN 4   CHN 5   CHN 6   CHN 7   CHN 8"
    61.                     Print #1, "------------------------------------------------------------------------"
    62.  
    63.                     For a = 0 To List1(0).ListCount - 1
    64.                         Print #1, Format(a + 1, "00000");
    65.                         For b = 0 To 7
    66.                             Print #1, Right$(Space(8) & List1(b).List(a), 8);
    67.                         Next b
    68.                         Print #1,
    69.                     Next
    70.                 Close #1
    71.             End If
    72.         End If
    73.     End If
    74. End If
    75.  
    76. End Sub

    this is the some parts of my code that i do it before this.....

  11. #11
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: common dialog box problem

    Here, I fixed the code as you also had an End If issue and indenting was hard to read. The .CancelError = True was not in your posted code. This works.
    VB Code:
    1. Private Sub Command1_Click()
    2.     [b]On Error GoTo MyError[/b]
    3.     If opt_Cus_log1.Value = True Or ans = 6 Then
    4.         If opt_txt.Value = True Then
    5.             [b]CommonDialog1.CancelError = True[/b]
    6.             CommonDialog1.DialogTitle = "Save Log File"
    7.             CommonDialog1.Flags = cdlOFNHideReadOnly
    8.             CommonDialog1.Filter = "Text Files (*.txt)|*.txt|"
    9.             CommonDialog1.FilterIndex = 1
    10.             CommonDialog1.InitDir = "C:\Program Files\FYP System\Log File\" & user_reg.txt_username
    11.             CommonDialog1.ShowSave
    12.             If CommonDialog1.FileName = "" Then
    13.                 Timer1.Enabled = False
    14.                 Exit Sub
    15.             Else
    16.                 show_dir = CommonDialog1.FileName
    17.             End If
    18.         End If
    19.  
    20.         com2 = 1
    21.  
    22.         Timer1.Enabled = True
    23.         Shape1.BackColor = vbGreen
    24.         lbl_Status.Caption = "Scanning..."
    25.         lbl_Status.ForeColor = vbGreen
    26.         cmd_scan.Caption = "Scan OFF"
    27.         start_datetime = Now
    28.  
    29.     Else
    30.         com2 = 0
    31.        
    32.         Timer1.Enabled = False
    33.         Shape1.BackColor = vbRed
    34.         lbl_Status.Caption = "Stop"
    35.         lbl_Status.ForeColor = vbRed
    36.         cmd_scan.Caption = "Scan ON"
    37.         end_datetime = Now
    38.  
    39.         If com2 = 0 Then
    40.                    
    41.             '******************************************************************************
    42.             'TXT Format
    43.             '******************************************************************************
    44.             If opt_txt.Value = True Then
    45.                 Open show_dir For Append As #1
    46.                     Print #1, "************************************************************************"
    47.                     Print #1, "Digital Curemeter Data Acqusition and Display System"
    48.                     Print #1, '""
    49.                     Print #1, "Experimenter..............", username
    50.                     Print #1, "Sampling Frequency........", TxtRate & " miliseconds"
    51.                     Print #1, "Start time................", start_datetime
    52.                     Print #1, "End time..................", end_datetime
    53.                     Print #1, "Total number of Data......", lbl_listcount.Caption
    54.                     Print #1, "Tag Name..................", Text2.Text
    55.                     Print #1, "Units.....................", Text7.Text
    56.                     Print #1, "************************************************************************"
    57.                     Print #1, '""
    58.                     Print #1, "COLLECTION OF DATA  (Analog Input of 8 Channel)"
    59.                     Print #1, ""
    60.                     Print #1, "   No   CHN 1   CHN 2   CHN 3   CHN 4   CHN 5   CHN 6   CHN 7   CHN 8"
    61.                     Print #1, "------------------------------------------------------------------------"
    62.    
    63.                     For a = 0 To List1(0).ListCount - 1
    64.                         Print #1, Format(a + 1, "00000");
    65.                         For b = 0 To 7
    66.                             Print #1, Right$(Space(8) & List1(b).List(a), 8);
    67.                         Next b
    68.                         Print #1,
    69.                     Next
    70.                 Close #1
    71.             End If
    72.         End If
    73.     End If
    74.     Exit Sub
    75. [b]MyError:
    76.     If Err.Number <> cdlerror Then
    77.         MsgBox Err.Number & " - " & Err.Description
    78.     End If[/b]
    79. 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

  12. #12

    Thread Starter
    Lively Member chxxangie's Avatar
    Join Date
    Feb 2007
    Location
    Malaysia
    Posts
    79

    Re: common dialog box problem

    yeah, it works.....i forgot that the "MyError" have to put before the end sub......
    thank you so much.......
    another problem is....now what i m doing is when the i key in the filename which is exist, it will just overwrite it......how to cover it?

  13. #13
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: common dialog box problem

    VB Code:
    1. CommonDialog1.Flags = cdlOFNHideReadOnly Or cdlOFNOverwritePrompt
    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

  14. #14

    Thread Starter
    Lively Member chxxangie's Avatar
    Join Date
    Feb 2007
    Location
    Malaysia
    Posts
    79

    Re: common dialog box problem

    thanks again......it really works......

  15. #15
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: [RESOLVED] common dialog box problem

    Here is the MSDN online help page with all the flags for the CDL.

    http://msdn.microsoft.com/library/de...oflagsfile.asp
    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