Page 1 of 1 1
Topic Options
#112650 - 2004-01-28 12:48 AM Optimizing a script
@lejo @rias Offline
Starting to like KiXtart

Registered: 2003-09-02
Posts: 100
Loc: Medellin, Colombia
Hi, I create a script but this is very large... (code) Existe some way to reduce???
sentences obvios, etc? pls helpme tks

This kix read a 2 files, one from local pc other from server, el file server is converted to variable pc, and compared to local, if is different must delete local and write the correct....

Code:
  
; *******************************************************************
; * declare vars
; *******************************************************************
$Sucursal = SubStr(@WKSTA,2,3)
$Cargo = SubStr(@WKSTA,5,2)
$Codigo = SubStr(@WKSTA,7,2)
;********************************************************************

$Titulo="Sesions PCOMM"
$exclude='AX15','AX16','SV','SE'
If AScan($exclude,@WKSTA)=-1
?'validate medellin.acg and nacional.acg'
; validate that exist files to begin procedure
If Exist ('N:\VARIOS\MEDELLIN.ACG') AND ('N:\VARIOS\NACIONAL.ACG')
; validate if files exist and copy if need
If NOT Exist ("C:\Archivos de programa\Personal Communications\PRIVATE\Medellin.acg")
Copy "N:\Varios\MEDELLIN.ACG" "C:\Archivos de programa\Personal Communications\PRIVATE\"
EndIf
If NOT Exist ("C:\Archivos de programa\Personal Communications\PRIVATE\Nacional.acg")
Copy "N:\Varios\NACIONAL.ACG" "C:\Archivos de programa\Personal Communications\PRIVATE\"
EndIf
; save local file to check in array
$file='C:\Archivos de programa\Personal Communications\PRIVATE\Medellin.acg'
$ArrCurrentMed=readfile($file)
Dim $CurrentValues[5]
$CurrentValues[0]=" CP_ALIAS=U"
$CurrentValues[1]=" FQ_CP_NAME=MEDELLIM.U"
$CurrentValues[2]=" DEST_ADDRESS=420000"
$CurrentValues[3]=" FQ_ADJACENT_CP_NAME=MEDELLIM.C"
$CurrentValues[4]=" DEFAULT_PU_NAME=U"
$CurrentValues[5]=" LU_NAME=T"
Dim $CorrectValues[5]
$CorrectValues[0]=$CurrentValues[0]+$Sucursal+$Cargo+$Codigo
$CorrectValues[1]=$CurrentValues[1]+$Sucursal+$Cargo+$Codigo
$CorrectValues[2]=$CurrentValues[2]+$Sucursal+"00204"
$CorrectValues[3]=$CurrentValues[3]+$Sucursal+"G"
$CorrectValues[4]=$CurrentValues[4]+$Sucursal+$Cargo+$Codigo
$CorrectValues[5]=$CurrentValues[5]+$Sucursal+$Cargo+$Codigo
; save standard file from server in array
$file='N:\Varios\Medellin.ACG'
$arrFile=ReadFile($file)
; converting standar array file in one array with paramets valid
$cont=0
$line=0
$FileReady=0
$GenerarMed=0
While $line<=Ubound($arrFile) AND $cont<=Ubound($CurrentValues)
If InStr($arrFile[$line], $CurrentValues[$cont])
$arrFile[$line]=$CorrectValues[$cont]
$cont=$cont+1
EndIf
$line=$line+1
Loop
$x=Ubound($arrFile)-1
ReDim preserve $arrFile[$x]
; comparing array local with array converted
$line=1
While $line<=Ubound($arrFile)
If $ArrCurrentMed[$line]=$arrFile[$line]
; array equal do nothing
Else
; array dif must regenerate a local file
$GenerarMed=1
EndIf
$line=$line+1
Loop
If $GenerarMed=1
$file='C:\Archivos de programa\Personal Communications\PRIVATE\Medellin.acg'
Del $file
$=WriteFile($arrFile,$file)
$Tipo ="I"
$Comments="Se realizo la correccion en archivo Medellin.acg"
Gosub WriteLog
EndIf

; repiting process now for ohter file similiar nacional.acg

