|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
1200+ fellow developers rate and compare features of the top IDEs, like Visual Studio, Eclipse, RAD, Delphi and others, across 13 categories. Enjoy this FREE Download of the IDE User Satisfaction Study by Evans Data Corporation. Download Now!
|
|
#1
|
|||
|
|||
|
Problems Using RegExp in VB Script
Hi all,
this is the first time I am using RegExp. I am trying to read the data from a .rtf file and parse it out to a SQL database table. Here is the sample data: 630 Abutiar,Khadar - Adherence Summary -------- Adherence -------- ------------------ Conformance ------------------ Scheduled Scheduled Actual Min. In Min.Out Perc. In +/- Min. Perc. In Percent of Percent of Activities Time Time Adhere Adhere Adhere Conform Conform Total Sched. Total Actual -------------------- --------- --------- ------- ------- ------ ------- -------- ------------ ------------ Logged In 114:21 99:44 5423 1438 79 % -877 87 % 62 % 54 % Logged Out 70:39 84:10 3722 561 88 % +811 119 % 38 % 46 % ==================== ========= ========= ======= ======= ====== ======= Total 185:00 183:54 9145 1999 82 % -66 547 Affandi, Valorie - Adherence Summary -------- Adherence -------- ------------------ Conformance ------------------ Scheduled Scheduled Actual Min. In Min.Out Perc. In +/- Min. Perc. In Percent of Percent of Activities Time Time Adhere Adhere Adhere Conform Conform Total Sched. Total Actual -------------------- --------- --------- ------- ------- ------ ------- -------- ------------ ------------ Logged In 142:30 89:19 4766 3784 56 % -3191 63 % 88 % 53 % Logged Out 19:00 78:48 791 593 69 % +3588 415 % 12 % 47 % ==================== ========= ========= ======= ======= ====== ======= Total 161:30 168:07 5557 4377 57 % +397 These are two sets of data from the file. I have several more similar sets of information in the .rtf file. From each set, I need the extension, agent name (630 Abutiar,Khadar in the first case), and the minutes in adherence and min out of adherence (9145, 1999 in the first case). The following is the code I am using: 'Variable definition DIM FSO DIM WSHShell DIM network DIM FSOStream DIM Conn DIM regEx DIM CurrentLine, RegVal, CurrentDay, Loop2Flag, SA, tSQL DIM AgentName, AgentExt DIM RecordCounter, DateToParse Const fsoForReading = 1 Const sql = "INSERT INTO FACT_IEX_ADHERENCE (AgentID, Name, Date) VALUES(" 'Create Objects Set WSHShell = Wscript.CreateObject("Wscript.Shell") Set Network = Wscript.CreateObject("Wscript.Network") Set FSO = CreateObject("Scripting.FileSystemObject") Set regEx = New RegExp Loop2Flag = False Do While Not FSOStream.AtEndOfStream CurrentLine = FSOStream.ReadLine RegVal = GetNameExt(CurrentLine) If RegVal <> "" Then Do While Loop2Flag= false and Not FSOStream.AtEndOfStream CurrentLine = FSOStream.ReadLine RegVal = TestRegExp(CurrentLine, "^Total") If RegVal <> "" Then Loop2Flag = True Loop If RegVal <> "" Then SA = TestRegExp(CurrentLine, "\d{1,3}\s\%") popup SA If SA <> "" Then Popup SA If len(SA) = 3 Then SA = int(left(SA, 1)) If len(SA) = 4 Then SA = int(left(SA, 2)) If len(SA) = 5 Then SA = int(left(SA, 3)) tSQL = SQL & AgentExt & ", " & SA & ", #" & CurrentDay & "2003#)" popup tSQL WriteSQL tSQL RecordCounter = RecordCounter + 1 Else Popup "SA was blank Line is = " & FSOStream.Line - 1 End If End If Loop2Flag = False End If Loop '************************************************ Function TestRegExp(strTarget, Pattern) Dim objMatch, objMatches, strReturn regEx.Pattern = Pattern regEx.IgnoreCase = True regEx.Global = True Set objMatches = regEx.Execute(strTarget) For Each objMatch in objMatches strReturn = objMatch.Value Next TestRegExp = strReturn End Function '************************************************ Function GetNameExt(CurrentLine) RegVal = TestRegExp(CurrentLine, "\d{3}\s[A-Z]+\,\s[A-Z]+") If RegVal <> "" Then AgentExt = left(RegVal, 4) AgentName = right(RegVal, Len(RegVal) - 3) GetNameExt = True Else GetNameExt = "" End If End Function '************************************************ Function WriteSQL(SQLtxt) Conn.Execute SQLtxt,,adCmdText + adExecuteNoRecords End Function Line 5 of the code [RegVal = GetNameExt(CurrentLine)] gives me 547 as the first result whereas it should be 630. Line 9 of the code [RegVal = TestRegExp(CurrentLine, "^Total")] is not reading the line that starts with Total". I am not sure what to do at this point. Any help would be greatly appreciated. Thanks a bunch in advance. P |
|
#2
|
|||
|
|||
|
I don't know how to resolve this problem,But i can Give u a regexp tutoail:http://www.zvon.org/other/PerlTutor...t/contents.html
|
![]() |
| Viewing: Dev Shed Forums > Programming Languages - More > Visual Basic Programming > Problems Using RegExp in VB Script |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|