Jump to content
Sign in to follow this  
Atticus

Code explication

Recommended Posts

Atticus

Hello everybody,

I have a problem. I used a code find on this forum but I don't know how to explain it. Can someone explain me this code line by line please.

Global $sFilePath = "\\Server\disqueCD\Commun XP CD\2008\CLIENTS\CREANCES CLTS EN COURS.xls" 
                $sFilePath = FileGetShortName($sFilePath)
                Global $oExcel = _ExcelBookOpen($sFilePath) 
                Global $avData = _ExcelReadArray($oExcel, 1, 1, 5000, 1, 1) 
                Global $iLastUsed = 0, $iNextRow = 0
                For $n = UBound($avData) - 1 To 1 Step -1
                    If StringStripWS($avData[$n], 8) <> "" Then 
                        $iLastUsed = $n
                        ExitLoop
                    EndIf
                Next
                If $iLastUsed Then 
                    $iNextRow = $iLastUsed + 1  
                EndIf

I thank you by advance

Share this post


Link to post
Share on other sites
rudi

Hello everybody,

I have a problem. I used a code find on this forum but I don't know how to explain it. Can someone explain me this code line by line please.

Well, I'm not going to explain every line, but I'll give you some hints where do readup all the stuff:

Look at Autoit's help file:

Global ...

FileGetShortName()

For $n = 20 To 1 Step -1
Next

UBound()

StringStripWS()                     

ExitLoop

If ... Then
ElseIf
Else
EndIf

For these have a look at ExcelCOM_UDF.AU3

_ExcelBookOpen() 
_ExcelReadArray()

Regards, Rudi.

Edited by rudi

Earth is flat, pigs can fly, and Nuclear Power is SAFE!

Share this post


Link to post
Share on other sites
Atticus

Thanks but I still don't understand this code, can someone please explain me. I need to understand that code.

Please.

thanks

Share this post


Link to post
Share on other sites
Kerros

Lets try this a different way. After reviewing the topics that Rudi suggested... What don't you understand?


Kerros===============================================================How to learn scripting: Figure out enough to be dangerous, then ask for assistance.

Share this post


Link to post
Share on other sites
SmOke_N

Thanks but I still don't understand this code, can someone please explain me. I need to understand that code.

Please.

thanks

You shouldn't need more explanation than this, if you do, then you shouldn't be using the udf(s) in question.
; Server file path
Global $sFilePath = "\\Server\disqueCD\Commun XP CD\2008\CLIENTS\CREANCES CLTS EN COURS.xls"
; Short name to server file path
$sFilePath = FileGetShortName($sFilePath)
; Read the Excel.au3 udf for specifics on these two  functions on what each parameter means
; Open the above xls file in excel
Global $oExcel = _ExcelBookOpen($sFilePath)
; Read the data into an array (again, read the excel udf to understand what the parameters are
Global $avData = _ExcelReadArray($oExcel, 1, 1, 5000, 1, 1)
; Global vars to distinguish cells used and what row you are currently on
Global $iLastUsed = 0, $iNextRow = 0
; For/Next loop going backwards from Max index to 1
For $n = UBound($avData) - 1 To 1 Step -1
    ; Strip all the whit spaces from the array element, if it actually has a value, proceed
    If StringStripWS($avData[$n], 8) <> "" Then
        $iLastUsed = $n
        ExitLoop
    EndIf
Next
; If something was actually found in the stripped array elements, pad it by one, and add it to the row variable
If $iLastUsed Then
    $iNextRow = $iLastUsed + 1    
EndIf

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Share this post


Link to post
Share on other sites
Atticus

Thanks a lot or your response. I have almost understand.

but I still don't understand this line

For $n = UBound($avData) - 1 To 1 Step -1

what is -1 to 1 Step -1

Thanks

Share this post


Link to post
Share on other sites
DaRam

Thanks a lot or your response. I have almost understand.

but I still don't understand this line

For $n = UBound($avData) - 1 To 1 Step -1

what is -1 to 1 Step -1

Thanks

UBound($avData) Is the Upper Bound (Max # of items) in the Array.

-1 ; You need to Discount it by 1 since the elements start from Zero.

The Loop starts from the last element of the Array and works it way backward to the first element, hence the directive to Step -1

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×