; save local file to check in array
$file='C:\Archivos de programa\Personal Communications\PRIVATE\Nacional.acg'
$ArrCurrentNal=readfile($file)
Dim $CurrentValues[5]
$CurrentValues[0]=" CP_ALIAS=U"
$CurrentValues[1]=" FQ_CP_NAME=NAL.U"
$CurrentValues[2]=" DEST_ADDRESS=420000"
$CurrentValues[3]=" FQ_ADJACENT_CP_NAME=NAL.C"
$CurrentValues[4]=" DEFAULT_PU_NAME=U"
$CurrentValues[5]=" LU_NAME=T"
Dim $CorrectValues[5]
$CorrectValues[0]=$CurrentValues[0]+$Sucursal+$Cargo+$Codigo
$CorrectValues[1]=$CurrentValues[1]+$Sucursal+$Cargo+$Codigo
$CorrectValues[2]=$CurrentValues[2]+$Sucursal+"00204"
$CorrectValues[3]=$CurrentValues[3]+$Sucursal+"G"
$CorrectValues[4]=$CurrentValues[4]+$Sucursal+$Cargo+$Codigo
$CorrectValues[5]=$CurrentValues[5]+$Sucursal+$Cargo+$Codigo
; save standard file from server in array
$file='N:\Varios\NACIONAL.ACG'
$arrFile=ReadFile($file)
; converting standar array file in one array with paramets valid
$cont=0
$line=0
$FileReady=0
$GenerarNal=0
While $line<=Ubound($arrFile) AND $cont<=Ubound($CurrentValues)
If InStr($arrFile[$line], $CurrentValues[$cont])
$arrFile[$line]=$CorrectValues[$cont]
$cont=$cont+1
EndIf
$line=$line+1
Loop
$x=Ubound($arrFile)-1
ReDim preserve $arrFile[$x]
; comparing array local with array converted
$line=1
While $line<=Ubound($arrFile)
If $ArrCurrentNal[$line]=$arrFile[$line]
; array equal do nothing
Else
; array dif must regenerate a local file
$GenerarNal=1
EndIf
$line=$line+1
Loop
If $GenerarNal=1
$file='C:\Archivos de programa\Personal Communications\PRIVATE\Nacional.acg'
Del $file
$=WriteFile($arrFile,$file)
$Tipo ="I"
$Comments="Se realizo la correccion en archivo Nacional.acg"
Gosub WriteLog
EndIf
Else
$Tipo ="W"
$Comments="SRV sin archivos"
Gosub WriteLog
EndIf
EndIf






; udf funcs


Function ReadFile($file)
Dim $lf, $t
$lf=Chr(10)
$f=FreeFileHandle
$=Open($f,$file)
If @error Exit @error EndIf
Do $t=$t+$lf+ReadLine($f) Until @error
$=Close($f)
$ReadFile=Split(SubStr($t,2),$lf)
EndFunction

Function WriteFile($array,$file)
Dim $f
$f=FreeFileHandle
$=Open($f,$file,5)
If @error Exit @error EndIf
For Each $line In $array
$=WriteLine($f,$line + @crlf)
Next
$=Close($f)
Exit @error
EndFunction




;Subrutins

:WriteLog
If Open(3,N:\Logs\instups.log,5)=0
$Y=WriteLine(3,@WKSTA+","+$Sucursal+","+$Titulo+","+@TIME+","+@DATE+","+$Tipo+","+$Comments+Chr(13)+Chr(10))
$=Close(3)
EndIf
Return



_________________________
Look always 4 the best...

Top
#112651 - 2004-01-28 03:14 AM Re: Optimizing a script
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11612
Loc: CA
Well if you're trying to keep a file or folder synched up then perhaps you would be better off using something like ROBOCOPY

Windows Server 2003 Resource Kit Tools

Top
#112652 - 2004-01-28 03:48 PM Re: Optimizing a script
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11163
Loc: Boston, MA, USA
Or an XCOPY /D.
_________________________
There are two types of vessels, submarines and targets.

Top
Page 1 of 1 1


Moderator:  Glenn Barnas, NTDOC, Arend_, Jochen, Radimus, Allen, ShaneEP, Ruud van Velsen, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 307 anonymous users online.
Newest Members
Thechadpma, CestMoi, MeMyselfAndI, Praveer, Ollero
17745 Registered Users

Generated in 0.029 seconds in which 0.011 seconds were spent on a total of 12 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org