Visual Basic Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming Languages - MoreVisual Basic Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
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  
Old November 14th, 2003, 10:10 PM
papamavs papamavs is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2003
Posts: 3 papamavs User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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

Reply With Quote
  #2  
Old November 15th, 2003, 04:47 AM
cleverpig cleverpig is offline
Contributing User
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Jul 2003
Posts: 1,152 cleverpig User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
Send a message via MSN to cleverpig
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

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreVisual Basic Programming > Problems Using RegExp in VB Script


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway