Jump to content

Recommended Posts

Posted

Hi Experts,

I've been searching a proper way on how to handle below code doing some combinations from 0-5 and I think I'm in the wrong path on doing the script. I need your advise experts on how to handle this concern.:(

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Run
            Call("RunClick") 
    EndSwitch
WEnd

Func RunClick()
        If GUICtrlRead($TrckNum) = 1 Then ; this is a radio button from my GUI
           Call("Combi") ; this is the issue where the value is if "1" then call the combi() function but it doesn't work.
        EndIf
EndFunc

Func Combi($Str, $MaxLen)
    Local $file3 = FileOpen(@scriptdir & "\TrackingNum.txt", 2)
    Sleep(500)
    $Numbrs = StringSplit("0,1,2,3,4,5", ",")
    Combi("", 3); combination of 3 from 0-5
    Dim $i
    if StringLen($Str) = $MaxLen Then
      FileWrite($file3, "Tracking Number = " & $Str & @CRLF)
      Return
    EndIf
      For $i = 1 to $Numbrs[0]
         Combi($Str & $Numbrs[$i], $MaxLen)
      Next
EndFunc

From that part of the script, the code won't work. I just need a proper arrangement with that script to work. Sorry experts if I ask this kind of thing, it's just messing-up my head a little bet.:sweating:

 

Thanks in advance Experts! If you need more information, please let me know.:>

 

BTW, fyi, this is a 3 combination numbers from 0-5. Purpose for this is to assign each number to our tracking database for each item (see below sample).

image.png.8fc1fc9582cb6db0f4938b8b6212e50b.png

Currently we are doing it manually inputting 3 unique numbers for their id. So, I was task to automate this by getting all possible combination from 0-5 and 0-9. But for now I'm still at the stage of 0-5. I just need to have this work for me to proceed.

 

Thanks!

KS15

Programming is "To make it so simple that there are obviously no deficiencies" or "To make it so complicated that there are no obvious deficiencies" by C.A.R. Hoare.

Posted

Post a runnable script so we know what you're doing.

Is this your GUI, or a third party GUI?

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Posted

@BrewManNH,

Actually, I am still starting the script so there's only few codes as for now.:> I was stacked on running the first item from radio button.:sweating:

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <ProgressConstants.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <File.au3>

#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 615, 438, 192, 124)
$Run = GUICtrlCreateButton("Run", 24, 127, 129, 33)
GUICtrlSetOnEvent(-1, "RunClick")
$Group1 = GUICtrlCreateGroup("Selection Range", 24, 15, 265, 97)
$TrckNum = GUICtrlCreateRadio("0 to 5", 48, 38, 65, 25)
$TrckNum2 = GUICtrlCreateRadio("0 to 9", 48, 62, 65, 25)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Edit1 = GUICtrlCreateEdit("", 296, 20, 304, 363)
GUICtrlSetData(-1, "")
$Progress = GUICtrlCreateProgress(296, 391, 305, 17)
$View = GUICtrlCreateButton("View Log", 24, 343, 129, 33)
$close = GUICtrlCreateButton("Close", 24, 383, 129, 33)
$Label1 = GUICtrlCreateLabel("Processing:", 296, 416, 307, 17)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Run
            Call("RunClick")
    EndSwitch
WEnd

Func RunClick()
        MsgBox(0,"","Clicked") ; working
        If GUICtrlRead($TrckNum) = 1 Then
           MsgBox(0,"","Tracking Number 0 to 9 selected") ;working
           Call("Combi")
        EndIf
EndFunc

Func Combi($Str, $MaxLen)
    MsgBox(0,"","Cobinations") ;not working
    Local $file3 = FileOpen(@scriptdir & "\TrackingNum.txt", 2)
    Sleep(500)
    $Numbrs  = StringSplit("0,1,2,3,4,5", ",")
    Combi("", 3)
    Dim $i
    if StringLen($Str) = $MaxLen Then
      GUICtrlSetData($Edit1, $Str & @CRLF, "1")
      FileWrite($file3, "Tracking Number = " & $Str & @CRLF)
      Return
    EndIf
      For $i = 1 to $Numbrs[0]
         Combi($Str & $Numbrs[$i], $MaxLen)
      Next
EndFunc

Here's the GUI and there's no third party on it.^_^

Programming is "To make it so simple that there are obviously no deficiencies" or "To make it so complicated that there are no obvious deficiencies" by C.A.R. Hoare.

Posted (edited)

Yes, @Nine. But that's the problem here, I can't use the call function due to parameters inside the combi() function. Any advise? Thanks!

PS, Need to use call function to separate each item on my radio button.

Edited by KickStarter15

Programming is "To make it so simple that there are obviously no deficiencies" or "To make it so complicated that there are no obvious deficiencies" by C.A.R. Hoare.

Posted
9 minutes ago, KickStarter15 said:

PS, Need to use call function to separate each item on my radio button.

No, you don't.

Just call the function directly, without using Call, and with the parameters your function needs. Nothing you're doing, or could plan to do, would require the use of Call.

BTW, your code is very recursive, and is not very well thought out in the Combi function.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Posted

Thanks, @BrewManNH. Tried calling the function directly and it running and yes it was recursive. Hmmp, any advise how to avoid such issue? maybe I'm just out of bounce here.:sweating:

Programming is "To make it so simple that there are obviously no deficiencies" or "To make it so complicated that there are no obvious deficiencies" by C.A.R. Hoare.

Posted

 

I don't know you want or need, you can see this example as a idea or how to make:

Global Const $GUI_EVENT_CLOSE = -3
Global Const $GUI_CHECKED = 1

Global $Form1_1 = GUICreate("Form1", 486, 439, -1, -1)
Global $Button_Run = GUICtrlCreateButton("Run", 24, 223, 129, 97)
Global $Group1 = GUICtrlCreateGroup("Selection Range", 24, 15, 137, 97)
Global $Radio_TrckNum = GUICtrlCreateRadio("0 to 5", 48, 38, 65, 25)
GUICtrlSetState(-1, $GUI_CHECKED)
Global $Radio_TrckNum_2 = GUICtrlCreateRadio("0 to 9", 48, 62, 65, 25)
GUICtrlCreateGroup("", -99, -99, 1, 1)
Global $Edit1 = GUICtrlCreateEdit("", 168, 20, 304, 363)
GUICtrlSetData(-1, "")
Global $ProgressBar = GUICtrlCreateProgress(168, 391, 305, 17)
Global $Button_ClearLog = GUICtrlCreateButton("Clear Log", 24, 343, 129, 33)
Global $Button_Close = GUICtrlCreateButton("Close", 24, 383, 129, 33)
Global $Label_Staus = GUICtrlCreateLabel("Processing:", 168, 416, 307, 17)
Global $LabelSTR = GUICtrlCreateLabel("STR", 24, 136, 36, 17)
Global $Input_String = GUICtrlCreateInput("String", 72, 136, 89, 21)
GUISetState(@SW_SHOW)

Global $nMsg, $iString, $iMaxLen
While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE, $Button_Close
            Exit
        Case $Button_Run
            RunClick()
        Case $Button_ClearLog
            GUICtrlSetData($Edit1, "")
    EndSwitch
WEnd

Func RunClick()
    _WriteLog(@CRLF & "Run Clicked")
    $iString = GUICtrlRead($Input_String)
    If GUICtrlRead($Radio_TrckNum) = $GUI_CHECKED Then
        _WriteLog("Tracking 0 to 5 selected")
        $iMaxLen = 5
    ElseIf GUICtrlRead($Radio_TrckNum_2) = $GUI_CHECKED Then
        _WriteLog("Tracking 0 to 9 selected")
        $iMaxLen = 9
    EndIf
    Combi($iString, $iMaxLen)
EndFunc   ;==>RunClick

Func Combi($Str, $MaxLen)
    _WriteLog("Processing....")
    _WriteLog("Cobinations 0 TO " & $MaxLen)
    Local $Numbrs
    If $MaxLen = 5 Then
        $Numbrs = StringSplit("0,1,2,3,4,5", ",")
    ElseIf $MaxLen = 9 Then
        $Numbrs = StringSplit("0,1,2,3,4,5,6,7,8,9", ",")
    Else
        Return SetError(1, 0, "!  Error MaxLen !")
    EndIf
    For $i = 1 To $Numbrs[0]
        _WriteLog($Str & $Numbrs[$i])
    Next
    _WriteLog("Processing....DONE")
EndFunc   ;==>Combi

Func _WriteLog($iMsg = "", $iBreak = 1)
    GUICtrlSetData($Label_Staus, $iMsg)
    Local $rDara = GUICtrlRead($Edit1)
    If $iBreak Then
        ConsoleWrite($iMsg & @CRLF)
        GUICtrlSetData($Edit1, $rDara & @CRLF & $iMsg)
    Else
        ConsoleWrite($iMsg)
        GUICtrlSetData($Edit1, $rDara & $iMsg)
    EndIf
EndFunc   ;==>_WriteLog

 

Regards,
 

Posted

@VIP,

Thanks, but the code is to get the 3 combination of 0 to 5 and 0 to 9, which would be as below sample. For now, I'm trying to get 0-5 but it would be great if you will include 0-9 as well.:sweating:

0 to 5 combination results:

Combination = 000
Combination = 001
Combination = 002
Combination = 003
Combination = 004
Combination = 005
Combination = 010
Combination = 011
Combination = 012
Combination = 013
Combination = 014
Combination = 015
... and so on.. ; up to end of the combinations

Here's the peace of the script that do the combination (google searched), however, when applying it to my GUI, it won't run anymore.

Run("notepad.exe") ; this was changed to fileopen and save the combinations in a log.
WinWaitActive("")

Sleep(500)
$Letter = StringSplit("0,1,2,3,4,5", ",")
Combi("", 3) ; here is the combination of 3
Func Combi($Str, $MaxLen)
Dim $i
    if StringLen($Str) = $MaxLen Then
        Send("Combination = " & $Str & @CRLF) ; this will be shown in $Edit1 in my first post
;       Sleep(50)
        Return
    EndIf
    For $i = 1 to $Letter[0]
        Combi($Str & $Letter[$i], $MaxLen)
    Next
EndFunc

 

Programming is "To make it so simple that there are obviously no deficiencies" or "To make it so complicated that there are no obvious deficiencies" by C.A.R. Hoare.

Posted

Hi Experts,

I think I got it working:D, please can you check if this is okay. Thanks!

Here's the complete running code:

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <ProgressConstants.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <File.au3>

#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 615, 438, 192, 124)
$Run = GUICtrlCreateButton("Run", 24, 127, 129, 33)
GUICtrlSetOnEvent(-1, "RunClick")
$Group1 = GUICtrlCreateGroup("Selection Range", 24, 15, 265, 97)
$TrckNum = GUICtrlCreateRadio("0-5", 48, 38, 65, 25)
$TrckNum2 = GUICtrlCreateRadio("0-9", 48, 62, 65, 25)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Edit1 = GUICtrlCreateEdit("", 296, 20, 304, 363)
GUICtrlSetData(-1, "")
$Progress = GUICtrlCreateProgress(296, 391, 305, 17)
$View = GUICtrlCreateButton("View Log", 24, 343, 129, 33)
$close = GUICtrlCreateButton("Close", 24, 383, 129, 33)
$Label1 = GUICtrlCreateLabel("Processing:", 296, 416, 307, 17)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
Global $Str, $MaxLen
While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $View
         If GUICtrlRead($TrckNum) = 1 Then
            $Count = "0-5"
         ElseIf GUICtrlRead($TrckNum2) = 1 Then
            $Count = "0-9"
         EndIf
         $path = @ScriptDir & "\TrackingNum" & $Count & ".txt"
         ShellExecute($path)
        Case $Run
         If GUICtrlRead($TrckNum) = 1 Then
           MsgBox(0,"","Tracking Number 0 to 5 selected") ;working
           Local $file3 = FileOpen(@scriptdir & "\TrackingNum0-5.txt", 2)
            Sleep(500)
            $Numbrs  = StringSplit("0,1,2,3,4,5", ",")
            Combi("", 3)
            Combi($Str, $MaxLen)
         ElseIf GUICtrlRead($TrckNum2) = 1 Then
           MsgBox(0,"","Tracking Number 0 to 9 selected") ;working
           Local $file3 = FileOpen(@scriptdir & "\TrackingNum0-9.txt", 2)
            Sleep(500)
            $Numbrs  = StringSplit("0,1,2,3,4,5,6,7,8,9", ",")
            Combi("", 3)
            Combi($Str, $MaxLen)
         EndIf
    EndSwitch
WEnd

Func Combi($Str, $MaxLen)
    Dim $i
    if StringLen($Str) = $MaxLen Then
      GUICtrlSetData($Edit1, "Tracking Number = " & $Str & @CRLF, "1")
      FileWrite($file3, "Tracking Number = " & $Str & @CRLF)
      Return
    EndIf
      For $i = 1 to $Numbrs[0]
         Combi($Str & $Numbrs[$i], $MaxLen)
      Next
EndFunc

 

Programming is "To make it so simple that there are obviously no deficiencies" or "To make it so complicated that there are no obvious deficiencies" by C.A.R. Hoare.

Posted

@KickStarter15 Not sure why you were calling Combi($Str, $MaxLen) within the Gui, also unsure why you added the $Str and $MaxLen in the Global scope when they're already defined in the Local scope of the Combi function a.k.a the parameters.  You shouldn't also use GUICtrlSetOnEvent when using GuiGetMsg, it should be one or the other but never both, anyway this is the updated code:

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <ProgressConstants.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <File.au3>

#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 615, 438, 192, 124)
$Run = GUICtrlCreateButton("Run", 24, 127, 129, 33)
;~ GUICtrlSetOnEvent(-1, "RunClick")
$Group1 = GUICtrlCreateGroup("Selection Range", 24, 15, 265, 97)
$TrckNum = GUICtrlCreateRadio("0-5", 48, 38, 65, 25)
$TrckNum2 = GUICtrlCreateRadio("0-9", 48, 62, 65, 25)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Edit1 = GUICtrlCreateEdit("", 296, 20, 304, 363)
GUICtrlSetData(-1, "")
$Progress = GUICtrlCreateProgress(296, 391, 305, 17)
$View = GUICtrlCreateButton("View Log", 24, 343, 129, 33)
$close = GUICtrlCreateButton("Close", 24, 383, 129, 33)
$Label1 = GUICtrlCreateLabel("Processing:", 296, 416, 307, 17)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $View
         If GUICtrlRead($TrckNum) = 1 Then
            $Count = "0-5"
         ElseIf GUICtrlRead($TrckNum2) = 1 Then
            $Count = "0-9"
         EndIf
         $path = @ScriptDir & "\TrackingNum" & $Count & ".txt"
         ShellExecute($path)
        Case $Run
         If GUICtrlRead($TrckNum) = 1 Then
           MsgBox(0,"","Tracking Number 0 to 5 selected") ;working
           Local $file3 = FileOpen(@scriptdir & "\TrackingNum0-5.txt", 2)
            Sleep(500)
            $Numbrs  = StringSplit("0,1,2,3,4,5", ",")
            Combi("", 3)
         ElseIf GUICtrlRead($TrckNum2) = 1 Then
           MsgBox(0,"","Tracking Number 0 to 9 selected") ;working
           Local $file3 = FileOpen(@scriptdir & "\TrackingNum0-9.txt", 2)
            Sleep(500)
            $Numbrs  = StringSplit("0,1,2,3,4,5,6,7,8,9", ",")
            Combi("", 3)
         EndIf
    EndSwitch
WEnd

Func Combi($Str, $MaxLen)
    Dim $i
    if StringLen($Str) = $MaxLen Then
      GUICtrlSetData($Edit1, "Tracking Number = " & $Str & @CRLF, "1")
      FileWrite($file3, "Tracking Number = " & $Str & @CRLF)
      Return
    EndIf
      For $i = 1 to $Numbrs[0]
         Combi($Str & $Numbrs[$i], $MaxLen)
      Next
EndFunc

Here is an alternative way of doing it as well

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GuiEdit.au3>
#include <GUIConstantsEx.au3>
#include <ProgressConstants.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <File.au3>

Global $idTrack1, $idTrack2

Local $iTrackSelection, $sTrackSelection, $sTrackFilePath
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 615, 438, 192, 124)
$Run = GUICtrlCreateButton("Run", 24, 127, 129, 33)
$Group1 = GUICtrlCreateGroup("Selection Range", 24, 15, 265, 97)
$idTrack1 = GUICtrlCreateRadio("0-5", 48, 38, 65, 25)
$idTrack2 = GUICtrlCreateRadio("0-9", 48, 62, 65, 25)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$idEdit = GUICtrlCreateEdit("", 296, 20, 304, 363)
_GUICtrlEdit_SetLimitText($idEdit, 64000)
GUICtrlSetData(-1, "")
$Progress = GUICtrlCreateProgress(296, 391, 305, 17)
$View = GUICtrlCreateButton("View Log", 24, 343, 129, 33)
$close = GUICtrlCreateButton("Close", 24, 383, 129, 33)
$Label1 = GUICtrlCreateLabel("Processing:", 296, 416, 307, 17)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
Global $Str, $MaxLen
While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $View
            $sTrackSelection = _TrackSelection(True)
            If $sTrackSelection Then
                $sTrackFilePath = @ScriptDir & "\TrackingNum" & $sTrackSelection & ".txt"
                ShellExecute($sTrackFilePath)
            EndIf
        Case $Run
            $iTrackSelection = _TrackSelection()
            If $iTrackSelection = False Then ContinueLoop
            MsgBox(0,"","Tracking Number " & _TrackSelection(True) & " selected")
            Local $hFileopen = FileOpen(@scriptdir & "\TrackingNum" & _TrackSelection(True) & ".txt", 2)
            For $i = 0 To $iTrackSelection & $iTrackSelection & $iTrackSelection Step 10
                For $j = 0 To $iTrackSelection
                    _GUICtrlEdit_AppendText($idEdit, "Tracking Number = " & StringFormat("%03i", $i + $j) & @CRLF)
                    FileWrite($hFileopen, "Tracking Number = " & StringFormat("%03i", $i + $j) & @CRLF)
                Next
            Next
    EndSwitch
