#147928 - 2005-09-15 07:53 PM
Building an array from right justified text
|
Gargoyle
MM club member
   
Registered: 2004-03-09
Posts: 1597
Loc: Valley of the Sun (Arizona, US...
|
I have a file that has this type of data in it... Sample Code:
T1 7/0: DS0's Active: 22 DS0's Active High Water Mark: 23 TimeSlot Type TotalCalls TotalDuration 1 pri 157 00:08:48 2 pri 129 01:06:24 3 pri 115 00:00:51 4 pri 124 00:02:57 5 pri 123 00:28:56 6 pri 126 00:08:48 7 pri 117 00:06:52 8 pri 97 00:00:21 9 pri 157 00:00:44 10 pri 111 00:10:56 11 pri 112 00:09:12 12 pri 120 00:05:03 13 pri 118 00:19:17 14 pri 107 00:02:30 15 pri 101 00:00:37 16 pri 124 00:04:26 17 pri 115 00:06:31 18 pri 108 00:34:02 19 pri 122 00:23:41 20 pri 120 00:02:43 21 pri 111 00:07:55 22 pri 145 00:06:46 23 pri 101 00:09:59 24 pri-sig 0 00:00:00
I want to build any array that will assign the Timeslot value and the TotalCalls Value to an array.
This is the code that I was attempting to use
Code:
Function Calc ($Name) DIM $Total, $out[], $Read, $R, $Counter, $TS
$Total = 0 ;Note = Array $CountTotal each element is equeal to the following list ; 0 = COX ; 1 = ACD Rolm ; 2 = ADOA ; 3 = Admin Rolm ; 4 = 12th Street ; 5 = Qwest ; 6 = Admin Down ; 7 = Not Defined
Open (1, "c:\tftp-root\recieve\"+$Name+"_CallCount.txt", 2)
For $Counter = 0 To 7 $R = ReadProfileString("C:\bin\t1des.ini", $Name, $Counter) $Read = ReadLine(1) While @ERROR = 0 If $Counter+":" = Right($Read,2) $TS = ReadLine(1) While @ERROR = 0 $Out = Split($TS, " ")
If UBound($out) => 23 Select Case $Out[6] = 0 $Total = $Total + $Out[23] Case $Out[6] = 1 $total = $total + $out[23] Case $Out[6] = 2 $total = $total + $out[23] Case $Out[6] = 3 $total = $total + $out[23] Case $Out[6] = 4 $total = $total + $out[23] Case $Out[6] = 5 $total = $total + $out[23] Case $Out[6] = 6 $total = $total + $out[23] Case $Out[6] = 7 $total = $total + $out[23] Case $Out[6] = 8 $total = $total + $out[23] Case $Out[6] = 9 $total = $total + $out[23] Case $Out[5] = 10 $total = $total + $out[23] Case $Out[5] = 11 $total = $total + $out[23] Case $Out[5] = 12 $total = $total + $out[23] Case $Out[5] = 13 $total = $total + $out[23] Case $Out[5] = 14 $total = $total + $out[23] Case $Out[5] = 15 $total = $total + $out[23] Case $Out[5] = 16 $total = $total + $out[23] Case $Out[5] = 17 $total = $total + $out[23] Case $Out[5] = 18 $total = $total + $out[23] Case $Out[5] = 19 $total = $total + $out[23] Case $Out[5] = 20 $total = $total + $out[23] Case $Out[5] = 21 $total = $total + $out[23] Case $Out[5] = 22 $total = $total + $out[23] Case $Out[5] = 23 $total = $total + $out[23] Case $Out[5] = 24 $total = $total + $out[23] EndSelect EndIf $TS = ReadLine(1) Loop Select Case $R = "Cox" $CountTotal[0] = $CountTotal[0] + $Total Case $R = "ACD_Rolm" $Counttotal[1] = $CountTotal[1] + $Total Case $R = "ADOA" $Counttotal[2] = $CountTotal[2] + $Total Case $R = "Admin_Rolm" $Counttotal[3] = $CountTotal[3] + $Total Case $R = "12th_Street" $Counttotal[4] = $CountTotal[4] + $Total Case $R = "Qwest" $Counttotal[5] = $CountTotal[5] + $Total Case $R = "Admin_Down" $Counttotal[6] = $CountTotal[6] + $Total Case $R = "" $Counttotal[7] = $CountTotal[7] + $Total EndSelect EndIf $Read = ReadLine(1) Loop ReDIM $Total Next
Close(1) Open (1, "c:\tftp-root\recieve\"+$Name+"_CallCount.txt", 4) WriteLine(1, @CRLF) WriteLine(1, "Count total for Cox circuits: "+$CountTotal[0]+@CRLF) WriteLine(1, "Count total for ACD Rolm circuits: "+$CountTotal[1]+@CRLF) WriteLine(1, "Count total for ADOA circuits: "+$CountTotal[2]+@CRLF) WriteLine(1, "Count total for Admin Rolm circuits: "+$CountTotal[3]+@CRLF) WriteLine(1, "Count total for 12th Street circuits: "+$CountTotal[4]+@CRLF) WriteLine(1, "Count total for Qwest circuits: "+$CountTotal[5]+@CRLF) WriteLine(1, "Count total for Admin Down circuits: "+$CountTotal[6]+@CRLF) WriteLine(1, "Count total for Undefined circuits: "+$CountTotal[7]+@CRLF)
Close (1)
EndFunction
I am just not getting how to grab a "right justified" value from a text file.
As alway's many thanks for your help.
_________________________
Today is the tomorrow you worried about yesterday.
|
|
Top
|
|
|
|
#147930 - 2005-09-15 08:19 PM
Re: Building an array from right justified text
|
Bryce
KiX Supporter
   
Registered: 2000-02-29
Posts: 3167
Loc: Houston TX
|
not sure if this is what you are after....
Code:
for each $item in GetData('data.txt') ? $item[0] " " $item[1] next
Function GetData($file) DIM $i, $data, $array[0] $data = loadfile($File) for $i = 4 to ubound($data) $array[$i-4] = trim(SubSTR($data[$i],1,7)),trim(SubSTR($data[$i],18,12)) redim preserve $array[$i-3] next If ubound($array) redim preserve $array[ubound($array)-2] Else $array=0 EndIf $getData=$array endfunction
;this Function will load the contents of a text file into an array Function loadfile($file) DIM $fso,$f,$fs $fso = CreateObject("Scripting.FileSystemObject") $f = $fso.GetFile($file) If @ERROR Exit(2) EndIf $fs = $f.OpenAsTextStream(1) $loadfile = Split($fs.Read($f.size),@CRLF) Exit(@ERROR) EndFunction
Edited by Bryce (2005-09-15 08:19 PM)
|
|
Top
|
|
|
|
#147934 - 2005-09-15 10:37 PM
Re: Building an array from right justified text
|
Les
KiX Master
   
Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
|
I think you are over-analyzing it. How hard can it be?
put the file into an array as Bryce demonstrated and then Split() each line into elements on the spaces since you don't need them anyway. Remove the resultant empty array elements with the ArrayPack() UDF, and Bob's your uncle.
Code:
Break On $Array = "T1 7/0:", " DS0's Active: 22", " DS0's Active High Water Mark: 23", " TimeSlot Type TotalCalls TotalDuration", " 1 pri 157 00:08:48", " 2 pri 129 01:06:24", " 3 pri 115 00:00:51", " 4 pri 124 00:02:57", " 5 pri 123 00:28:56", " 6 pri 126 00:08:48", " 7 pri 117 00:06:52", " 8 pri 97 00:00:21", " 9 pri 157 00:00:44", " 10 pri 111 00:10:56", " 11 pri 112 00:09:12", " 12 pri 120 00:05:03", " 13 pri 118 00:19:17", " 14 pri 107 00:02:30", " 15 pri 101 00:00:37", " 16 pri 124 00:04:26", " 17 pri 115 00:06:31", " 18 pri 108 00:34:02", " 19 pri 122 00:23:41", " 20 pri 120 00:02:43", " 21 pri 111 00:07:55", " 22 pri 145 00:06:46", " 23 pri 101 00:09:59", " 24 pri-sig 0 00:00:00"
For each $Line in $Array $Line ? For each $Element in ArrayPack(Split($Line,' ')) '['+$Element+']' ? Next Next
THe results are as follows: Code:
T1 7/0: [T1] [7/0:] DS0's Active: 22 [DS0's] [Active:] [22] DS0's Active High Water Mark: 23 [DS0's] [Active] [High] [Water] [Mark:] [23] TimeSlot Type TotalCalls TotalDuration [TimeSlot] [Type] [TotalCalls] [TotalDuration] 1 pri 157 00:08:48 [1] [pri] [157] [00:08:48] 2 pri 129 01:06:24 [2] [pri] [129] [01:06:24] 3 pri 115 00:00:51 [3] [pri] [115] [00:00:51] 4 pri 124 00:02:57 [4] [pri] [124] [00:02:57] 5 pri 123 00:28:56 [5] [pri] [123] [00:28:56] 6 pri 126 00:08:48 [6] [pri] [126] [00:08:48] 7 pri 117 00:06:52 [7] [pri] [117] [00:06:52] 8 pri 97 00:00:21 [8] [pri] [97] [00:00:21] 9 pri 157 00:00:44 [9] [pri] [157] [00:00:44] 10 pri 111 00:10:56 [10] [pri] [111] [00:10:56] 11 pri 112 00:09:12 [11] [pri] [112] [00:09:12] 12 pri 120 00:05:03 [12] [pri] [120] [00:05:03] 13 pri 118 00:19:17 [13] [pri] [118] [00:19:17] 14 pri 107 00:02:30 [14] [pri] [107] [00:02:30] 15 pri 101 00:00:37 [15] [pri] [101] [00:00:37] 16 pri 124 00:04:26 [16] [pri] [124] [00:04:26] 17 pri 115 00:06:31 [17] [pri] [115] [00:06:31] 18 pri 108 00:34:02 [18] [pri] [108] [00:34:02] 19 pri 122 00:23:41 [19] [pri] [122] [00:23:41] 20 pri 120 00:02:43 [20] [pri] [120] [00:02:43] 21 pri 111 00:07:55 [21] [pri] [111] [00:07:55] 22 pri 145 00:06:46 [22] [pri] [145] [00:06:46] 23 pri 101 00:09:59 [23] [pri] [101] [00:09:59] 24 pri-sig 0 00:00:00 [24] [pri-sig] [0] [00:00:00]
C:\KiXScripts>
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.
|
|
Top
|
|
|
|
#147935 - 2005-09-15 10:39 PM
Re: Building an array from right justified text
|
Bryce
KiX Supporter
   
Registered: 2000-02-29
Posts: 3167
Loc: Houston TX
|
This turns it into space delimited strings....
Code:
$data = loadfile('data.txt') for $i = 4 to ubound($data) While $length <> Len($data[$i]) $length = Len($data[$i]) $data[$i] = join(split($data[$i],' '),' ') Loop ? $data[$i] next
Edited by Bryce (2005-09-15 10:40 PM)
|
|
Top
|
|
|
|
#147937 - 2005-09-17 10:21 PM
Re: Building an array from right justified text
|
Sealeopard
KiX Master
   
Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
|
This might help as well, as the file IS fixed-width, right-justified or not. Code:
; some kind of fixed-length string $sString='' ; the positions where a new column begins $aiDelim=6,11,20,28,33,38 $asResult= FixedLength($sString,$result) function FixedLength($sString,$aiDelimPos) if not vartype($aiDelimPos) & 1892 exit 3 endif dim $iPos, $iMaxPos $iMaxPos=ubound($aiDelimPos) dim $asFields[$iMaxPos+1]
$asFields[0]=left($sString,$aiDelimPos[0]-1) for $iPos=0 to $iMaxPos-1 $asFields[$iPos+1]=''+substr($sString,$aiDelimPos[$iPos],$aiDelimPos[$iPos+1]-$aiDelimPos[$iPos]) next $asFields[$iPos+1]=''+substr($sString,$aiDelimPos[$iPos]) $FixedLength=$asFields endfunction
_________________________
There are two types of vessels, submarines and targets.
|
|
Top
|
|
|
|
Moderator: Glenn Barnas, NTDOC, Arend_, Jochen, Radimus, Allen, ShaneEP, Ruud van Velsen, Mart
|
0 registered
and 476 anonymous users online.
|
|
|