|
-
Feb 23rd, 2007, 04:34 AM
#1
Thread Starter
Lively Member
[RESOLVED] common dialog box problem
VB Code:
If opt_txt.Value = True Then
CommonDialog1.DialogTitle = "Save Log File"
CommonDialog1.Flags = cdlOFNHideReadOnly
CommonDialog1.Filter = "Text Files (*.txt)|*.txt|"
CommonDialog1.FilterIndex = 1
CommonDialog1.ShowSave
file_inidir = "C:\Program Files\FYP System\Log File\" & user_reg.txt_username
CommonDialog1.InitDir = file_inidir
If CommonDialog1.FileName = "" Then
Timer1.Enabled = False
Exit Sub
Else
show_dir = CommonDialog1.FileName
End If
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?
-
Feb 23rd, 2007, 04:40 AM
#2
Re: common dialog box problem
Use the CancelError property to trap for when they click theCancel button.
VB Code:
On Error GoTo MyError
If opt_txt.Value = True Then
CommonDialog1.CancelError = True
CommonDialog1.DialogTitle = "Save Log File"
CommonDialog1.Flags = cdlOFNHideReadOnly
CommonDialog1.Filter = "Text Files (*.txt)|*.txt|"
CommonDialog1.FilterIndex = 1
CommonDialog1.InitDir = "C:\Program Files\FYP System\Log File\" & user_reg.txt_username
CommonDialog1.ShowSave
If CommonDialog1.FileName = "" Then
Timer1.Enabled = False
Exit Sub
Else
show_dir = CommonDialog1.FileName
End If
End If
Exit Sub
MyError:
If Err.Number <> cdlCancel Then
MsgBox Err.Number & " - " & Err.Description
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 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 
-
Feb 23rd, 2007, 04:47 AM
#3
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!
-
Feb 23rd, 2007, 04:52 AM
#4
Thread Starter
Lively Member
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......
-
Feb 23rd, 2007, 04:55 AM
#5
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 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 
-
Feb 23rd, 2007, 04:57 AM
#6
Thread Starter
Lively Member
Re: common dialog box problem
yup....i had already added the .CancelError = True ........
-
Feb 23rd, 2007, 04:58 AM
#7
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!
-
Feb 23rd, 2007, 05:01 AM
#8
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 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 
-
Feb 23rd, 2007, 05:04 AM
#9
Thread Starter
Lively Member
Re: common dialog box problem
-
Feb 23rd, 2007, 05:05 AM
#10
Thread Starter
Lively Member
Re: common dialog box problem
VB Code:
Private Sub Command1_Click()
If opt_Cus_log1.Value = True Or ans = 6 Then
If opt_txt.Value = True Then
CommonDialog1.DialogTitle = "Save Log File"
CommonDialog1.Flags = cdlOFNHideReadOnly
CommonDialog1.Filter = "Text Files (*.txt)|*.txt|"
CommonDialog1.FilterIndex = 1
CommonDialog1.InitDir = "C:\Program Files\FYP System\Log File\" & user_reg.txt_username
CommonDialog1.ShowSave
If CommonDialog1.FileName = "" Then
Timer1.Enabled = False
Exit Sub
Else
show_dir = CommonDialog1.FileName
End If
End If
End If
com2 = 1
Timer1.Enabled = True
Shape1.BackColor = vbGreen
lbl_Status.Caption = "Scanning..."
lbl_Status.ForeColor = vbGreen
cmd_scan.Caption = "Scan OFF"
start_datetime = Now
Else
com2 = 0
Timer1.Enabled = False
Shape1.BackColor = vbRed
lbl_Status.Caption = "Stop"
lbl_Status.ForeColor = vbRed
cmd_scan.Caption = "Scan ON"
end_datetime = Now
If com2 = 0 Then
'******************************************************************************
'TXT Format
'******************************************************************************
If opt_txt.Value = True Then
Open show_dir For Append As #1
Print #1, "************************************************************************"
Print #1, "Digital Curemeter Data Acqusition and Display System"
Print #1, '""
Print #1, "Experimenter..............", username
Print #1, "Sampling Frequency........", TxtRate & " miliseconds"
Print #1, "Start time................", start_datetime
Print #1, "End time..................", end_datetime
Print #1, "Total number of Data......", lbl_listcount.Caption
Print #1, "Tag Name..................", Text2.Text
Print #1, "Units.....................", Text7.Text
Print #1, "************************************************************************"
Print #1, '""
Print #1, "COLLECTION OF DATA (Analog Input of 8 Channel)"
Print #1, ""
Print #1, " No CHN 1 CHN 2 CHN 3 CHN 4 CHN 5 CHN 6 CHN 7 CHN 8"
Print #1, "------------------------------------------------------------------------"
For a = 0 To List1(0).ListCount - 1
Print #1, Format(a + 1, "00000");
For b = 0 To 7
Print #1, Right$(Space(8) & List1(b).List(a), 8);
Next b
Print #1,
Next
Close #1
End If
End If
End If
End If
End Sub
this is the some parts of my code that i do it before this.....
-
Feb 23rd, 2007, 05:12 AM
#11
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:
Private Sub Command1_Click()
[b]On Error GoTo MyError[/b]
If opt_Cus_log1.Value = True Or ans = 6 Then
If opt_txt.Value = True Then
[b]CommonDialog1.CancelError = True[/b]
CommonDialog1.DialogTitle = "Save Log File"
CommonDialog1.Flags = cdlOFNHideReadOnly
CommonDialog1.Filter = "Text Files (*.txt)|*.txt|"
CommonDialog1.FilterIndex = 1
CommonDialog1.InitDir = "C:\Program Files\FYP System\Log File\" & user_reg.txt_username
CommonDialog1.ShowSave
If CommonDialog1.FileName = "" Then
Timer1.Enabled = False
Exit Sub
Else
show_dir = CommonDialog1.FileName
End If
End If
com2 = 1
Timer1.Enabled = True
Shape1.BackColor = vbGreen
lbl_Status.Caption = "Scanning..."
lbl_Status.ForeColor = vbGreen
cmd_scan.Caption = "Scan OFF"
start_datetime = Now
Else
com2 = 0
Timer1.Enabled = False
Shape1.BackColor = vbRed
lbl_Status.Caption = "Stop"
lbl_Status.ForeColor = vbRed
cmd_scan.Caption = "Scan ON"
end_datetime = Now
If com2 = 0 Then
'******************************************************************************
'TXT Format
'******************************************************************************
If opt_txt.Value = True Then
Open show_dir For Append As #1
Print #1, "************************************************************************"
Print #1, "Digital Curemeter Data Acqusition and Display System"
Print #1, '""
Print #1, "Experimenter..............", username
Print #1, "Sampling Frequency........", TxtRate & " miliseconds"
Print #1, "Start time................", start_datetime
Print #1, "End time..................", end_datetime
Print #1, "Total number of Data......", lbl_listcount.Caption
Print #1, "Tag Name..................", Text2.Text
Print #1, "Units.....................", Text7.Text
Print #1, "************************************************************************"
Print #1, '""
Print #1, "COLLECTION OF DATA (Analog Input of 8 Channel)"
Print #1, ""
Print #1, " No CHN 1 CHN 2 CHN 3 CHN 4 CHN 5 CHN 6 CHN 7 CHN 8"
Print #1, "------------------------------------------------------------------------"
For a = 0 To List1(0).ListCount - 1
Print #1, Format(a + 1, "00000");
For b = 0 To 7
Print #1, Right$(Space(8) & List1(b).List(a), 8);
Next b
Print #1,
Next
Close #1
End If
End If
End If
Exit Sub
[b]MyError:
If Err.Number <> cdlerror Then
MsgBox Err.Number & " - " & Err.Description
End If[/b]
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 
-
Feb 23rd, 2007, 05:20 AM
#12
Thread Starter
Lively Member
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?
-
Feb 23rd, 2007, 05:21 AM
#13
Re: common dialog box problem
VB Code:
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 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 
-
Feb 23rd, 2007, 05:31 AM
#14
Thread Starter
Lively Member
Re: common dialog box problem
thanks again......it really works......
-
Feb 23rd, 2007, 05:36 AM
#15
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 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
|