WEnd

Func _TrackSelection($bTrackValue = False)
    Local $vResult
    If BitAND(GUICtrlRead($idTrack1), $GUI_CHECKED) = $GUI_CHECKED Then
        $vResult = $bTrackValue ? GUICtrlRead($idTrack1, 1) : 5
    ElseIf BitAND(GUICtrlRead($idTrack2), $GUI_CHECKED) = $GUI_CHECKED Then
        $vResult = $bTrackValue ? GUICtrlRead($idTrack2, 1) : 9
    Else
        $vResult = False
    EndIf
    Return $vResult
EndFunc

 

Posted

Example for  _LeadingZero()

#include <GUIConstantsEx.au3>
#include <GuiEdit.au3>

#Region ### START GUI section ###
Global $hGUI = GUICreate("/ Number Combi /", 420, 374, -1, -1)
Global $bRun = GUICtrlCreateButton("RUN", 8, 191, 161, 73)
Global $cLogs = GUICtrlCreateEdit("", 176, 12, 232, 299)
_GUICtrlEdit_SetLimitText($cLogs, 64000)
Global $ProgressBar = GUICtrlCreateProgress(184, 319, 225, 17)
Global $bClearLog = GUICtrlCreateButton("Clear Log", 8, 279, 161, 33)
Global $bSaveLog = GUICtrlCreateButton("Save Logs to File", 8, 327, 161, 33)
Global $Label_Staus = GUICtrlCreateLabel("--- READY ---", 184, 344, 227, 17)
GUICtrlCreateLabel("Insert :", 8, 112, 36, 17)
Global $iStringInsert = GUICtrlCreateInput(" Tracking Number = ", 8, 136, 153, 21)
GUICtrlCreateLabel("Len :", 16, 80, 29, 17)
Global $iNumLen = GUICtrlCreateInput("3", 64, 80, 97, 21)
GUICtrlCreateLabel("From:", 16, 16, 30, 17)
Global $iNumFrom = GUICtrlCreateInput("0", 64, 16, 97, 21)
GUICtrlCreateLabel("To:", 16, 48, 23, 17)
Global $iNumTo = GUICtrlCreateInput("999", 64, 48, 97, 21)
Global $rStringInsertBefore = GUICtrlCreateRadio("Before", 56, 112, 49, 17)
GUICtrlSetState(-1, $GUI_CHECKED)
Global $rStringInsertAfter = GUICtrlCreateRadio("After", 120, 112, 41, 17)
Global $cbShowLiveLogs = GUICtrlCreateCheckbox("SHOW LIVE PROCESS", 16, 168, 137, 17)
GUICtrlSetState(-1, $GUI_CHECKED)
GUISetState(@SW_SHOW)
#EndRegion ### START GUI section ###

