Buttons: Rename and Action Topic is solved

Get help with using AutoHotkey and its commands and hotkeys
asad41163
Posts: 268
Joined: 29 Jul 2014, 14:31

Buttons: Rename and Action

13 May 2018, 12:59

Hi, everyone
the following code for A folder comparison, the code works very well, it's from here:
https://autohotkey.com/boards/viewtopic ... 66#p215966

Code: Select all

Gui Add, ListBox, w650 r10 vfiles1, % "Dir1 = " dir1 "| |" list1
Gui Add, ListBox, xm w650 r10 vfiles2, % "Dir2 = " dir2 "| |" list2
Gui Add, Button, w75 gGuiOK default, Exit
Gui,Add, Text, yp+5 x100,Dir1
Gui,Add, Edit, yp-3 x130 w200 vDir1,%dir1%
Gui,Add, Text, yp+2 x340,Dir2
Gui,Add, Edit, yp-3 x365 w200 vDir2,%dir2%
Gui,Add, Text, yp+2 x575,Mask
Gui,Add, Edit, yp-3 x605 w75 vFileMask,%fileMask%
Gui Add, Button, yp x685 w75 gGo, Go
Gosub, AddRightSideButtons
Gui Show, w775
Return

AddRightSideButtons:
    GuiControlGet, ctl, Pos, files1

    x := ctlX + ctlW + 10
    Gui, Add, Button, x%x% y%ctlY% w90 h28, Button 1
    Loop, 7
        Gui, Add, Button, wp hp, % "Button " A_Index+1
return

Go:
    Gui, Submit, NoHide 
    gosub, DoTheWork
    GuiControl,,files1,% "|Dir1 = " dir1 "| |" list1
    GuiControl,,files2,% "|Dir2 = " dir2 "| |" list2
return

GuiOK:
GuiClose:
GuiEscape:
ExitApp
DoTheWork:
filelist1 := filelist2 := ""
list1 := list2 := ""
fnb1 := fnb2 := 0 ; <<<<< added: initialize the counters
Loop %dir1%\%fileMask%
{
If ( A_LoopFileName ~= "~\$")
        continue
    fileList1 .= A_LoopFileName . "`n"
    fnb1++ ; <<<<< changed: don't use A_Index because some files may be skipped
}
StringTrimRight fileList1, fileList1, 1
Loop %dir2%\%fileMask%
{
    If ( A_LoopFileName ~= "~\$")
        continue
    fileList2 .= A_LoopFileName . "`n"
    fnb2++ ; <<<<< changed: don't use A_Index because some files may be skipped
}
StringTrimRight fileList2, fileList2, 1

If (fnb1 = 0) && (fnb2 = 0) ; <<<<< added: early return
    Return

Sort fileList1
Sort fileList2
StringSplit files_1_, fileList1, `n
StringSplit files_2_, fileList2, `n
idxF1 := idxF2 := 1

Loop
{
    If (idxF1 > fnb1) ; <<<<< moved to the top of the loop
    {
        Loop % fnb2 - idxF2 + 1
        {
            list1 .= " |"   ; Empty
            list2 .= files_2_%idxF2% . "|"
            idxF2++
        }
        Break
    }
    If (idxF2 > fnb2) ; <<<<< moved to the top of the loop
    {
        Loop % fnb1 - idxF1 + 1
        {
            list1 .= files_1_%idxF1% . "|"
            idxF1++
            list2 .= " |"   ; Empty
        }
        Break
    }
    If (files_1_%idxF1% = files_2_%idxF2%)
    {
        ; We are in synch
        list1 .= files_1_%idxF1% . "|"
        idxF1++
        list2 .= files_2_%idxF2% . "|"
        idxF2++
    }
    Else
    {
        ; Either file at idxF1 or at idxF3 is missing, we must find which one
        If (files_1_%idxF1% > files_2_%idxF2%)
        {
            ; Missing in first list
            list1 .= " |"   ; Empty
            list2 .= files_2_%idxF2% . "|"
            idxF2++
        }
        Else
        {
            ; Missing in second list
            list1 .= files_1_%idxF1% . "|"
            idxF1++
            list2 .= " |"   ; Empty
        }
    }
}

