S D
accessd667 at yahoo.com
Tue Mar 30 01:37:33 CST 2004
OK, I wanted to add a minidb but a message has a max size of 30KB...
I've added the code I use in the following order:
Form
Module
Class
I've got the following questions:
Q1: I'm calling the method SaveLine via a function ImportInterface. I don't think that this is very good programming.
How can I improve this?
Q2: I'm not using properties. Do I need them? For what and why?
Q3: If anyone has more tips...
Form Code
Private Sub cmdReadFile_Click()
Dim intInterfaceID As Integer
intInterfaceID = cboImport
Call ImportInterface(cboImport, "D:\Temp Projecten\Access\Interface.dat")
End Sub
Module
'=========================================================================================
' Function Name : ImportInterface
' Parameters : intInterfaceID, strFilename
' Purpose : inserts every line of the interface into tblData
' Assumptions : ---
' Uses : ---
' Created : 2004-03-29 07:56, SaDe
' Modifications :
'=========================================================================================
Public Sub ImportInterface(intInterfaceID As Integer, strFilename As String)
Dim objFSO As FileSystemObject
Dim objTS As TextStream
Dim strCurrentLine As String
Dim strSQL As String
Dim dtmCurrentDate As Date
Dim intLineID As Integer
Dim cInterface As cInterface
Dim cnnConnection As ADODB.Connection
Dim blnSaveLineOK As Boolean
On Error GoTo ImportInterface_Error
Set cnnConnection = CurrentProject.Connection
Set objFSO = New FileSystemObject
Set objTS = objFSO.OpenTextFile(strFilename)
Set cInterface = New cInterface
blnSaveLineOK = False
intLineID = 1
cnnConnection.BeginTrans
Do While Not objTS.AtEndOfStream
'strCurrentLine = objTS.ReadLine
blnSaveLineOK = cInterface.SaveLine(cnnConnection, intInterfaceID, intLineID, objTS.ReadLine)
intLineID = intLineID + 1
Loop
'Check if method executed correct
If blnSaveLineOK Then
cnnConnection.CommitTrans
Call MsgBox("Interface imported!", vbInformation)
Else
cnnConnection.RollbackTrans
Call MsgBox("An error occured!", vbCritical)
End If
Set cnnConnection = Nothing
Exit Sub
ImportInterface_Exit:
' Collect your garbage here
cnnConnection.RollbackTrans
Set cnnConnection = Nothing
Exit Sub
ImportInterface_Error:
' Collect your garbage here
MsgBox "An Error Occured!!!" & Err.Number & ";" & Err.Description
End Sub
class cInterface
Function SaveLine(cnnConnection As ADODB.Connection, intInterfaceID As Integer, intLineID As Integer, strLine As String) As Boolean
Dim rstInterfaceData As ADODB.Recordset
On Error GoTo SaveLine_Error
Set rstInterfaceData = New ADODB.Recordset
With rstInterfaceData
.ActiveConnection = cnnConnection
.CursorType = adOpenKeyset
.LockType = adLockOptimistic
.Source = "SELECT * FROM tblInterfaceData"
.Open
.AddNew
!InterfaceID = intInterfaceID
!InterfaceDate = Format(Now)
!InterfaceLine = intLineID
!InterfaceData = strLine
.Update
End With
Set rstInterfaceData = Nothing
'Set cnnConnection = Nothing
SaveLine = True
SaveLine_Exit:
' Collect your garbage here
Set rstInterfaceData = Nothing
'Set cnnConnection = Nothing
Exit Function
SaveLine_Error:
' Collect your garbage here
SaveLine = False
Call MsgBox(Err.Number & vbCrLf & _
Err.Description & vbCrLf & _
Err.Source & vbCrLf & _
"Newest.cInterface.SaveLine", vbCritical)
Resume SaveLine_Exit
End Function
rsmethurst at uk.ey.com wrote:
Sure Sander...
I will.
Cheers
Ryan
S D
Sent by: accessd-bounces at databaseadvisors.com
29/03/2004 14:46
Please respond to Access Developers discussion and problem solving
To: accessd
cc:
Subject: [AccessD] Importing data using a Class..Who can help/review?
Hi group,
I'm building a little app that is able to import textfiles. I want to do
this using a class. I've made a start and it works! Does anybody have the
time/interest to shoot at it?
It's very basic.
I've got:
a class called: cInterface
a method called: SaveLine
TIA
Sander
---------------------------------
Do you Yahoo!?
Yahoo! Finance Tax Center - File online. File on time.
--
_______________________________________________
AccessD mailing list
AccessD at databaseadvisors.com
http://databaseadvisors.com/mailman/listinfo/accessd
Website: http://www.databaseadvisors.com
This e-mail and any attachment are confidential and contain proprietary information, some or all of which may be legally privileged. It is intended solely for the use of the individual or entity to which it is addressed. If you are not the intended recipient, please notify the author immediately by telephone or by replying to this e-mail, and then delete all copies of the e-mail on your system. If you are not the intended recipient, you must not use, disclose, distribute, copy, print or rely on this e-mail.
Whilst we have taken reasonable precautions to ensure that this e-mail and any attachment has been checked for viruses, we cannot guarantee that they are virus free and we cannot accept liability for any damage sustained as a result of software viruses. We would advise that you carry out your own virus checks, especially before opening an attachment.
The UK firm Ernst & Young LLP is a limited liability partnership registered in England and Wales with registered number OC300001 and is a member practice of Ernst & Young Global. A list of members? names is available for inspection at 1 More London Place, London, SE1 2AF, the firm?s principal place of business and its registered office.
--
_______________________________________________
AccessD mailing list
AccessD at databaseadvisors.com
http://databaseadvisors.com/mailman/listinfo/accessd
Website: http://www.databaseadvisors.com
---------------------------------
Do you Yahoo!?
Yahoo! Finance Tax Center - File online. File on time.