Global $nMsg, $_StringInsert = "", $_NumLen = 0, $_NumFrom = 0, $_NumTo = 0, $_StringInsertTo = "", $_ShowLiveLogs = 0
Global $OverWriteLog = True, $iLogsFileName = @ScriptDir & "\" & @ScriptName & "_logs.txt"

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit

        Case $bRun
            RunClick()

        Case $bSaveLog
            Local $hOpen, $cLogsData = GUICtrlRead($cLogs)
            If $OverWriteLog Then
                $hOpen = FileOpen($iLogsFileName, $FO_OVERWRITE + $FO_CREATEPATH + $FO_UTF8)
            Else
                $hOpen = FileOpen($iLogsFileName, $FO_APPEND + $FO_CREATEPATH + $FO_UTF8)
            EndIf
            FileWrite($hOpen, $cLogsData)
            FileClose($hOpen)
            _Log("! Logs Writed to:" & @CRLF & $iLogsFileName & @CRLF)

        Case $bClearLog
            GUICtrlSetData($cLogs, "")

    EndSwitch
WEnd

Func RunClick()
    _Log(@CRLF & "! Run Clicked " & @YEAR & "/" & @MON & "/" & @MDAY & " " & @HOUR & ":" & @MIN & ":" & @SEC)
    $_StringInsert = GUICtrlRead($iStringInsert)
    $_NumLen = GUICtrlRead($iNumLen)
    $_NumFrom = GUICtrlRead($iNumFrom)
    $_NumTo = GUICtrlRead($iNumTo)
    If (GUICtrlRead($rStringInsertBefore) = $GUI_CHECKED) Then
        $_StringInsertTo = "Before"
    ElseIf (GUICtrlRead($rStringInsertAfter) = $GUI_CHECKED) Then
        $_StringInsertTo = "After"
    EndIf
    $_ShowLiveLogs = (GUICtrlRead($cbShowLiveLogs) = $GUI_CHECKED)
    _Log("-NumFrom       : " & $_NumFrom & "")
    _Log("-NumTo         : " & $_NumTo & "")
    _Log("-NumLen        : " & $_NumLen & "")
    _Log("-StringInsert  : " & $_StringInsert & "")
    _Log("-StringInsertTo: " & $_StringInsertTo & "")
    _Log("-ShowLiveLogs  : " & $_ShowLiveLogs & "")
    Combi($_NumFrom, $_NumTo, $_NumLen, $_StringInsert, $_StringInsertTo)
