| Author |
Message |
xardoz Ashigaru
Joined: 31 Dec 1969 Posts: 108 Location: Napavine, WA USA
|
Posted: Thu Nov 24, 2005 4:16 pm Post subject: Need some C+ Programming done |
|
|
Yes, I know about Rent-A-Coder
But I want people I know for a small project, I have the code written in VB but it lags on a slower machine. I believe, maybe wrongly, that c+ would proform faster.
It is parsing a text file and loading a Access table with data
Anybody interested? $100-$200 |
|
| Back to top |
|
 |
Cerulean Gokenin
Joined: 22 Oct 2004 Posts: 742 Location: London, England
|
Posted: Thu Nov 24, 2005 4:53 pm Post subject: |
|
|
| Hold your horses there. You're better off optimizing the VB code than paying someone for a C++ version. Run your code through a profiler so you can see which sections need optimization - chances are it's not the language. |
|
| Back to top |
|
 |
aschenta *narf*
Joined: 07 May 2003 Posts: 548 Location: Windsor Ontario Canada
|
Posted: Thu Nov 24, 2005 6:06 pm Post subject: |
|
|
| Unless the parsing is the slow part i don't see c++ being much faster since the data access is basically the same. |
|
| Back to top |
|
 |
xardoz Ashigaru
Joined: 31 Dec 1969 Posts: 108 Location: Napavine, WA USA
|
Posted: Thu Nov 24, 2005 8:07 pm Post subject: |
|
|
| Yes, it is the parsing part. I thought C was lighting faster than VB, guess I was wrong.... How do I run the code thru an optimizer? |
|
| Back to top |
|
 |
Eric Idea Hamster
Joined: 21 Oct 2004 Posts: 679 Location: Bangor, Maine
|
Posted: Sat Nov 26, 2005 12:53 pm Post subject: |
|
|
You could post the code and we can take a look at it.
If your text file is in a standard format, then you might be able to connect to it directly with the database methods (you can do that with about any delimited fields).
The only way that other languages are faster in regular parsing is if you can use RegEx for parsing. VB doesn't natively support RegEx. |
|
| Back to top |
|
 |
xardoz Ashigaru
Joined: 31 Dec 1969 Posts: 108 Location: Napavine, WA USA
|
Posted: Sat Nov 26, 2005 9:37 pm Post subject: |
|
|
I will post the code, but the data is not just simple transfer a dimlimited text into a database fild, some parsing/spliting of data is involved...  |
|
| Back to top |
|
 |
