Go Back  Xtreme Visual Basic Talk > Legacy Visual Basic (VB 4/5/6) > Database and Reporting > problem


Reply
 
Thread Tools Display Modes
  #1  
Old 03-03-2003, 07:20 AM
jordan
Guest
 
Posts: n/a
Default problem


hi in my application I allow the user to import csv files through a common dialog control. If i click on a file of this type they will update the form perfectly, however what i want to do is perform some error control where by they cant try and select a word document or some other file which cant be imported with my code.
Is there a way I can do this. Please help.
this is the code where i select the file
Code:
Private Sub cmdbrowse1_Click() Dim strTxtfile As String txtfile.Locked = False txtfile.Text = strTxtfile update1.Enabled = True With CommonDialog1 .CancelError = True On Error GoTo Errhandler .ShowOpen strTxtfile = .FileName End With txtfile.Text = strTxtfile Errhandler: Select Case Err.Number Case cdlCancel MsgBox "No File Was Selected As The Operation Was Cancelled", vbOKOnly, "Information" End Select End sub
Thanks

Last edited by Robby; 03-03-2003 at 10:36 AM.
Reply With Quote
  #2  
Old 03-03-2003, 11:35 AM
Machaira's Avatar
Machaira Machaira is offline
Jedi Coder

* Expert *
 
Join Date: Aug 2002
Location: Abingdon, MD
Posts: 3,438
Default

You can set the Filter property of the CommonDialog control to only show files with a certain extension (txt, csv, etc.):

CommonDialog1.Filter = "Text (*.txt)|*.txt|CSV Files(*.csv)|*.csv"

That will at least limit the amount of wrong files that can be selected. You would still have to have error handling in your application to catch parsing errors if a text file that isn't properly formatted is selected. There's nothing in the selection process that can guarantee that a wrong file isn't selected.

BTW - you might want to add an:

Exit Sub

before your error handler label.
Reply With Quote
  #3  
Old 03-03-2003, 11:52 AM
jordan
Guest
 
Posts: n/a
Default

Hi thanks for the reply, it is .txt file which i will be importing so i put in i changed the code to the following

With CommonDialog1 file
.CancelError = True
On Error GoTo Errhandler
'.Filter = "Text Files (*.txt)/*.txt)"
.ShowOpen
strTxtfile = .FileName
End With

however unfortunatley it doesnt seem to do the job i now get an error saying subscript out of range!!
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
A Problem for The Expert Programmers – or maybe not! cballe General 2 07-15-2002 06:48 PM
A problem for the Guru programmers cballe General 3 06-26-2002 09:55 AM
A Problem for the Guru programmers (or not!) cballe General 16 06-09-2002 07:35 AM
Timers jemerico General 7 05-30-2001 05:30 PM

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
 
 
-->