EndFunc   ;==>RunClick

Func Combi($iNumStart, $iNumEnd, $iNumLen, $iString, $iStrInsertBA = "Before")
    _Log("+ Processing....", 2)
    GUICtrlSetData($ProgressBar, 0)
    Local $iLogx = "", $tmpLog, $iStep = 1
    If $iNumStart > $iNumEnd Then $iStep = -1
    Local $xTol = Int($iNumEnd - $iNumStart), $cPos = 0, $iPerCen = 0
    If (($iStrInsertBA = Default) Or ($iStrInsertBA = -1) Or (StringLower($iStrInsertBA) = "before")) Then $iStrInsertBA = "Before"
    For $i = $iNumStart To $iNumEnd Step $iStep
        $cPos = ($i + 1 - $iNumStart)
        $iPerCen = Int(($cPos / $xTol) * 100)
        If ($iStrInsertBA = "Before") Then
            $tmpLog = $iString & _LeadingZero($i, $iNumLen)
        Else
            $tmpLog = _LeadingZero($i, $iNumLen) & $iString
        EndIf
        If $_ShowLiveLogs Then _Log($tmpLog)
        GUICtrlSetData($ProgressBar, $iPerCen)
        $iLogx &= $tmpLog & @CRLF
    Next
    If Not $_ShowLiveLogs Then _Log($iLogx)
    _Log("+ Processing....DONE", 2)
    GUICtrlSetData($ProgressBar, 100)
