Results 1 to 16 of 16

Thread: slo-o-w code

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Jun 2002
    Posts
    586

    slo-o-w code

    Say, my program is taking kind of long too run, mostly becasue of the size of the files being extracted. Still, the customer needs it to be quicker.

    The code for sending the extracted items to the database is below. Does anyone see anything I can do to speed up the process. I realize its long and convoluted; but if anyone sees anything at first glance that I can do to speed thngs up, please let me know. Its a big section, so I'll break it in pieces. I really apprecaite it.

    VB Code:
    1. Sub SendToDatabase()
    2. Dim rst As New ADODB.Recordset
    3. Dim cmd As ADODB.Command
    4. Dim dbAdd As Boolean
    5. Dim reopenRecordset As Boolean
    6. Dim sql As String
    7. Dim Characteristic As String
    8. Dim n As Integer
    9. Dim x As Long
    10. 'On Error GoTo stdhandler
    11. tr = 1
    12. 'subgroupitemcount = 0
    13. 'On Error Resume Next
    14. dbAdd = True
    15. pbimport.Enabled = True
    16. 'On Error GoTo handler
    17. reopenRecordset = True
    18. 'Create a connection object.
    19. Set cnn = CreateObject("ADODB.Connection")
    20.  
    21. 'Open a Microsoft Access database connection using the OLE DB connection string.
    22. cnn.Open "Provider=Microsoft.Jet.OLEDB.4.0; Data Source= " & Trim(lbldatabase.Caption)
    23.  
    24. 'Open a Microsoft SQL Server Connection
    25. 'Provider=SQLOLEDB.1;Data Source=path to server
    26.  
    27. '***save assigned data into the appropriate database***
    28.  
    29. 'for each line of the code
    30. For x = 1 To xcount
    31.  
    32. 'PART NAME
    33.  
    34. ' First, check to see if the part already exists, by getting all partnames
    35. ' and seeing if any of them are the same as the variable 'partname'
    36. 'temppartname = partname
    37. 'temppartname = Replace(temppartname, "&", "and")
    38. temppartname = part(x)
    39. temppartname = Replace(temppartname, "&", "and")
    40. temppartname = Replace(temppartname, "#", "")
    41. temppartname = Replace(temppartname, Chr$(34), "")
    42. sourcesqlstatement = "Select PartName from Part where PartName <> ''"
    43. rst.Open sourcesqlstatement, cnn, adOpenStatic, adLockOptimistic
    44. If rst.RecordCount > 0 Then
    45.     rst.MoveFirst
    46.     Do While Not rst.EOF
    47.         Value = rst.Fields("PartName")
    48.         If Value = temppartname Then
    49.             dbAdd = False
    50.             Exit Do
    51.          End If
    52.         rst.MoveNext
    53.     Loop
    54. End If
    55. rst.Close
    56.  
    57. 'Secondly, put the part into database, if necessary.
    58.     If dbAdd Then
    59.         lasteditdate = Now
    60.  
    61.         sql = "INSERT INTO Part (PartName, LastEditDate, GroupId) VALUES ('" & temppartname & "', '" & lasteditdate & "',-1)"
    62.        
    63.         cnn.Execute sql
    64.     End If
    65.     dbAdd = True
    66.  
    67. 'Thirdly, assign the id value for the part to a variable, so that it can be put in the characteristic table, if necessary.
    68. sourcesqlstatement = "Select PartId From Part Where PartName = '" & temppartname & "'"
    69. rst.Open sourcesqlstatement, cnn, adOpenStatic, adLockOptimistic
    70.     If rst.RecordCount > 0 Then
    71.         rst.MoveFirst
    72.         dbAdd = True
    73.         Do While Not rst.EOF
    74.             partid = rst.Fields("PartId")
    75.             rst.MoveNext
    76.         Loop
    77.     End If
    78.     rst.Close
    79.  
    80. 'TRACE
    81. ' First, check to see if the trace name alreday exists, by getting all trace names
    82. ' and seeing if any of them are the same as the variable 'tracename'
    83. For t = 1 To tracecount
    84. sourcesqlstatement = "Select TraceId, TraceName from Trace where TraceName <> ''"
    85. rst.Open sourcesqlstatement, cnn, adOpenStatic, adLockOptimistic
    86. dbAdd = True
    87. If rst.RecordCount > 0 Then
    88.     rst.MoveFirst
    89.     Do While Not rst.EOF
    90.         traceid(t) = rst.Fields("TraceId")
    91.         Value = rst.Fields("TraceName")
    92.         If Trim(UCase(Value)) = Trim(UCase(tracename(t))) Then
    93.             dbAdd = False
    94.             reopenRecordset = False
    95.             Exit Do
    96.          End If
    97.         rst.MoveNext
    98.     Loop
    99. End If
    100. rst.Close
    101.  
    102. 'Second, add any new trace name to the trace table.
    103. If dbAdd Then 'add trace name to Trace table if it doesn't already exist
    104.     sql = ""
    105.     temptracename = tracename(t)
    106.     temptracename = Replace(temptracename, "&", "and")
    107.     temptracename = Replace(temptracename, "#", "")
    108.     temptracename = Replace(temptracename, Chr$(34), "")
    109.     sql = "INSERT INTO Trace (TraceName, LastEditDate, GroupId, IsACCA, StoreTraceCodes) VALUES ('" & temptracename & "', '" & Now & "',-1,0,0)"
    110.     cnn.Execute sql
    111. End If
    112. latesttracename = tracename(t)
    113.  
    114. 'Thirdly, reopen the Trace table recordset, and extract the traceid of the latest
    115. 'trace name inserted, so that it can be inserted into TraceCodes and Data tables
    116. If reopenRecordset Then
    117.     sourcesqlstatement = "Select TraceId, TraceName from Trace where TraceName <> ''"
    118.     rst.Open sourcesqlstatement, cnn, adOpenStatic, adLockOptimistic
    119.     dbAdd = True
    120.     If rst.RecordCount > 0 Then
    121.         rst.MoveFirst
    122.         Do While Not rst.EOF
    123.             Value = rst.Fields("TraceName")
    124.             If Trim(UCase(latesttracename)) = Trim(UCase(Value)) Then
    125.                 traceid(t) = rst.Fields("TraceId") 'save these to check for adding trace codes later
    126.                 'tr = tr + 1
    127.                 Exit Do
    128.             End If
    129.             rst.MoveNext
    130.         Loop
    131.     End If
    132.     rst.Close
    133. End If
    134. Next t

  2. #2

    Thread Starter
    Fanatic Member
    Join Date
    Jun 2002
    Posts
    586
    VB Code:
    1. 'CHARACTERISTIC
    2.     'Firstly, check to see if the characteristic already exists, a characteristic being
    3.     'a matching Charname and PartId combo within the Characteristic table.
    4.     dbAdd = True
    5.     charname(x) = Replace(charname(x), "&", "and")
    6.     charname(x) = Replace(charname(x), "#", "")
    7.     charname(x) = Replace(charname(x), Chr$(34), "")
    8.     sourcesqlstatement = "Select CharId, PartId, CharName from Characteristic where PartId = " & partid & " And CharName = '" & charname(x) & "'"
    9.     rst.Open sourcesqlstatement, cnn, adOpenStatic, adLockOptimistic
    10.     If rst.RecordCount > 0 Then
    11.         rst.MoveFirst
    12.         Do While Not rst.EOF
    13.             dbAdd = False
    14.             vcharid = rst.Fields("CharId")
    15.             Exit Do
    16.             rst.MoveNext
    17.         Loop
    18.     End If
    19.     rst.Close
    20.  
    21.     If dbAdd Then 'If the characteristic does not exist in the table, then
    22.         ' add a new record to the characteristic table
    23.         sql = "INSERT INTO Characteristic (PartId, CharName, LastEditDate, Target, USL, LSL, CharDataId, SubgroupSize, DecimalPlaces, ChartType, ShowHistogram, ShowLSL, ShowUSL, ShowTarget, ShowControlChart, IsRainbow, ValidateEntry, CurveFit, ValidateUpper, ValidateLower, ValidateRatio, ValidateSampleSize, BatchSize, BatchType, PlotLastCount, PlotLastType) VALUES (" & partid & ", '" & charname(x) & "', '" & Now & "', '" & target(x) & "', '" & USL(x) & "', '" & LSL(x) & "',0, '" & subgroupsize & "', 6, 3, 0, 1, 1, 1, 1, -1, 1, 1, 2.225074E-308, 2.225074E-308, 2.225074E-308, 0, 0, 0, 0, 0)"
    24.         cnn.Execute sql
    25.     Else 'If the characteristic does exist in the table, then
    26.         'just update the target, USL, and LSL of the existing record
    27.         sql = "UPDATE Characteristic SET Target = " & target(x) & ", " & "USL = " & USL(x) & ", " & "LSL = " & LSL(x) & " where CharId = " & vcharid
    28.         cnn.Execute sql
    29.         DoEvents
    30.     End If
    31.     dbAdd = True
    32.  
    33. 'TRACE CODES
    34. 'Firstly, open TraceCode table and check to ensure that no
    35. 'duplicate TraceCodeName and TraceId combos are inserted for each tracevalue(t, x)
    36.  
    37. For t = 1 To tracecount
    38.     whileflag = 1
    39.     dbAdd = True
    40.     If whileflag = 1 Then
    41.         sourcesqlstatement = "Select TraceId, TraceCodeName from TraceCodes where TraceCodeName <> ''"
    42.         rst.Open sourcesqlstatement, cnn, adOpenStatic, adLockOptimistic
    43.         If rst.RecordCount > 0 Then
    44.             rst.MoveFirst
    45.             Do While Not rst.EOF
    46.                 Value = rst.Fields("TraceCodeName")
    47.                 tid = rst.Fields("TraceId")
    48.                 If tid = traceid(t) And (Trim(UCase(Value)) = Trim(UCase(operator(x))) Or Trim(UCase(Value)) = Trim(UCase(serialnumber(x))) Or Trim(UCase(Value)) = Trim(UCase(trial(x))) Or Trim(UCase(Value)) = Trim(UCase(cam(x))) Or Trim(UCase(Value)) = Trim(UCase(check(x))) Or Trim(UCase(Value)) = Trim(UCase(grinder(x)))) Then
    49.                     dbAdd = False
    50.                     Exit Do
    51.                 End If
    52.                 rst.MoveNext
    53.             Loop
    54.             rst.Close
    55.         End If
    56.        
    57.         Select Case t
    58.             Case 1
    59.                 'insert OPERATOR
    60.                 tracevalue(t, x) = operator(x)
    61.                 If Len(operator(x)) > 0 And dbAdd = True Then
    62.                     sql = "INSERT INTO TraceCodes (TraceId, TraceCodeName, ActiveStatus) VALUES ('" & traceid(t) & "', '" & operator(x) & "', 0)"
    63.                     cnn.Execute sql
    64.                 End If
    65.            
    66.             Case 2
    67.                 tracevalue(t, x) = serialnumber(x)
    68.                 'insert SERIALNUMBER
    69.                 If Len(serialnumber(x)) > 0 And dbAdd = True Then
    70.                     sql = "INSERT INTO TraceCodes (TraceId, TraceCodeName, ActiveStatus) VALUES ('" & traceid(t) & "', '" & serialnumber(x) & "', 0)"
    71.                     cnn.Execute sql
    72.                 End If
    73.        
    74.             Case 3
    75.                 tracevalue(t, x) = trial(x)
    76.                 'insert TRIAL
    77.                 If Len(trial(x)) > 0 And dbAdd = True Then
    78.                     sql = "INSERT INTO TraceCodes (TraceId, TraceCodeName, ActiveStatus) VALUES ('" & traceid(t) & "', '" & trial(x) & "', 0)"
    79.                     cnn.Execute sql
    80.                 End If
    81.        
    82.             Case 4
    83.                 tracevalue(t, x) = cam(x)
    84.                 'insert CAM
    85.                 If Len(cam(x)) > 0 And dbAdd = True Then
    86.                     sql = "INSERT INTO TraceCodes (TraceId, TraceCodeName, ActiveStatus) VALUES ('" & traceid(t) & "', '" & cam(x) & "', 0)"
    87.                     cnn.Execute sql
    88.                 End If
    89.        
    90.             Case 5
    91.                 tracevalue(t, x) = check(x)
    92.                 'insert CHECK
    93.                 If Len(check(x)) > 0 And dbAdd = True Then
    94.                     sql = "INSERT INTO TraceCodes (TraceId, TraceCodeName, ActiveStatus) VALUES ('" & traceid(t) & "', '" & check(x) & "', 0)"
    95.                     cnn.Execute sql
    96.                 End If
    97.        
    98.             Case 6
    99.                 tracevalue(t, x) = grinder(x)
    100.                 'insert GRINDER
    101.                 If Len(grinder(x)) > 0 And dbAdd = True Then
    102.                     sql = "INSERT INTO TraceCodes (TraceId, TraceCodeName, ActiveStatus) VALUES ('" & traceid(t) & "', '" & grinder(x) & "', 0)"
    103.                     cnn.Execute sql
    104.                 End If
    105.         End Select
    106.     End If
    107.     DoEvents
    108. Next t
    109.  
    110. 'DATA
    111.     'First, get the last DataId in the present Data table, to later determine where the new
    112.     'data was inserted in the table. It will serve as
    113.     'an indication of where to start inserting the SubgroupLock values.
    114.     'The last DataId value will be asssigned to the variable lastDataId. This will assist in
    115.     'determining the SubgroupLockNumber and SubroupItem number.
    116.     sourcesqlstatement = "Select DataId From Data"
    117.     rst.Open sourcesqlstatement, cnn, adOpenStatic, adLockOptimistic
    118.     If rst.RecordCount > 0 Then
    119.         rst.MoveLast
    120.         Do While Not rst.EOF
    121.             lastDataId = rst.Fields("DataId")
    122.             Exit Do
    123.         Loop
    124.     Else
    125.         lastDataId = 1 'jrm 5/15/2003
    126.     End If
    127.     rst.Close
    128.  
    129.     'Secondly, obtain the proper partid
    130.     sourcesqlstatement = "Select PartId From Part Where PartName = '" & temppartname & "'"
    131.     rst.Open sourcesqlstatement, cnn, adOpenStatic, adLockOptimistic
    132.     rst.MoveFirst
    133.     dbAdd = True
    134.     Do While Not rst.EOF
    135.         partid = rst.Fields("PartId")
    136.         rst.MoveNext
    137.     Loop
    138.     rst.Close
    139.  
    140.     'Thirdly, obtain the CharId and the SubgroupSize, based on CharName and the PartId
    141.     sourcesqlstatement = "Select CharId, SubgroupSize From Characteristic Where PartId = " & partid & " And CharName = '" & charname(x) & "'"
    142.     rst.Open sourcesqlstatement, cnn, adOpenStatic, adLockOptimistic
    143.     If rst.RecordCount > 0 Then
    144.         rst.MoveFirst
    145.         dbAdd = True
    146.         Do While Not rst.EOF
    147.             Charid = rst.Fields("CharId")
    148.             subgroupsize = rst.Fields("SubgroupSize")
    149.             'subgroupItemNumber = n Mod subgroupsize
    150.             rst.MoveNext
    151.         Loop
    152.     End If
    153.     rst.Close
    154.  
    155.     'Fourthly, insert the data into the database
    156.     ddatetime(x) = Replace(ddatetime(x), Chr$(34), "")
    157.     sql1 = "INSERT INTO Data (CharId, [Value], [DateTime]"
    158.     sql2 = ") VALUES (" & Charid & ", " & dvalue(x) & ", '" & ddatetime(x) & "'"
    159.        
    160.     'add necessary trace info to the insert query
    161.     For Y = 1 To tracecount
    162.         temptracevalueY = Replace(tracevalue(Y, x), "&", "and")
    163.         temptracevalueY = Replace(temptracevalueY, Chr$(34), "")
    164.         temptracevalueY = Replace(temptracevalueY, "#", "")
    165.         sql1 = sql1 & ", Trace" & Y & ", TraceId" & Y
    166.         sql2 = sql2 & ", '" & temptracevalueY & "', " & traceid(Y)
    167.     Next Y
    168.     sql2 = sql2 & ")"
    169.     sql = sql1 & sql2
    170.     cnn.Execute sql
    171.        
    172.     'Fifthly, open the newest data record that contained the same CharId, and insert the appropriate Subgroup Item number, as well as the appropriate SubgroupLock value
    173.     sourcesqlstatement = "Select DataId, CharId, SubgroupItem, SubgroupLock From Data Where CharId = " & Charid & " And DataId > " & lastDataId & " ORDER BY DataId"
    174.     rst.Open sourcesqlstatement, cnn, adOpenStatic, adLockOptimistic
    175.     SubgroupItem = 0
    176.     rc = rst.RecordCount
    177.     If rc > 0 Then
    178.     rst.MoveFirst
    179.     rst.MoveLast
    180.     Do While Not rst.EOF
    181.         rst!SubgroupLock = rst!DataId
    182.         rst!SubgroupItem = 0
    183.         Exit Do
    184.     Loop
    185.     rst.MoveFirst
    186.     rst.Close
    187.     End If
    188.    
    189.     'display to the user where the program is at
    190.     pbimport.Min = 0
    191.     pbimport.Max = fc
    192.     DoEvents
    193.     Label5.Caption = "Total number of directories being imported: " & dircount & "; Presently on directory: " & presentdir & ";" & Chr(13) & "Total number of files in present directory: " & fc & "; Presently on file: " & partcount & ";" & Chr(13) & "Present directory: " & directory & ";" & Chr(13) & "Present file name: " & file(UBound(file)) & ";" & Chr(13) & "Present part name: " & temppartname & ";" & Chr(13) & "Number of data items in present file: " & xcount & " Presently on data item: " & x & "."
    194.     pbimport.Value = partcount
    195.  
    196. Next x
    197.  
    198. cnn.Close
    199. Exit Sub
    200. End Sub

  3. #3
    Supreme User Madboy's Avatar
    Join Date
    Oct 2003
    Location
    England
    Posts
    3,253
    It may be better to attach a project, or use the vbCode tags - easier to read then

  4. #4

    Thread Starter
    Fanatic Member
    Join Date
    Jun 2002
    Posts
    586
    Thanks for the tip. Sorry about that.

    Well, for instance, consider the query below:

    VB Code:
    1. sourcesqlstatement = "Select DataId, CharId, SubgroupItem, SubgroupLock From Data Where CharId = " & Charid & " And DataId > " & lastDataId & " ORDER BY DataId"

    What I'm doing is keeping track of the very lastly saved DataId to use as a standard for determining the next one.

    Is there some command that would just go and get the maximum DataId value, and maybe save some time, and not necesarily go through all bazillion data records to see if each is greater than the last id?

    Put another way, is there any way to start the search at the last data id rather than at the first?

    I'm figuring that for one, may save some time. So, any ideas for maximinzing the speed of the qeury above?

    Thank you,
    Jim
    Last edited by JimMuglia; Mar 22nd, 2004 at 04:29 PM.

  5. #5

  6. #6

    Thread Starter
    Fanatic Member
    Join Date
    Jun 2002
    Posts
    586
    Thank you for that, and sorry for not seeing your signature earlier.
    So... any answers out there?

    Thank you,
    Jim
    Last edited by JimMuglia; Mar 22nd, 2004 at 04:32 PM.

  7. #7

  8. #8

    Thread Starter
    Fanatic Member
    Join Date
    Jun 2002
    Posts
    586
    Originally posted by MartinLiss
    I believe there are code analyzers that will show you where you are spending your execution time. You/your company might want to invest in one.
    Hmm, are there any websites with free downloads out there, that you know of?

  9. #9

  10. #10
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263
    As for getting the max value

    "SELECT MAX(columnname) FROM TABLE WHERE..." - will do just that...

    Do you have indexes on the columns that are being used in WHERE clauses (we do MS SQL 2000 here - not ACCESS, I'm not sure of what the differences are).

    Does ACCESS have provisions for STORED PROCEDURES?

  11. #11
    Frenzied Member Shawn N's Avatar
    Join Date
    Dec 2001
    Location
    Houston
    Posts
    1,631
    I see some room for improvement. For example, in the beginning of your procedure where you're loading "tempname" you could turn tempname into an array, load all your part name's into that array, and load all your partname's (as you're already doing) into rst.

    Then you could use 2 nested for/next loops to iterate through the array and recordset.

    You'd probably get a little more help if you actually posted your project.
    Please rate my post.

  12. #12

    Thread Starter
    Fanatic Member
    Join Date
    Jun 2002
    Posts
    586
    I really appreciate everyone's input.

    Hmmm, I think I'll have to do the array idea at least for the characteristics, as there are several records in that, which must be searched by two PK fields: PartId and CharName. I really think that's what's making the program go like molasses. That's gottabe what's bogging it down.

    One other qeustion, would doing an insert this way save any time, or is it just prettier than the "insert into trace..." style?

    With rst
    .AddNew
    !tracename = temptracename
    !lasteditdate = Now
    !LastEdit = "SPC AutoCollector"
    !GroupID = -1
    !ISAccA = 0
    !StoreTraceCodes = 0
    !ActiveStatus = 0
    !Persistent = 0
    .Update
    .Close
    End With

  13. #13
    PowerPoster
    Join Date
    Nov 2002
    Location
    Manila
    Posts
    7,629
    This would be easier if the project and the database (just some smple data) where attached.

    You have part() right? Instead of looping through that and checking each if it already exists in the database for adding, I would create a query that would return all records not in part(). Then iterate through those... hopefully less iterations.

    Something like the inverse of...
    VB Code:
    1. Private Function Build_ShapeCommand() As String
    2.  
    3. Dim strWHERE_Supplier() As String
    4. Dim strWHERE_TestMat() As String
    5. Dim strWHERE_Subtest() As String
    6. Dim strWHERE_Misc() As String
    7.  
    8.    strWHERE_Misc = Build_WHERE_Misc
    9.    strWHERE_Subtest = Build_WHERE_Subtest
    10.    strWHERE_Supplier = Build_WHERE_Supplier
    11.    strWHERE_TestMat = Build_WHERE_TestMaterial
    12.  
    13.    strWHERE = "WHERE (1 = 1) "
    14.    strWHERE = strWHERE & IIf(strWHERE_Misc(UBound(strWHERE_Misc)) <> "", "AND " & Join(strWHERE_Misc, " AND ") & " ", "")
    15.    strWHERE = strWHERE & IIf(strWHERE_Subtest(UBound(strWHERE_Subtest)) <> "", "AND (" & Join(strWHERE_Subtest, " OR ") & ") ", "")
    16.    strWHERE = strWHERE & IIf(strWHERE_Supplier(UBound(strWHERE_Supplier)) <> "", "AND (" & Join(strWHERE_Supplier, " OR ") & ") ", "")
    17.    strWHERE = strWHERE & IIf(strWHERE_TestMat(UBound(strWHERE_TestMat)) <> "", "AND (" & Join(strWHERE_TestMat, " OR ") & ") ", "")
    18.    strWHERE = strWHERE & " "
    19.  
    20. 'blah
    21. 'blah
    22. End Sub
    23.  
    24. Private Function Build_WHERE_Subtest() As String()
    25. Dim strWHERE() As String
    26. Dim lngIterate As Long
    27.  
    28.    ReDim strWHERE(0)
    29.    Build_WHERE_Subtest = strWHERE   'init value
    30.    
    31.    'Check for CheckAll and CheckNone conditions
    32.    If chkSubTest.Value = vbUnchecked Then Exit Function 'Unfiltered
    33.    If (lvwSubtest.ListItems.Count > 0) And (cmdSubtestChkAll.Enabled = False) Then
    34.       Exit Function  'return all
    35.    ElseIf (lvwSupplier.ListItems.Count > 0) And (cmdSubtestChkNone.Enabled = False) Then
    36.       strWHERE(0) = "([PO Details].[Subtest ID] = '')"   'return none
    37.    Else
    38.       '(F = x) or (F = y) or..., create (F = ) condition if checked
    39.       For lngIterate = 1 To lvwSubtest.ListItems.Count
    40.          If lvwSubtest.ListItems(lngIterate).Checked = True Then
    41.             If strWHERE(UBound(strWHERE)) <> "" Then ReDim Preserve strWHERE(UBound(strWHERE) + 1)
    42.             strWHERE(UBound(strWHERE)) = "([PO Details].[Subtest ID] = '" & lvwSubtest.ListItems(lngIterate).Text & "') "
    43.          End If
    44.       Next
    45.    End If
    46.    
    47.    If strWHERE(UBound(strWHERE)) = "" And UBound(strWHERE) > 0 Then
    48.       ReDim Preserve strWHERE(UBound(strWHERE) - 1)  'Delete appending blank if any
    49.    End If
    50.    
    51.    Build_WHERE_Subtest = strWHERE
    52. End Function
    Last edited by leinad31; Mar 23rd, 2004 at 11:12 AM.

  14. #14

    Thread Starter
    Fanatic Member
    Join Date
    Jun 2002
    Posts
    586
    Originally posted by leinad31
    This would be easier if the project and the database (just some smple data) where attached.
    I really appreciate the desire to see the whole program; and I'd send all of that in a heartbeat if my boss would let me.

    Well, if we can at least get me set up with making this quicker, that would be where I need to go anyways. I'll test things out here; if anyone has any modifcations to speed this CHARACTERISTIC portion up, please let me know. It sure is slowing things down.

    VB Code:
    1. 'CHARACTERISTIC
    2.     'Firstly, check to see if the characteristic already exists, a characteristic being
    3.     'a matching Charname and PartId combo within the Characteristic table.
    4.     dbAdd = True
    5.     charname(x) = Replace(charname(x), "&", "and")
    6.     charname(x) = Replace(charname(x), "#", "")
    7.     charname(x) = Replace(charname(x), Chr$(34), "")
    8.     sourcesqlstatement = "Select CharId, PartId, CharName from Characteristic where PartId = " & partid & " And CharName = '" & charname(x) & "'"
    9.     rst.Open sourcesqlstatement, cnn, adOpenStatic, adLockOptimistic
    10.     If rst.RecordCount > 0 Then
    11.         rst.MoveFirst
    12.         Do While Not rst.EOF
    13.             dbAdd = False
    14.             vcharid = rst.Fields("CharId")
    15.             Exit Do
    16.             rst.MoveNext
    17.         Loop
    18.     End If
    19.     rst.Close
    20.  
    21.     If dbAdd Then 'If the characteristic does not exist in the table, then
    22.         ' add a new record to the characteristic table
    23.         sql = "INSERT INTO Characteristic (PartId, CharName, LastEditDate, Target, USL, LSL, CharDataId, SubgroupSize, DecimalPlaces, ChartType, ShowHistogram, ShowLSL, ShowUSL, ShowTarget, ShowControlChart, IsRainbow, ValidateEntry, CurveFit, ValidateUpper, ValidateLower, ValidateRatio, ValidateSampleSize, BatchSize, BatchType, PlotLastCount, PlotLastType) VALUES (" & partid & ", '" & charname(x) & "', '" & Now & "', '" & target(x) & "', '" & USL(x) & "', '" & LSL(x) & "',0, '" & subgroupsize & "', 6, 3, 0, 1, 1, 1, 1, -1, 1, 1, 2.225074E-308, 2.225074E-308, 2.225074E-308, 0, 0, 0, 0, 0)"
    24.         cnn.Execute sql
    25.     Else 'If the characteristic does exist in the table, then
    26.         'just update the target, USL, and LSL of the existing record
    27.         sql = "UPDATE Characteristic SET Target = " & target(x) & ", " & "USL = " & USL(x) & ", " & "LSL = " & LSL(x) & " where CharId = " & vcharid
    28.         cnn.Execute sql
    29.         DoEvents
    30.     End If
    31.     dbAdd = True

  15. #15

    Thread Starter
    Fanatic Member
    Join Date
    Jun 2002
    Posts
    586
    Well, I got the code to go a lot faster with some tinkering and some help.

    Now I am interested in this question:

    Would the program be even faster if they were using a SQLServer database, instead of an Access database?

    Or would it not make a difference?

    I know SQLServer is good for larger quantities of data; but would it any way effect the speed of my program?

    Thank you,
    Jim

  16. #16
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263
    SQL is designed for true client server application. This means that you have a different processor running the queries. You would want to stop building "query strings" in VB and executing those commands and instead develop stored procedures on the server - passing parameters with ADO from VB to these procedures. They are pre-compiled and optimized - run much faster.

    MSDE is a version of SQL that runs on a standalone workstation with the client code (it is just the data engine).

    Visit this website and post your question to them...

    http://www.microsoft.com/sql/communi...lserver.server

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