StringTrimRight list1, list1, 1
StringTrimRight list2, list2, 1
Return
the question:
I want to change the name of button 1 to "Sales" and when pressed it performs the following action:

Code: Select all

ControlSetText, Edit1, E:\ask\work
ControlSetText, Edit2, E:\ask\backup
I want to change the name of button 2 to "Cashing" and when pressed it performs the following action:

Code: Select all

ControlSetText, Edit1, E:\ask\sales
ControlSetText, Edit2, E:\ask\work
I want to change the name of button 7 to "DocFiles" and when pressed it performs the following action:

Code: Select all

ControlSetText, Edit3, *.docx
ControlClick, Go, Comp 
I want to change the name of button 8 to "PdfFiles" and when pressed it performs the following action:

Code: Select all

ControlSetText, Edit3, *.pdf
ControlClick, Go, Comp 
Thanks in advance
asad41163
Posts: 268
Joined: 29 Jul 2014, 14:31

Re: Buttons: Rename and Action

14 May 2018, 03:52

Any help would be greatly appreciated
Rangerbot
Posts: 34
Joined: 02 Mar 2018, 10:33

Re: Buttons: Rename and Action

14 May 2018, 04:01

[/quote]Gui, Add, ControlType [, Options, Text]
Adds a control to a GUI window (first creating the GUI window itself, if necessary).

ControlType is one of the following:

Text, Edit, UpDown, Picture
Button, Checkbox, Radio
DropDownList, ComboBox
ListBox, ListView, TreeView
Link, Hotkey, DateTime, MonthCal
Slider, Progress
GroupBox, Tab, StatusBar
ActiveX (e.g. Internet Explorer Control)
Custom
For example:

Gui, Add, Text,, Please enter your name:
Gui, Add, Edit, vName
Gui, Show[/quote]
asad41163
Posts: 268
Joined: 29 Jul 2014, 14:31

Re: Buttons: Rename and Action

14 May 2018, 04:13

Hi, Rangerbot
Gui actually has the buttons, As the picture
buttons.png
buttons.png (6.81 KiB) Viewed 1143 times
Help me in two buttons, I will complete the rest buttons
please help
asad41163
Posts: 268
Joined: 29 Jul 2014, 14:31

Re: Buttons: Rename and Action

14 May 2018, 06:20

Please Help
buttons action.png
buttons action.png (41.33 KiB) Viewed 1131 times
asad41163
Posts: 268
Joined: 29 Jul 2014, 14:31

Re: Buttons: Rename and Action  Topic is solved

14 May 2018, 10:23

Hi, everyone
this Answer for "jmeneses", thank you very much "jmeneses".
https://autohotkey.com/boards/viewtopic ... 26#p218026

Code: Select all

#NoEnv 
#SingleInstance force 
#Persistent   

nameBUT := StrSplit("SALES|Cashing|Button3|Button4|Button5|Button6|DocFiles|PdfFiles", "|")   

Gui Add, ListBox, w650 r10 vfiles1, % "Dir1 = " dir1 "| |" list1
Gui Add, ListBox, xm w650 r10 vfiles2, % "Dir2 = " dir2 "| |" list2
Gui Add, Button, w75 gGuiOK default, Exit
Gui,Add, Text, yp+5 x100,Dir1
Gui,Add, Edit, yp-3 x130 w200 vDir1,%dir1%
Gui,Add, Text, yp+2 x340,Dir2
Gui,Add, Edit, yp-3 x365 w200 vDir2,%dir2%
Gui,Add, Text, yp+2 x575,Mask
Gui,Add, Edit, yp-3 x605 w75 vFileMask,%fileMask%
Gui Add, Button, yp x685 w75 gGo, Go
Gosub, AddRightSideButtons
Gui Show, w775
Return