xardoz Ashigaru
Joined: 31 Dec 1969 Posts: 108 Location: Napavine, WA USA
|
Posted: Sat Nov 26, 2005 9:50 pm Post subject: |
|
|
The data is not just simple transfer a dimlimited text into a database fild, some parsing/spliting of data is involved...
| Code: | Function ProcessJournals(strFileName As String, _
strFileDate As String, _
strJournalDatabase As String) As Boolean
Dim intFreeFile As Integer, strData As String
If Trim(strFileName) = "" Then Exit Function
Database_Connection strJournalDatabase
OpenRS , rsTemp, "Journal"
OpenRS , rsOutdoor, "OutdoorSales"
intFreeFile = FreeFile
On Error GoTo 0
Open strFileName For Input As intFreeFile
Do Until EOF(intFreeFile)
rsTemp.AddNew
Line Input #intFreeFile, strData
rsTemp.Fields(1).Value = Mid(strData, 1, 5) 'Trans Counter
If Trim(Mid(strData, 6, 3)) = 0 Then
rsTemp.Fields(2).Value = 0
Else
rsTemp.Fields(2).Value = Mid(strData, 6, 3) 'Record Type
End If
rsTemp.Fields(3).Value = Mid(strData, 9, 8) 'Date
rsTemp.Fields(4).Value = Mid(strData, 17, 6) 'Time
rsTemp.Fields(5).Value = Mid(strData, 23, 12) 'PLU #
rsTemp.Fields(6).Value = Mid(strData, 35, 4) 'Dept
rsTemp.Fields(7).Value = Mid(strData, 39, 20) 'Desc
rsTemp.Fields(8).Value = CDbl(Mid(strData, 59, 10)) 'Price
rsTemp.Fields(9).Value = Mid(strData, 69, 8) 'Quanity
' If rsTemp.Fields(2).Value = 18 And rsTemp.Fields(6).Value = 3 Then
' 'Debug.Print rsTemp.Fields(7).Value, rsTemp.Fields(8).Value, rsTemp.Fields(9).Value
' lngCount = lngCount + 1
' dPrice = dPrice + rsTemp.Fields(8).Value
' dQuan = dQuan + rsTemp.Fields(9).Value
' End If
rsTemp.Fields(10).Value = Mid(strData, 77, 12) 'Misc
rsTemp.Fields(11).Value = Mid(strData, 89, 1) 'Flag
rsTemp.Fields(12).Value = Mid(strData, 90, 1) 'Tax Flag
rsTemp.Fields(13).Value = Mid(strData, 91, 8) 'Misc Misc
rsTemp.Fields("Terminal").Value = CLng(Mid$(strFileName, InStrRev(strFileName, ".") - 1, 1))
rsTemp.Fields("Shift").Value = CLng(Mid$(strFileName, InStrRev(strFileName, ".") - 3, 1))
If rsTemp.Fields("Terminal").Value = 9 Then 'Fill Alternate Recordset
Select Case rsTemp.Fields(2).Value
Case "068"
rsOutdoor.AddNew
rsOutdoor.Fields(1).Value = CDbl(Mid(strData, 78, 2)) 'FP
If CDbl(Mid(strData, 59, 10)) = 0 Then 'Zero Dollar Sale
rsOutdoor.Fields(2).Value = 0
Else
rsOutdoor.Fields(2).Value = CDbl(Mid(strData, 81, 2)) 'Grade
End If
rsOutdoor.Fields(3).Value = Trim(Mid(strData, 39, 20)) 'Grade Name
rsOutdoor.Fields(5).Value = CDbl(Mid(strData, 59, 10)) 'Sales (Money)
rsOutdoor.Fields(8).Value = Trim(Mid(strData, 9, 8)) 'Date
rsOutdoor.Fields(9).Value = Trim(Mid(strData, 17, 6)) 'Time
rsOutdoor.Fields(10).Value = CDbl(Mid(strData, 1, 5)) 'Transaction Counter
Case "040"
rsOutdoor.Fields(6).Value = CDbl(Mid(strData, 59, 10)) 'Price Per Gallon
If rsOutdoor.Fields(2).Value = 0 Then
rsOutdoor.Fields(3).Value = "Unknown"
rsOutdoor.Fields(4).Value = 0
Else
rsOutdoor.Fields(4).Value = CDbl(Mid(strData, 82, 6)) 'Quanity
End If
Case "004"
rsOutdoor.Fields(7).Value = CDbl(Mid(strData, 79, 10)) 'Tendar Type
rsOutdoor.UpdateBatch
Case Else
End Select
End If
rsTemp.Fields("Source_File").Value = Mid$(strFileName, InStrRev(strFileName, "\") + 1)
rsTemp.Fields("FileDate").Value = strFileDate
rsTemp.UpdateBatch
Loop
Close intFreeFile
End Function |
|
|
| Back to top |
|
 |
Eric Idea Hamster
Joined: 21 Oct 2004 Posts: 679 Location: Bangor, Maine
|
Posted: Sun Nov 27, 2005 3:27 pm Post subject: |
|
|
Change all your "Mid(strData," to: "Mid$(strData,"
That will give you a small speed boost. Especially since your in a loop.
Next, convert the RS.AddNew into a rs.Execute and use an Insert Query. MEGA speed boost there.
This:
Trim(strFileName) = ""
Should be this:
LEN(Trim(strFileName)) = 0
But since it is outside of your loop, you won't notice a big improvement.
You should also use the StrComp function to compare strings. It will make a small improvement as well. But your biggest boost will come from using a Insert Query, and not the .AddNew (or .Edit) methods. |
|
| Back to top |
|
 |
bdi Nobody
Joined: 21 Oct 2004 Posts: 1646 Location: Chicago
|
Posted: Sun Nov 27, 2005 4:15 pm Post subject: |
|
|
| Quote: | Next, convert the RS.AddNew into a rs.Execute and use an Insert Query. MEGA speed boost there.
|
Yeah, you are hitting the recordset a ton of times in there. I agree this is probably the biggest hit. But with all the times Mid( is listed, I would do a find replace on it to Mid$( too. Generally, I see one or two and doubt it's a problem. In this case though, I could see it adding up, and for as quick as Ctrl+H Mid( {TAB} Mid$( Ctrl+A is, it's worth changing.
In Access you also might want to run some of the maintenance for the tables too. Hate to do a ton of work and just find out they needed fixed. |
|
| Back to top |
|
 |
xardoz Ashigaru
Joined: 31 Dec 1969 Posts: 108 Location: Napavine, WA USA
|
Posted: Sun Nov 27, 2005 6:36 pm Post subject: |
|
|
I have never used an insert Query, could you post an example?
Thank you for the help, each loop is about 4000 records, but the table are disposable  |
|
| Back to top |
|
 |
bdi Nobody
Joined: 21 Oct 2004 Posts: 1646 Location: Chicago
|
Posted: Sun Nov 27, 2005 7:30 pm Post subject: |
|
|
sqlConnection.Execute "INSERT INTO Journal (TransCounter, RecordType, ...)" & _
"VALUES '" & strTransCounter & "', '" & strRecordType & "'"
where sqlConnection is your connection object, TransCounter, RecordType, and ... are your field names, and the values variables (strTransCounter, strRecordType, etc) are the values you are plugging in. It's following the Syntax of Access or whatever DB you use and directly runs a SQL statement against it. |
|
| Back to top |
|
 |
|
Powered by phpBB © 2001, 2002 phpBB Group
|