Your right, it makes very little difference to speed, just because you write
the name of an object on 2 different lines does not mean that there are 2
objects in memory, its still the same one being referenced.
Nick.
"Siv" <gs@remove.sivill.com> wrote in message
news:ewS%23LgSmEHA.3452@TK2MSFTNGP15.phx.gbl...[color=blue]
> Are you sure, or do you mean the code will be more concise??
> Siv
>
> "Howard Kaikow" <kaikow@standards.com> wrote in message
> news:ebUfxYSmEHA.3156@TK2MSFTNGP12.phx.gbl...[color=green]
>> The code will run a lot faster if you use With ... End With to reduce
>> the
>> number of object references.
>>
>> --
>>
http://www.standards.com/; See Howard Kaikow's web site.
>> "Siv" <gs@remove.sivill.com> wrote in message
>> news:%23Ey6QmRmEHA.896@TK2MSFTNGP12.phx.gbl...
>> Thanks for the advice, I do have Option Explicit on, but not Option
>> Strict.
>> The conversion routine picked up a few "I can't figure ot the default
>> property" errors, but I can't see a way round those as I am using OLE
>> Automation into Excel to open the sheets. The code is as follows:
>>
>> ================================================== ==========================
>> =======================
>> Dim FName, SheetName As String
>>
>> Dim DataArray(12, 60) As Object
>>
>> Dim mth, cl As Short
>>
>> Dim xlc, xlr, n As Short
>>
>> Dim rs As ADODB.Recordset
>>
>> Dim Cn As ADODB.Connection
>>
>> Dim strSQL, strCnn, MSg As String
>>
>> Dim XLApp As Object
>>
>> Dim LastM As Short
>>
>>
>>
>> On Error GoTo ConvertRoutine_Err
>>
>>
>>
>> ConvertRoutine = False 'Start off assuming fail and correct this
>> if
>> we do succeed.
>>
>>
>>
>> 'Work out the lastM var from LastMonth
>>
>> LastM = Val(LastMonth)
>>
>>
>>
>> FileOpen(1, "C:\T7ConversionLog.txt", OpenMode.Append)
>>
>>
>>
>> PrintLine(1, "TACSY 7 Conversion Log - " & Now)
>>
>> PrintLine(1, "===========================================")
>>
>> PrintLine(1, " ")
>>
>>
>>
>>
>>
>> 'Look for the files in the source directory by
>>
>> FName = Dir(tp & "*.xls") 'tp is the var holding the path to the
>> spreadsheets being processed.
>>
>> If FName = "" Then
>>
>> 'No xls files in this directory
>>
>> MSg = "WARNING: No Excel files found in:" & NL & NL
>>
>> MSg = MSg & tp & NL & NL
>>
>> MSg = MSg & "Click OK to exit the Conversion Routine, "
>>
>> MSg = MSg & "so that you can reselect the source folder."
>>
>> MsgBox(MSg, MsgBoxStyle.Information, H)
>>
>> PrintLine(1, "No Files found in selected folder ( " & tp & " )
>> to convert!")
>>
>> PrintLine(1, "Aborting Conversion Run at " & Now)
>>
>> FileClose(1)
>>
>> Exit Function
>>
>> Else
>>
>> 'Found some XL files.
>>
>> 'So Get Excel fired up
>>
>> XLApp = CreateObject("Excel.Application")
>>
>> XLApp.screenupdating = False
>>
>>
>>
>> 'Get the Tacsy7Data tble open ready to add records
>>
>> Cn = New ADODB.Connection
>>
>> Cn.ConnectionString = "Driver={SQL
>> Server};Server=SERVER;UID=;PWD=;DATABASE=TACSY"
>>
>> Cn.Open()
>>
>>
>>
>> rs = New ADODB.Recordset
>>
>> rs.Open("SELECT * FROM Tacsy7Data", Cn,
>> ADODB.CursorTypeEnum.adOpenKeyset, ADODB.LockTypeEnum.adLockOptimistic,
>> ADODB.CommandTypeEnum.adCmdText)
>>
>>
>>
>> Do
>>
>> XLApp.workbooks.Open(tp & FName)
>>
>>
>>
>> lblReadout.Text = "Processing " & FName & "."
>>
>> PrintLine(1, "Started converting " & tp & FName & " at " &
>> Now)
>>
>> System.Windows.Forms.Application.DoEvents() 'Let system in
>> for a tick + allow readout refresh.
>>
>> xlr = 64 'Row start, 1 less than desired so that the mth
>> can
>> be added to it to get the correct row.
>>
>>
>>
>> DataArray(0, 0) = XLApp.cells(50, 4).Value 'Get the points
>> score
>>
>>
>>
>> If XLApp.cells(84, 2).Value = "EmpNo" Then
>>
>> DataArray(0, 1) = VB.Left(FName, Len(FName) - 4)
>>
>> Else
>>
>> DataArray(0, 1) = XLApp.cells(84, 2).Value 'Get EmpNo
>>
>> End If
>>
>>
>>
>> For mth = 1 To 12
>>
>> For cl = 1 To 55
>>
>> 'Read the existing data into the array
>>
>> DataArray(mth, cl) = XLApp.cells(xlr + mth,
>> cl).Value
>>
>> Next cl
>>
>> Next mth
>>
>>
>>
>> 'Array now has all the data from the old sheet - close
>> the
>> sheet
>>
>> XLApp.workbooks(FName).Close(savechanges:=False) 'close
>> but
>> do not save
>>
>>
>>
>>
>>
>>
>>
>> For mth = 1 To 12
>>
>> 'Read the data back from the array - Up to col 36 they
>> are the same, then
>>
>> 'the new column appears at the 37th column and then
>> the
>> data is the same to the end.
>>
>> Select Case mth
>>
>> Case 1 To 5
>>
>> rs.AddNew()
>>
>> 'UPGRADE_WARNING: Couldn't resolve default
>> property of object DataArray(). Click for more:
>> 'ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="vbup1037"'
>>
>> rs.Fields("EmpNo").Value = Val(DataArray(0,
>> 1))
>> 'Employee Number
>>
>> 'UPGRADE_WARNING: Couldn't resolve default
>> property of object DataArray(0, 0). Click for more:
>> 'ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="vbup1037"'
>>
>> rs.Fields("PointsScoreAtThisMonth").Value =
>> DataArray(0, 0) 'Points score.
>>
>> If mth > LastM Then
>>
>> rs.Fields("Year").Value = Year(Now) - 1
>>
>> Else
>>
>> rs.Fields("Year").Value = VB6.Format(Now,
>> "YYYY")
>>
>> End If
>>
>> 'UPGRADE_WARNING: Couldn't resolve default
>> property of object DataArray(mth, 1). Click for more:
>> 'ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="vbup1037"'
>>
>> rs.Fields("TextMonthNumber").Value =
>> DataArray(mth, 1)
>>
>> 'UPGRADE_WARNING: Couldn't resolve default
>> property of object DataArray(mth, 2). Click for more:
>> 'ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="vbup1037"'
>>
>> rs.Fields("RollMonthNumber").Value =
>> DataArray(mth, 2)
>>
>>
>>
>> ... Lots more fields as per the above ...
>>
>>
>>
>> 'UPGRADE_WARNING: Couldn't resolve default
>> property of object DataArray(mth, 55). Click for more:
>> 'ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="vbup1037"'
>>
>> rs.Fields("BusMixPCInvNumShade").Value =
>> DataArray(mth, 55)
>>
>> rs.Update()
>>
>>
>>
>> Case 6 To 12 'beyond m6 data is screwed from
>> column
>> 36, data is in 1 to right of where it should be ie 37.
>>
>> rs.AddNew()
>>
>> 'UPGRADE_WARNING: Couldn't resolve default
>> property of object DataArray(). Click for more:
>> 'ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="vbup1037"'
>>
>> rs.Fields("EmpNo").Value = Val(DataArray(0,
>> 1))
>> 'Employee Number
>>
>> 'UPGRADE_WARNING: Couldn't resolve default
>> property of object DataArray(0, 0). Click for more:
>> 'ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="vbup1037"'
>>
>> rs.Fields("PointsScoreAtThisMonth").Value =
>> DataArray(0, 0) 'Points score.
>>
>> If mth > LastM Then
>>
>> rs.Fields("Year").Value = Year(Now) - 1
>>
>> Else
>>
>> rs.Fields("Year").Value = VB6.Format(Now,
>> "YYYY")
>>
>> End If
>>
>> 'UPGRADE_WARNING: Couldn't resolve default
>> property of object DataArray(mth, 1). Click for more:
>> 'ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="vbup1037"'
>>
>> rs.Fields("TextMonthNumber").Value =
>> DataArray(mth, 1)
>>
>> 'UPGRADE_WARNING: Couldn't resolve default
>> property of object DataArray(mth, 2). Click for more:
>> 'ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="vbup1037"'
>>
>> rs.Fields("RollMonthNumber").Value =
>> DataArray(mth, 2)
>>
>>
>>
>> ... Lots more fields as per the above ...
>>
>>
>>
>> 'UPGRADE_WARNING: Couldn't resolve default
>> property of object DataArray(mth, 55). Click for more:
>> 'ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="vbup1037"'
>>
>> rs.Fields("BusMixPCInvNum").Value =
>> DataArray(mth, 55)
>>
>> rs.Fields("BusMixPCInvNumShade").Value = 0
>> 'Just
>> have to hardcode a value of no shade as there is no data on sheets.
>>
>> rs.Update()
>>
>> End Select
>>
>> Next mth
>>
>>
>>
>> AfterError:
>>
>> 'Clear the array ready for next loop (if any).
>>
>> For mth = 1 To 12
>>
>> For cl = 1 To 55
>>
>> 'Clear the array
>>
>> 'UPGRADE_WARNING: Couldn't resolve default
>> property
>> of object DataArray(mth, cl). Click for more:
>> 'ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="vbup1037"'
>>
>> DataArray(mth, cl) = 0
>>
>> Next cl
>>
>> Next mth
>>
>>
>>
>>
>>
>>
>>
>> 'do a dir for the next file name or exit if FName=""
>>
>> 'UPGRADE_WARNING: Dir has a new behavior. Click for more:
>> 'ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="vbup1041"'
>>
>> FName = Dir()
>>
>>
>>
>> Loop Until FName = "" 'Move on to next sheet.
>>
>>
>>
>> 'Close recordset
>>
>> rs.Close()
>>
>>
>>
>> 'Write closing log entry
>>
>> PrintLine(1, " and finished file writes at " & Now) 'Finishes
>> a
>> line started near top of loop
>>
>> PrintLine(1,
>> "================================================= ====================")
>>
>>
>>
>> FileClose(1) 'close log file!
>>
>>
>>
>> 'UPGRADE_WARNING: Couldn't resolve default property of object
>> XLApp.screenupdating. Click for more:
>> 'ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="vbup1037"'
>>
>> XLApp.screenupdating = True 'Turn on screen updating
>>
>> 'UPGRADE_WARNING: Couldn't resolve default property of object
>> XLApp.quit. Click for more:
>> 'ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="vbup1037"'
>>
>> XLApp.quit() 'Quit excel
>>
>>
>>
>> End If
>>
>>
>>
>>
>>
>>
>>
>>
>>
>> ConvertRoutine = True
>>
>>
>>
>> ConvertRoutine_End:
>>
>> Exit Function
>>
>>
>>
>>
>>
>> ConvertRoutine_Err:
>>
>> Select Case Err.Number
>>
>> Case 13 'Type Mismatch
>>
>> Resume Next
>>
>> Case 94 'Invalid Use of Null
>>
>> Resume Next
>>
>> Case 3021 'No record found
>>
>> Resume ConvertRoutine_End
>>
>> Case 3022 'Duplicate record
>>
>> Resume ConvertRoutine_End
>>
>> Case -2147217887 'Multiple-step OLE DB operation generated
>> errors. Check each OLE DB status value, if available. No work was done.
>>
>> rs.CancelUpdate() 'Will occurr if dataarray(x,y) is empty
>> due to sheet being empty?? Found one so have put in this patch to bypass
>> it.
>>
>> Resume AfterError
>>
>> Resume 'debugging
>>
>> Case Else
>>
>> Me.Cursor = System.Windows.Forms.Cursors.Default
>>
>> Call ProgErrorHandler("ConvertRoutine in
>> frmConvertT7ToData", False)
>>
>> Resume ConvertRoutine_End
>>
>> Resume 'Debugging
>>
>> End Select
>>
>> ================================================== ===
>>
>> I have retained the "On error Goto" because using Try, Catch, Finally I
>> can't find out how to trap a specific error like the -2147217887 Multiple
>> Step OLE error the help on this is "pants".
>>
>> Siv
>>
>> "Austin Ehlers" <liberal*number_eight*@ku.edu> wrote in message
>> news:f079k0599a8638b8t9of97g2k8q3j5lvjm@4ax.com...[color=darkred]
>>> On Sun, 12 Sep 2004 18:45:48 +0100, "Siv" <gs@remove.sivill.com>
>>> wrote:
>>>
>>>>Hi,
>>>>
>>>>As part of an evaluation of a small utility that I wrote that converts[/color]
>> some[color=darkred]
>>>>data held in a large number of Excel spreadsheets into SQL Server, I[/color]
>> decided[color=darkred]
>>>>to convert the utility to VB .NET and run both versions both in the IDE[/color]
>> and[color=darkred]
>>>>as standalone compiled exe and see what the difference in time to
>>>>complete
>>>>was.
>>>>
>>>>The utility has to read 3842 single page Excel Sheets that contain a
>>>>block
>>>>of data 12 rows deep and 55 columns across, this is then transferred
>>>>into[/color]
>> an[color=darkred]
>>>>SQL Server table with the same number of columns.
>>>>
>>>>I thought VB .NET might be slower, but I was surprised by how much.
>>>
>>> Make sure you have Option Explicit On and Option Strict set. Watch
>>> out for string concatenation (use System.Text.StringBuilder instead).
>>> Watch out for legacy VB methods, classes, etc., and use .NET versions
>>> instead.
>>>
>>>>I would like to release the findings to this community for comment, but
>>>>I
>>>>remembered something in the EULA for .NET that says you can't release
>>>>benchmarks. Now I am not in the business of falling out with anyone and
>>>>I
>>>>don't want to get into trouble with MS (particuarly as I make my living
>>>>on
>>>>the back of Microsoft's products). What I would like to release is just
>>>>a
>>>>table showing the start and end times for each run of my program and the
>>>>calculated elapsed times bothe for VB6 and VB .NET.
>>>>
>>>>If anyone from MS is looking in I would be pleased to know if you would
>>>>be
>>>>unhappy about me releasing my findings??
>>>>
>>>>Siv
>>>>
>>>
>>> I ANAL, but you should be fine; you're trying to figure out what's
>>> wrong with your code. It's to prevent articles like "C# vs. Java",
>>> etc.
>>>
>>> Austin
>>>[/color]
>>
>>[/color]
>
>[/color]