Jump to content
Sign in to follow this  
Groumphy

Not a problem... A question !

Recommended Posts

Groumphy

Hello,

This time I call you not for a problem, but I don't understand a script...

For my training with the scripting, I use this UDF and more precisely the following functions:

;===============================================================================
; Function Name:    RegisterGenerate()
; Description:      Generates the final register number.
; Parameter(s):     $RegName - The person's full name
;                   $RegMail - The person's email
;                   $RegNumber - The verification number
; Return Value(s):  On Success - Returns the final register number. Format -> NNNNN-NNNNN-NNNNN-NNNNN
;                   On Failure - Returns 0 and sets @ERROR = 1
; Author(s):        CoePSX
;===============================================================================
Func RegisterGenerate($RegName, $RegMail, $RegNumber)
    If $RegName = "" Or $RegMail = "" Or $RegNumber = "" Then
        SetError(1)
        Return(0)
    EndIf
    Return(RegGetCode(1, $RegName, $RegMail, $RegNumber))
EndFunc
;===============================================================================
; Function Name:    OrderRegister()
; Description:      Creates a verification number to be sent with a name and an email as an order.
; Parameter(s):     $RegName - The person's full name
;                   $RegMail - The person's email
; Return Value(s):  On Success - Returns the verification number. Format -> NNNNN-NNNNN-NNNNN-NNNNN
;                   On Failure - Returns 0 and sets @ERROR = 1
; Author(s):        CoePSX
;===============================================================================
Func OrderRegister($RegName, $RegMail)
    If $RegName = "" Or $RegMail = "" Then
        SetError(1)
        Return(0)
    EndIf
    Return(RegGetCode(0, $RegName, $RegMail))
EndFunc
;===============================================================================
; Function Name:    Stretch()
; Description:      
; Parameter(s):     $Macro  - 1 to Encrypt, 0 to Decrypt
;                   $Mode   -
;                   $Size   -
; Return Value(s):  On Success - Return $Temp value
;                   On Failure - Returns 0
; Author(s):        CoePSX
;===============================================================================
Func Stretch($Macro, $Mode, $Size = 5)
    If $Macro = "" Then Return(0)
    $Macro = _StringEncrypt(1, $Macro, $Mode, 1)
    Local $Length = StringLen($Macro)
    Local $Temp = $Macro
    If $Length > $Size Then
        $Array = StringSplit($Macro, "")
        Do
            $Temp = ""
            For $i = 1 To $Array[0]-1 Step 1
                $Temp = $Temp & Mod(($Array[$i] + $Array[$i+1]), 10)
            Next
            $Length = StringLen($Temp)
            $Array = StringSplit($Temp, "")
        Until $Length = $Size
    Else
        If $Length < $Size Then
            $Temp = $Macro
            Do
                $Temp = $Temp * 2
                $Length = StringLen($Temp)
            Until $Length = $Size
        EndIf
    EndIf
    Return $Temp
EndFunc
;===============================================================================
; Function Name:    RegGetCode()
; Description:      
; Parameter(s):     $Mode   - 0, place "-" each $Number caracter ; 1, replace "" by "-" each $Number caracter
;                   $Name   - => $RegName in the function
;                   $Email  - => $RegMail in the functino
;                   $Number -
; Return Value(s):  On Success - Return à OEM Number
;                   On Failure - Returns 0
; Author(s):        CoePSX
;===============================================================================
Func RegGetCode($Mode, $Name, $Email, $Number = 0)
    If $Name = "" Or $Email = "" Then
        Return(0)
    EndIf   
    If $Mode = 1 Then
        $Temp = StringReplace($Number, "-", "")
        $Temp = Stretch($Temp, 1, 10)
        $Temp = StringLeft($Temp, 5) & "-" & StringTrimLeft($Temp, 5)
        Return(Stretch($Name, 1) & "-" & Stretch($Email, 1) & "-" & $Temp)
    Else
        $Temp = Stretch(@UserName & @ComputerName, 0, 20)
        Return(StringLeft($Temp, 5) & "-" & StringMid($Temp, 6, 5) & "-" & StringMid($Temp, 11, 5) & "-" & StringRight($Temp, 5))
    EndIf   
