#171384 - 2006-12-12 10:07 PM
Re: read cell from excel then validate data
[Re: Gargoyle]
|
booey
Getting the hang of it
Registered: 2005-07-25
Posts: 76
Loc: USA
|
Thanks. I added the DirList code to the bottom of the script and edited the $File1 variable, but when ran nothing is happening. The script finishes without errors, but nothing happens. It just goes back to a command prompt. Do you have any idea what's going on? The complete script is below.
The script ran fine until I added the UDF and changed the $file1 variable, but I'm not sure what else I need to edit to get it to work. Any help would be appreciated. Thanks.
;Set script options If Not @LOGONMODE Break On Else Break Off EndIf Dim $RC $RC = SetOption("Explicit","On") $RC = SetOption("NoVarsInStrings","On") $RC = SetOption("NoMacrosInStrings","On") $RC = SetOption("WrapAtEOL","On")
Dim $objExcel, $File1, $File2, $Value ;$Values is a 2-dimensional array Dim $Values[1,0], $i ;$i is a counter $i = -1 ;(Path and) filename of first Excel workbook $File1 = DIRLIST("C:\kix\verify\*.xls",2) ;(Path and) filename of second Excel workbook $File2 = "C:\kix\verify\SIT.xls"
;Create Excel object $objExcel = CreateObject("Excel.Application") ;If creation object failed, an @ERROR <> 0 is returned If @ERROR = 0
;Open first Excel workbook $RC = $objExcel.Workbooks.Open($File1) ;Catch value in cell C6 $Value = $objExcel.Range("C6").Value ;Close workbook $objExcel.Application.Quit ;Open second Excel workbook $RC = $objExcel.Workbooks.Open($File2) ;Loop as long as values are found in column A While Not $objExcel.Range("A"+($i+2)).Value = "" ;Add 1 to counter $i $i = $i + 1 ;Resize 2-dimensional array $Values, preserving existing data ReDim preserve $Values[1,$i] ;Put value from column A in first dimension of array $Values[0,$i] = $objExcel.Range("A"+($i+1)).Value ;Put value from column B in second dimension of array $Values[1,$i] = $objExcel.Range("B"+($i+1)).Value Loop ;Close workbook $objExcel.Application.Quit Else
;Error handling ? "Error creating Excel object" ? "Error " + @ERROR + ": " + @SERROR ;End the KiXtart script Quit @ERROR
EndIf
;$j is a counter Dim $j For $j = 0 to $i Step 1 ;compare $Value with every value in the first dimension ;of the 2-dimensional array ;If values match, go into the if statement If $Values[0,$j] = $Value ;Here you can write your MOVE command Move $File1 $Values[1,$j] ;Error handling if move fails If @ERROR ? "Error moving file " + $File1 ? "Error " + @ERROR + ": " + @SERROR EndIf ;The value was found, end the for/next by making $j equal to $i $j = $i EndIf Next
;FUNCTION DirList ; ;AUTHOR Jens Meyer (sealeopard@usa.net) ; ;ACTION Returns an array with a list of files in a given directory ; ;VERSION 1.2 ; ;KIXTART 4.12 ; ;SYNTAX DIRLIST(DIRNAME [,OPTIONS]) ; ;PARAMETERS DIRNAME ; Required string containing the directory name ; ; OPTIONS ; Optional value for additional options, options are set bitwise ; 1 = include directories (denoted by a backslash) that match the search mask ; 2 = include full path ; 4 = search all subdirectories ; ;RETURNS array with a list of files, otherwise an empty string ; ;REMARKS none ; ;DEPENDENCIES none ; ;EXAMPLE $dirlist = DIRLIST("c:\*.*",1+2+4) ; ;KIXTART BBS http://www.kixtart.org/cgi-bin/ultimatebb.cgi?ubb=get_topic&f=12&t=000090 ; Function dirlist($dirname, optional $options) Dim $filename, $counter, $filepath, $mask Dim $list, $sublist, $subcounter
$counter=-1
$dirname=Trim($dirname) If $dirname='' $dirname=@CURDIR EndIf If Right($dirname,1)='\' $dirname=Left($dirname,Len($dirname)-1) EndIf If GetFileAttr($dirname) & 16 $mask='*.*' Else $mask=SubStr($dirname,InStrRev($dirname,'\')+1) $dirname=Left($dirname,Len($dirname)-Len($mask)-1) EndIf
ReDim $list[10] $filename=Dir($dirname+'\'+$mask) While $filename<>'' And @ERROR=0 If $filename<>'.' And $filename<>'..' Select Case (GetFileAttr($dirname+'\'+$filename) & 16) If $options & 1 $counter=$counter+1 If $options & 2 $list[$counter]=$dirname+'\'+$filename+'\' Else $list[$counter]=$filename+'\' EndIf EndIf If ($options & 4) $sublist=dirlist($dirname+'\'+$filename+'\'+$mask,4) If UBound($sublist)+1 ReDim preserve $list[UBound($list)+UBound($sublist)+1] For $subcounter=0 to UBound($sublist) $counter=$counter+1 If $options & 2 $list[$counter]=$dirname+'\'+$filename+'\'+$sublist[$subcounter] Else $list[$counter]=$filename+'\'+$sublist[$subcounter] EndIf Next EndIf EndIf Case ($options & 2) $counter=$counter+1 $list[$counter]=$dirname+'\'+$filename Case 1 $counter=$counter+1 $list[$counter]=$filename EndSelect If $counter mod 10 ReDim preserve $list[$counter+10] EndIf EndIf $filename = Dir('') Loop
If $counter+1 ReDim preserve $list[$counter] Else $list='' EndIf
If $mask<>'*.*' And ($options & 4) $filename=Dir($dirname+'\*.*') While $filename<>'' And @ERROR=0 If $filename<>'.' And $filename<>'..' If (GetFileAttr($dirname+'\'+$filename) & 16) $sublist=dirlist($dirname+'\'+$filename+'\'+$mask,4) If UBound($sublist)+1 ReDim preserve $list[UBound($list)+UBound($sublist)+1] For $subcounter=0 to UBound($sublist) $counter=$counter+1 If $options & 2 $list[$counter]=$dirname+'\'+$filename+'\'+$sublist[$subcounter] Else $list[$counter]=$filename+'\'+$sublist[$subcounter] EndIf Next EndIf EndIf EndIf $filename = Dir('') Loop EndIf
If $counter+1 ReDim preserve $list[$counter] Else $list='' EndIf
$dirlist=$list EndFunction
|
|
Top
|
|
|
|
Moderator: Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart
|
0 registered
and 1343 anonymous users online.
|
|
|