Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Probably doing it the hardware. Database question...

Status
Not open for further replies.

wbeach

Technical User
Aug 30, 2007
1
CA
Ok so I will try to explain as best I can. I have a reporting system generating logging files every hour of the day for the whole month. I need to add up all these values into a grand total.

So what I was trying to do is do a readline to get the information and then input the information into a database.

Example of log file.
IP address Input Output Total
111.111.111.11 71836520 72412347 144248867
111.111.111.12 6743 0 6743

All I care about is the IP, and the total.

I was trying to use the split method, but that was when I thought it was tabs, not spaces and then I noticed that the amount of spaces isn't consistent as well because it changes for formating.

My guess is a readline to the right till it hits a space then do a readline from the right going left till it hits a space.

Any thoughts?
 
You could use a regular expression to search for multiple spaces, then replace those spaces with a Tab, you can then use the split routine on the line.

Code:
tmpStr = "111.111.111.11     71836520       72412347      144248867"

'Setup Regular Expression pattern
Set objRegExp = New RegExp
objRegExp.Pattern = "[ ]+"
objRegExp.IgnoreCase = True
objRegExp.Global = True

Set objMatch = objRegExp.Execute(tmpstr)
newStr = objRegExp.Replace(tmpstr, vbtab)
tmpArray = split(newstr,vbTab)

I'm not very good at regular expressions, so there may be an easier way of doing this, but I have tested the code and it does work.
 
Or Replace?

Code:
Set fs=Createobject("Scripting.FileSystemObject")
Set f=fs.OpenTextfile("Imp.Txt")
l=f.Readline

Do While Instr(l,"  ")>0
  l=Replace(l,"  "," ")
Loop

l=Replace(l," ",",")
al=Split(l,",")
 
Hi After a bit more testing I have refined the code a bit, you don't need the Set objMatch line

Code:
tmpStr = "111.111.111.11     71836520       72412347      144248867"
Wscript.Echo RexReplace(tmpStr, "\s+", vbTab)

Function RexReplace(Source, Pattern, Value)
	Set objRegExp = New RegExp
	objRegExp.Pattern = Pattern
	objRegExp.IgnoreCase = True
	objRegExp.Global = True
	RexReplace = objRegExp.Replace(Source, Value)
End Function

Hope it helps
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top