EndFunc

This work !

... Why ?? The function is the same...

Thanks for your explain,

Groumphy


----------------------GroumphyMore information about me [Fr]

Share this post


Link to post
Share on other sites
Uten

This line is changed in the second sample:

$s_OrderRegister = OrderRegister($s_computerID[1], $s_computerID[2])

So, what happens? Do you never reach msgbox in the first sample? Or do you reach msgbox and don't get the expected result?

Share this post


Link to post
Share on other sites
Uten

This is what I get when I run the provided code (modified to run in scite):

>"D:\portableapps\PortableApps\autoit-v3.2.3.0\SciTe\..\autoit3.exe" /ErrorStdOut "C:\slettes\test.au3"

(12) := (1)(0) : $s_OrderRegister:=0

(13) := (0)(0) : $s_RegisterGenerate:=0

(18) := (1)(0) : $s_OrderRegister:=0

(19) := (0)(0) : $s_RegisterGenerate:=0

>Exit code: 0 Time: 0.297

Global $s_computerID = StringSplit(";;c:\",";")        ; Computer ID
$s_computerID[1] = DriveGetLabel($s_computerID[3])
$s_computerID[2] = DriveGetSerial($s_computerID[3])
testUdfTest1()
testUdfTest2()
Func testUdfTest1()
    $s_OrderRegister = RegGetCode(1,$s_computerID[1], $s_computerID[2])     ; OrderRegister($RegName, $RegMail)                                                                         ; = Return(RegGetCode(0, $RegName, $RegMail))
    $s_RegisterGenerate = RegisterGenerate($s_computerID[1], $s_computerID[2], $s_OrderRegister)
    dbg( "$s_OrderRegister:=" & $s_OrderRegister )
    dbg(" $s_RegisterGenerate:=" & $s_RegisterGenerate)
EndFunc
Func testUdfTest2()
    $s_OrderRegister = OrderRegister($s_computerID[1], $s_computerID[2])
    $s_RegisterGenerate = RegisterGenerate($s_computerID[1], $s_computerID[2], $s_OrderRegister)
    dbg( "$s_OrderRegister:=" & $s_OrderRegister )
    dbg(" $s_RegisterGenerate:=" & $s_RegisterGenerate)
EndFunc
Func dbg($msg, $line=@ScriptLineNumber, $err=@error, $ext=@extended)
    ConsoleWrite("(" & $line & ") := (" & $err & ")(" & $ext & ") : " & $msg & @CRLF)
EndFunc

Share this post


Link to post
Share on other sites
Groumphy

Cool !

>Running AU3Check (1.54.6.0)  params:  from:C:\Program Files\AutoIt3
+>13:23:25 AU3Check ended.rc:0
>Running:(3.2.2.0):C:\Program Files\AutoIt3\autoit3.exe "d:\profiles\Groumphy\Desktop\test.au3" 
(22) := (0)(0) : $s_OrderRegister:=82894-78944-12833-25952
(23) := (0)(0) :  $s_RegisterGenerate:=82894-78944-96088-27005

But I don't have the end... This loop without end :

+>13:23:56 AutoIT3.exe ended.rc:0
+>13:23:57 AutoIt3Wrapper Finished
>Exit code: 0   Time: 32.390

And the line 22/23 come from the testUdfTest1() and the testUdfTest2() don't give anything...

Edited by Groumphy

----------------------GroumphyMore information about me [Fr]

Share this post


Link to post
Share on other sites
Uten

Come to think of it I should have rearanged the code like this

Func testUdfTest1()
    $s_OrderRegister = RegGetCode(1,$s_computerID[1], $s_computerID[2])     ; OrderRegister($RegName, $RegMail)                                                                         ; = Return(RegGetCode(0, $RegName, $RegMail))
    dbg( "$s_OrderRegister:=" & $s_OrderRegister )
    $s_RegisterGenerate = RegisterGenerate($s_computerID[1], $s_computerID[2], $s_OrderRegister)
    dbg(" $s_RegisterGenerate:=" & $s_RegisterGenerate)
EndFunc
Func testUdfTest2()
    $s_OrderRegister = OrderRegister($s_computerID[1], $s_computerID[2])
    dbg( "$s_OrderRegister:=" & $s_OrderRegister )
    $s_RegisterGenerate = RegisterGenerate($s_computerID[1], $s_computerID[2], $s_OrderRegister)
    dbg(" $s_RegisterGenerate:=" & $s_RegisterGenerate)
EndFunc

Witch gives:

(11) := (0)(0) : $s_OrderRegister:=0

(13) := (1)(0) : $s_RegisterGenerate:=0

(17) := (1)(0) : $s_OrderRegister:=0

(19) := (1)(0) : $s_RegisterGenerate:=0

>Exit code: 0 Time: 0.297

As you can see from the output (1)(0) the error flag is set in my case. Have not spent the time to figure it out. Could be a missing library?

Share this post


Link to post
Share on other sites
Uten

Looks like the problem is in your testUdfTest2.

So put some dbg lines in there to figure out where it starts to loop (or wait for something).

Share this post


Link to post
Share on other sites
Groumphy

Can you try this script ?

#include <string.au3>
Global $s_computerID = StringSplit(";;c:\",";")        ; Computer ID
$s_computerID[1] = DriveGetLabel($s_computerID[3])
$s_computerID[2] = DriveGetSerial($s_computerID[3])
testUdfTest1()
testUdfTest2()
Func testUdfTest1()
    $s_OrderRegister = RegGetCode(1,$s_computerID[1], $s_computerID[2])     ; OrderRegister($RegName, $RegMail)                   ; = Return(RegGetCode(0, $RegName, $RegMail))
    dbg( "$s_OrderRegister:=" & $s_OrderRegister )
    $s_RegisterGenerate = RegisterGenerate($s_computerID[1], $s_computerID[2], $s_OrderRegister)
    dbg(" $s_RegisterGenerate:=" & $s_RegisterGenerate)
EndFunc
Func testUdfTest2()
    $s_OrderRegister = OrderRegister($s_computerID[1], $s_computerID[2])
    dbg( "$s_OrderRegister:=" & $s_OrderRegister )
    $s_RegisterGenerate = RegisterGenerate($s_computerID[1], $s_computerID[2], $s_OrderRegister)
    dbg(" $s_RegisterGenerate:=" & $s_RegisterGenerate)
EndFunc
Func dbg($msg, $line=@ScriptLineNumber, $err=@error, $ext=@extended)
    ConsoleWrite("(" & $line & ") := (" & $err & ")(" & $ext & ") : " & $msg & @CRLF)
EndFunc
;===============================================================================
; Function Name:    RegisterGenerate()
; Description:      Generates the final register number.
; Parameter(s):     $RegName - The person's full name
;                   $RegMail - The person's email
;                   $RegNumber - The verification number
; Return Value(s):  On Success - Returns the final register number. Format -> NNNNN-NNNNN-NNNNN-NNNNN
;                   On Failure - Returns 0 and sets @ERROR = 1
; Author(s):        CoePSX
;===============================================================================
Func RegisterGenerate($RegName, $RegMail, $RegNumber)
    If $RegName = "" Or $RegMail = "" Or $RegNumber = "" Then
        SetError(1)
        Return(0)
    EndIf
    Return(RegGetCode(1, $RegName, $RegMail, $RegNumber))
EndFunc
;===============================================================================
; Function Name:    OrderRegister()
; Description:      Creates a verification number to be sent with a name and an email as an order.
; Parameter(s):     $RegName - The person's full name
;                   $RegMail - The person's email
; Return Value(s):  On Success - Returns the verification number. Format -> NNNNN-NNNNN-NNNNN-NNNNN
;                   On Failure - Returns 0 and sets @ERROR = 1
; Author(s):        CoePSX
;===============================================================================
Func OrderRegister($RegName, $RegMail)
    If $RegName = "" Or $RegMail = "" Then
        SetError(1)
        Return(0)
    EndIf
    Return(RegGetCode(0, $RegName, $RegMail))
EndFunc
;===============================================================================
; Function Name:    Stretch()
; Description:      
; Parameter(s):     $Macro  - 1 to Encrypt, 0 to Decrypt
;                   $Mode   -
;                   $Size   -
; Return Value(s):  On Success - Return $Temp value
;                   On Failure - Returns 0
; Author(s):        CoePSX
;===============================================================================
Func Stretch($Macro, $Mode, $Size = 5)
    If $Macro = "" Then Return(0)
    $Macro = _StringEncrypt(1, $Macro, $Mode, 1)
    Local $Length = StringLen($Macro)
    Local $Temp = $Macro
    If $Length > $Size Then
        $Array = StringSplit($Macro, "")
        Do
            $Temp = ""
            For $i = 1 To $Array[0]-1 Step 1
                $Temp = $Temp & Mod(($Array[$i] + $Array[$i+1]), 10)
            Next
            $Length = StringLen($Temp)
            $Array = StringSplit($Temp, "")
        Until $Length = $Size
    Else
        If $Length < $Size Then
            $Temp = $Macro
            Do
                $Temp = $Temp * 2
                $Length = StringLen($Temp)
            Until $Length = $Size
        EndIf
    EndIf
    Return $Temp
EndFunc
;===============================================================================
; Function Name:    RegGetCode()
; Description:      
; Parameter(s):     $Mode   - 0, place "-" each $Number caracter ; 1, replace "" by "-" each $Number caracter
;                   $Name   - => $RegName in the function
;                   $Email  - => $RegMail in the functino
;                   $Number -
; Return Value(s):  On Success - Return à OEM Number
;                   On Failure - Returns 0
; Author(s):        CoePSX
;===============================================================================
Func RegGetCode($Mode, $Name, $Email, $Number = 0)
    If $Name = "" Or $Email = "" Then
        Return(0)
    EndIf   
    If $Mode = 1 Then
        $Temp = StringReplace($Number, "-", "")
        $Temp = Stretch($Temp, 1, 10)
        $Temp = StringLeft($Temp, 5) & "-" & StringTrimLeft($Temp, 5)
        Return(Stretch($Name, 1) & "-" & Stretch($Email, 1) & "-" & $Temp)
    Else
        $Temp = Stretch(@UserName & @ComputerName, 0, 20)
        Return(StringLeft($Temp, 5) & "-" & StringMid($Temp, 6, 5) & "-" & StringMid($Temp, 11, 5) & "-" & StringRight($Temp, 5))
    EndIf   
EndFunc

P.S. : thanks for your attention and your help !!


----------------------GroumphyMore information about me [Fr]

Share this post


Link to post
Share on other sites
Groumphy

Oups, a topics at the same time...

Yes, this come from the testUdfTest2() who call the function OrderRegister($RegName, $RegMail) ...

This is this function who have problem :

Func OrderRegister($RegName, $RegMail)
    If $RegName = "" Or $RegMail = "" Then
        SetError(1)
        Return(0)
    EndIf
    Return(RegGetCode(0, $RegName, $RegMail))
EndFuncoÝ÷ Ù8^¥ªÚë^®Í7èÊz¯zÊ&zènW¦³}÷Ýh­ö¥¹ímêÞÉ覺éºÜ"¶azö¥¹í7ß}ÀÛaz«jg­z½.±ëayú%"îËb¢v®¶­s`¤gVæ27G&WF6b33c´Ö7&òÂb33c´ÖöFRÂb33cµ6¦RÒR bb33c´Ö7&òÒgV÷C²gV÷C²FVâ&WGW&â b33c´Ö7&òÒõ7G&ætVæ7'BÂb33c´Ö7&òÂb33c´ÖöFR Æö6Âb33c´ÆVæwFÒ7G&ætÆVâb33c´Ö7&ò Æö6Âb33cµFV×Òb33c´Ö7&ð bb33c´ÆVæwFfwC²b33cµ6¦RFVà b33c´'&Ò7G&æu7ÆBb33c´Ö7&òÂgV÷C²gV÷C² Fð b33cµFV×ÒgV÷C²gV÷C° f÷"b33c¶ÒFòb33c´'&³ÒÓ7FW b33cµFV×Òb33cµFV×fײÖöBb33c´'&²b33c¶Ò²b33c´'&²b33c¶³Ò æW@ b33c´ÆVæwFÒ7G&ætÆVâb33cµFV× b33c´'&Ò7G&æu7ÆBb33cµFV×ÂgV÷C²gV÷C² VçFÂb33c´ÆVæwFÒb33cµ6¦P VÇ6P bb33c´ÆVæwFfÇC²b33cµ6¦RFVà b33cµFV×Òb33c´Ö7&ð Fð b33cµFV×Òb33cµFV×¢  b33c´ÆVæwFÒ7G&ætÆVâb33cµFV× VçFÂb33c´ÆVæwFÒb33cµ6¦P VæD` VæD` &WGW&âb33cµFVפVæDgVæ0
Edited by Groumphy

----------------------GroumphyMore information about me [Fr]

Share this post


Link to post
Share on other sites
Uten

Strech should check _StringEncryp's return value and @error

You get looping conditions when _StringEncrypt fails.

Func Stretch($Macro, $Mode, $Size = 5)
    dbg("Stretch($Macro:=" & $Macro & ", $Mode:=" & $Mode & ", $Size:=" & $Size )
    If $Macro = "" Then Return(0)
    $Macro = _StringEncrypt(1, $Macro, $Mode, 1)
    dbg("Strech::$macro:=" & $macro)
    If $Macro="" Then
        dbg("ERROR: Strech::$macro IS EMPTY : " & $macro)
        SetError(10, 0, "")
        Return
    EndIf
    Local $Length = StringLen($Macro)
    Local $Temp = $Macro
    Local $c
    If $Length > $Size Then
        $Array = StringSplit($Macro, "")
        Do
            $Temp = ""
            For $i = 1 To $Array[0]-1 Step 1
                $Temp = $Temp & Mod(($Array[$i] + $Array[$i+1]), 10)
                ;dbg("$temp:=" & $temp)
                $c += 1
                If $c > 10000 Then 
                    SetError(1000, 0, 0)
                    ExitLoop
                EndIf
            Next
            $Length = StringLen($Temp)
            $Array = StringSplit($Temp, "")
        Until $Length = $Size
    Else
        If $Length < $Size Then
            $Temp = $Macro
            Do
                $Temp = $Temp * 2
                $Length = StringLen($Temp)
            Until $Length = $Size
        EndIf
    EndIf
    Return $Temp
EndFunc

Share this post


Link to post
Share on other sites
Groumphy

And an other "problem" (or inattention...) :

#include <String.au3>
_StringEncrypt ( $i_Encrypt, $s_EncryptText, $s_EncryptPassword [, $i_EncryptLevel ] )
oÝ÷ Ú)íä^+-z¶®Ý«­¢+Ø)Õ¹}MÑÉ¥¹¹ÉåÁÐ ÀÌØí¥}¹ÉåÁаÀÌØíÍ}¹ÉåÁÑQáаÀÌØí5½°ÀÌØí¥}¹ÉåÁÑ1Ù°ôĤ(¸¸¸¸¹¹¹¸¸¸)¹Õ¹(

I'm sorry :s

:shocked:


----------------------GroumphyMore information about me [Fr]

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  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.