AddRightSideButtons:
    GuiControlGet, ctl, Pos, files1

    x := ctlX + ctlW + 10
    Gui, Add, Button, x%x% y%ctlY% w90 h28 gBUT, % nameBUT[1]  
    Loop, 7
        Gui, Add, Button, wp hp gBUT, % nameBUT[A_index+1]  
return

Go:	
    Gui, Submit, NoHide 
    gosub, DoTheWork
    GuiControl,,files1,% "|Dir1 = " dir1 "| |" list1
    GuiControl,,files2,% "|Dir2 = " dir2 "| |" list2
return

BUT:
If (A_GuiControl=nameBUT[1]){
    ControlSetText, Edit1, % "E:\ask\work"
    ControlSetText, Edit2, % "E:\ask\backup"
    }
Else
  If (A_GuiControl=nameBUT[2]){
  	  ControlSetText, Edit1,% "E:\ask\sales"
      ControlSetText, Edit2, % "E:\ask\work"
  }
Else
  If (A_GuiControl=nameBUT[7]){
  	  ControlSetText, Edit3, *.docx
      ControlClick, Go, Comp 
  }
Else
  If (A_GuiControl=nameBUT[8]){
  	  ControlSetText, Edit3, *.pdf
      ControlClick, Go, Go 
  }  
Else
	Msgbox % "NONE!!" A_GuiControl

return

GuiOK:
GuiClose:
GuiEscape:
ExitApp
DoTheWork:
filelist1 := filelist2 := ""
list1 := list2 := ""
fnb1 := fnb2 := 0 ; <<<<< added: initialize the counters
Loop %dir1%\%fileMask%
{
If ( A_LoopFileName ~= "~\$")
        continue
    fileList1 .= A_LoopFileName . "`n"
    fnb1++ ; <<<<< changed: don't use A_Index because some files may be skipped
}
StringTrimRight fileList1, fileList1, 1
Loop %dir2%\%fileMask%
{
    If ( A_LoopFileName ~= "~\$")
        continue
    fileList2 .= A_LoopFileName . "`n"
    fnb2++ ; <<<<< changed: don't use A_Index because some files may be skipped
}
StringTrimRight fileList2, fileList2, 1

If (fnb1 = 0) && (fnb2 = 0) ; <<<<< added: early return
    Return

Sort fileList1
Sort fileList2
StringSplit files_1_, fileList1, `n
StringSplit files_2_, fileList2, `n
idxF1 := idxF2 := 1

Loop
{
    If (idxF1 > fnb1) ; <<<<< moved to the top of the loop
    {
        Loop % fnb2 - idxF2 + 1
        {
            list1 .= " |"   ; Empty
            list2 .= files_2_%idxF2% . "|"
            idxF2++
        }
        Break
    }
    If (idxF2 > fnb2) ; <<<<< moved to the top of the loop
    {
        Loop % fnb1 - idxF1 + 1
        {
            list1 .= files_1_%idxF1% . "|"
            idxF1++
            list2 .= " |"   ; Empty
        }
        Break
    }
    If (files_1_%idxF1% = files_2_%idxF2%)
    {
        ; We are in synch
        list1 .= files_1_%idxF1% . "|"
        idxF1++
        list2 .= files_2_%idxF2% . "|"
        idxF2++
    }
    Else
    {
        ; Either file at idxF1 or at idxF3 is missing, we must find which one
        If (files_1_%idxF1% > files_2_%idxF2%)
        {
            ; Missing in first list
            list1 .= " |"   ; Empty
            list2 .= files_2_%idxF2% . "|"
            idxF2++
        }
        Else
        {
            ; Missing in second list
            list1 .= files_1_%idxF1% . "|"
            idxF1++
            list2 .= " |"   ; Empty
        }
    }
}

StringTrimRight list1, list1, 1
StringTrimRight list2, list2, 1
Return

Return to “Ask For Help”

Who is online

Users browsing this forum: DanRim, Google [Bot] and 62 guests