EndFunc   ;==>Combi

Func _LeadingZero($iNum, $iLen = 0)
    Return StringFormat('%0' & $iLen & 's', $iNum)
EndFunc   ;==>_LeadingZero

;--- : Code By Dao Van Trong - TRONG.LIVE

Func _Log($iMsg = "", $sAll = 3, $iBreak = 1)
    If $sAll >= 2 Then GUICtrlSetData($Label_Staus, $iMsg)
    If $iBreak Then
        If $sAll >= 1 Then ConsoleWrite($iMsg & @CRLF)
        If $sAll >= 3 Then _GUICtrlEdit_AppendText($cLogs, @CRLF & $iMsg)
    Else
        If $sAll >= 1 Then ConsoleWrite($iMsg)
        If $sAll >= 3 Then _GUICtrlEdit_AppendText($cLogs, $iMsg)
    EndIf
EndFunc   ;==>_Log

image.png.42bb31b8ad070002eb9a10f16b75812e.png

Regards,
 

Posted (edited)

Thanks, Experts.

 

@Subz, I followed your suggestion and its fine and okay. Easy to read. Well there still cases that I still need to learn:sweating: . Thanks!

@VIP, Thanks men, I tried your way and its good and very nice especially when doing the input "From", "To", "Len" and the "before and after". However, If you can make it like the below input that I only need to input the required number for combination and not the actual total count of combinations then that would be great. :) Also, leading zero is not advisable to add it in the script it should be pure combination of 3digit only from 0 to 5 and 0 to 9.

image.png.495e9c79bdd4d2e27a8b5fc5c7905b47.png

image.png.e75a25269f2a656b0947954ed6fa7f68.png

 

Thanks!

KS15

 

 

Edited by KickStarter15

Programming is "To make it so simple that there are obviously no deficiencies" or "To make it so complicated that there are no obvious deficiencies" by C.A.R. Hoare.

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...