 |
AutoHotkey Community Let's help each other out
|
| View previous topic :: View next topic |
| Author |
Message |
Invalid User
Joined: 14 Feb 2005 Posts: 442 Location: Texas, Usa
|
Posted: Mon Apr 18, 2005 10:37 pm Post subject: Using Lists and Common Functions |
|
|
The Document that was here has been removed for some super revision, in the mean time the following script can be used as an example for those who want to proform the following actions to a list, or set of lists:
Move the Cursel Up
Move the Cursel Down
Add Files to a list
Add a User Entry to a list
Add Files via Drag and Drop
Import Contents of a file to a list
Remove A Item from a list
Remove a Select Items' Duplicates from a list
Remove All Duplicated Items from a list
Move Selected Item Up in list
Move Selected Item Down in list
Move Selected Item from one to the other
Replace an Item with User defined entry
Copy Selected Item to other list
Sort a lists contents by Case (Add a single N character to this function for Numeric Sorting)
Swap Items from list to list
Switch two items within a list
Each function has been well tested but bugs may still be present. Please report them as they are found. Note: Know issue with Importing files, Entering "n" as a delimiter is seen as "`n" This will soon be fixed
Functions that are planned to be developed:
Mass Copy (Simular to above)
Mass Swap (Simular to above)
Mass Switch
Mass Move selected Items
...and more as they are thought of....
This script is not well comented but should suffice until I write I document to explain it all.
| Code: | AllowedExtList = ahk,wav,mp3,txt
ExcludedExtList = tmp,exe
AppWinTitle = List Function Demo
TargetList = 1
TargetListOSD = %TargetList%
BlankVar =
;$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
Menu, FileMenu, Add, Exit, Exit
Menu, LLFunctionsMenu, Add, Move Cursel Down, MoveCurselDown
Menu, LLFunctionsMenu, Add, Move Cursel UP, MoveCurselUp
Menu, LLFunctionsMenu, Add, Add File, AddFile
Menu, LLFunctionsMenu, Add, Remove Item, RemoveItem
Menu, LLFunctionsMenu, Add, Move Item Down, MoveItemDown
Menu, LLFunctionsMenu, Add, Move Item Up, MoveItemUp
Menu, HLFunctionsMenu, Add, Replace Item, ReplaceItem
Menu, HLFunctionsMenu, Add, Remove Select Duplicates, RemoveDuplicates
Menu, HLFunctionsMenu, Add, Switch Items, SwitchItems
Menu, HLFunctionsMenu, Add, Move Item to Other List, MoveItemToOtherList
Menu, LLFunctionsMenu, Add, Add User Entry, AddUserEntry
Menu, HLFunctionsMenu, Add, Import List From File, ImportListFromFile
Menu, LLFunctionsMenu, Add, Sort Items, SortItems
;Menu, LLFunctionsMenu, Add, Remove All Duplicates, RemoveAddDuplicates
;Menu, HLFunctionsMenu, Add, Swap Items, SwapItems
;Menu, HLFunctionsMenu, Add, Copy Item, CopyItem
;Menu, FunctionsMenu, Add, Function5, Function5
;Menu, FunctionsMenu, Add, Function6, Function6
;Menu, FunctionsMenu, Add, Function7, Function7
;Menu, FunctionsMenu, Add, Function8, Function8
;Menu, FunctionsMenu, Add, Function9, Function9
;Menu, FunctionsMenu, Add, Function10, Function10
;Menu, FunctionsMenu, Add, Function11, Function11
;Menu, FunctionsMenu, Add, Function12, Function12
Menu, OptionsMenu, Add, Filter Settings, FilterSettings
Menu, MyMenuBar, Add, File, :FileMenu ; Attach the three sub-menus that were created above.
Menu, MyMenuBar, Add, Low Level Functions, :LLFunctionsMenu
Menu, MyMenuBar, Add, High Level Fucntions, :HLFunctionsMenu
Menu, MyMenuBar, Add, Options, :OptionsMenu ;Add Options to menu
Gui, Menu, MyMenuBar
Gui, Add, Button, gMoveCurselDown x6 y10 w100 h30, Move Cursel Down
Gui, Add, Button, gMoveCurselUp x6 y40 w100 h30, Move Cursel Up
Gui, Add, Button, gAddFile x6 y70 w100 h30, Add File
Gui, Add, Button, gRemoveItem x6 y100 w100 h30, Remove Item
Gui, Add, Button, gMoveItemUp x6 y130 w100 h30, Move Item Up
Gui, Add, Button, gMoveItemDown x6 y160 w100 h30, Move Item Down
Gui, Add, Button, gReplaceItem x6 y190 w100 h30, Replace Item
Gui, Add, Button, gRemoveDuplicates x6 y220 w100 h30, Remove Select Duplicates
Gui, Add, Button, gSwitchItems x6 y250 w100 h30, Switch Items
Gui, Add, Button, gMoveItemToOtherList x6 y280 w100 h30, Move Item To Other List
Gui, Add, Button, gAddUserEntry x6 y310 w100 h30, Add User Entry
Gui, Add, Button, gImportListFromFile x6 y340 w100 h30, Import List From File
Gui, Add, Button, gCopyItem x106 y10 w100 h30, Copy Item
Gui, Add, Button, gSwapItems x106 y40 w100 h30, Swap Items
Gui, Add, Button, gSortItems x106 y70 w100 h30, Sort Items
Gui, Add, Button, gRemoveAllDuplicates x106 y100 w100 h30, Remove All Duplicates
;Gui, Add, Button, x106 y130 w100 h30, New Function5
;Gui, Add, Button, x106 y160 w100 h30, New Function6
;Gui, Add, Button, x106 y190 w100 h30, New Function7
;Gui, Add, Button, x106 y220 w100 h30, New Function8
;Gui, Add, Button, x106 y250 w100 h30, New Function9
;Gui, Add, Button, x106 y280 w100 h30, New Function10
;Gui, Add, Button, x106 y310 w100 h30, New Function11
;Gui, Add, Button, x106 y340 w100 h30, New Function12
Gui, Add, Text, gTargetList1 x236 y10 w350 h20, List 1 (Select this text to activate this list if there is no entries)
Gui, Add, ListBox, gTargetList1 vListBox1 AltSubmit HScroll x236 y30 w350 h160,
Gui, Add, Text, gTargetList2 x236 y190 w350 h20, List 2 (Select this text to activate this list if there is no entries)
Gui, Add, ListBox, gTargetList2 vListBox2 AltSubmit HScroll x236 y210 w350 h160,
Gui, Font, s18
Gui, Add, Text, vTargetListOSD Center x206 y10 w30 h30, %TargetListOSD%
;#################Second GUI######################
Gui, 2:Add, Text, x116 y30 w250 h20, Allow these types of files (use comma delimited list)
Gui, 2:Add, Edit, vAllowedExtList x116 y60 w250 h20, %AllowedExtList%
Gui, 2:Add, Text, x116 y90 w260 h20, Exclude these types of files (use comma delimited list)
Gui, 2:Add, Edit, vExcludedExtList x116 y120 w250 h20, %ExcludedExtList%
;Gui, 2:Add, Radio, x16 y40 w80 h30, Allow these extentions
;Gui, 2:Add, Radio, x16 y90 w90 h50, Exclude these extentions
Gui, 2:Add, GroupBox, x6 y10 w380 h140, Filter Options
Gui, 2:Add, Button, gApplyOptions x396 y20 w70 h30, Apply
;#####################Third GUI#########################
Gui, 3:Add, Text,, What Character would you like your delimiter to be?
Gui, 3:Add, Edit, vUserDelimiter,
Gui, 3:Add, Text,, What Character/s would you like to omit from the retrieved contense between delimited characters?
Gui, 3:Add, Edit, vUserOmit
Gui, 3:Add, Button, gContImport, Import File
Gui, Show, x0 y0 h377 w594, %AppWinTitle%
Return
;############################################################
TargetList1:
TargetList = 1
OtherList = 2
GuiControl,1:,TargetListOSD, 1
Return
;------------------------------------------------------------
TargetList2:
TargetList = 2
OtherList = 1
GuiControl,1:,TargetListOSD, 2
Return
;############################################################
FilterSettings:
Gui, 2:Show, x147 y109 h159 w477, Options
Return
;------------------------------------------------------------
ApplyOptions:
Gui, 2:Submit
Return
;------------------------------------------------------------
SwapItems:
Gui, Submit, NoHide
TargetItemPos1 := ListBox%TargetList%
TargetItemPos2 := ListBox%OtherList%
GoSub, SplitUpString
TargetItemCont1 := ArrayOfAllEntries%TargetItemPos1%
GoSub, TargetList%OtherList%
GoSub, SplitUpString
TargetItemCont2 := ArrayOfAllEntries%TargetItemPos2%
ArrayOfAllEntries%TargetItemPos2% = %TargetItemCont1%
GoSub, FillListFromArray
GoSub, TargetList%OtherList%
GoSub, SplitUpString
ArrayOfAllEntries%TargetItemPos1% = %TargetItemCont2%
GoSub, FillListFromArray
Return
;------------------------------------------------------------
SortItems:
SortedList := ListBoxCont%TargetList%
Sort, SortedList, D| C
ListBoxCont%TargetList% = %SortedList%
GoSub, SplitUpString
GoSub, FillListFromArray
Return
;------------------------------------------------------------
MoveCurselDown:
Gui,Submit,NoHide
ChoicePos:= ListBox%TargetList%
ChoicePos++
If (ChoicePos> 0)
Control, Choose, %ChoicePos%, ListBox%TargetList%
Return
;------------------------------------------------------------
MoveCurselUp:
Gui,Submit,NoHide
ChoicePos:= ListBox%TargetList%
ChoicePos--
If (ChoicePos> 0)
Control, Choose, %ChoicePos%, ListBox%TargetList%
Return
;------------------------------------------------------------
RemoveAllDuplicates:
SortedList := ListBoxCont%TargetList%
Sort, SortedList, D| U C
ListBoxCont%TargetList% = %SortedList%
GoSub, SplitUpString
GoSub, FillListFromArray
;GuiControl,1:, ListBox%TargetList%, |%SortedList%
Return
;------------------------------------------------------------
AddFile:
FileSelectFile, FilesToAdd, M 3,, Select some files,
If FilesToAdd =
Return
Loop, parse, FilesToAdd, `n
{
If A_Index = 1
RootPath = %A_LoopField%
Else
{
StringSplit, FileListArray, A_loopField, `.
If FileListArray%FileListArray0% Not Contains %AllowedExtList%
Continue
If FileListArray%FileListArray0% In %ExcludedExtList%
Continue
Else
{
If ListBoxCont%TargetList% =
{
ListBoxCont%TargetList% = %RootPath%\%A_LoopField%
}
Else ;If ListBoxCont%TargetList% <>
{
ListBoxCont%TargetList% := ListBoxCont%TargetList% . "|" . RootPath . "\" . A_LoopField
}
}
}
}
GoSub, SplitUpString
GoSub, FillListFromArray
Return
;------------------------------------------------------------
RemoveItem:
Gui, Submit, NoHide
ItemToRemovePos := ListBox%TargetList%
;Create array of listboxes contents
GoSub, SplitUpString
;Remove Selected Item
GoSub, RemoveSelection
;Recreate array with new list after selected item was removed
GoSub, SplitUpString
;Fill array and update listbox
GoSub, FillListFromArray
Control, Choose, %ItemToRemovePos%, ListBox%TargetList%, %AppWinTitle%
;This method below is a complex version that removes the selected item from the list
;however this does NOT remove that selected item from the array that makes up that list
;GuiControl, -AltSubmit, ListBox%TargetList%
;GuiControlGet, FileList,, ListBox%TargetList%
;ControlGet, ItemToRemove, FindString, %FileList%, ListBox%TargetList%, %AppWinTitle%
;Control, Delete, %ItemToRemove%, ListBox%TargetList%, %AppWinTitle%
;GuiControl, Choose, ListBox%TargetList%, %ItemToRemove%
;GuiControl, +AltSubmit, ListBox%TargetList%
Return
;------------------------------------------------------------
MoveItemDown:
Gui, Submit, NoHide
GoSub, SplitUpString
; If selected entry is not first entry
If (ListBox%TargetList% < ArrayOfAllEntries0)
{
; New position is one up
NewPosition := ListBox%TargetList% + 1
; Flip entries
GoSub, FlipEntriesInArray
; Fill Array into Listbox
GoSub, FillListFromArray
; Keep moved entry selected
GuiControl, Choose, ListBox%TargetList%, %NewPosition%
}
Return
;------------------------------------------------------------
MoveItemUp:
BtnMoveItemUp:
Gui, Submit, NoHide
GoSub, SplitUpString
; If selected entry is not first entry
If (ListBox%TargetList% > 1)
{
; New position is one up
NewPosition := ListBox%TargetList% - 1
; Flip entries
GoSub, FlipEntriesInArray
; Fill Array into Listbox
GoSub, FillListFromArray
; Keep moved entry selected
GuiControl, Choose, ListBox%TargetList%, %NewPosition%
}
Return
;------------------------------------------------------------
ReplaceItem:
Gui, Submit, NoHide
ReplaceItemPos := ListBox%TargetList%
GoSub, SplitUpString
InputBox, UserEntry, Add User Item, Enter some text to add to list %TargetList%, , 300, 200,
ArrayOfAllEntries%ReplaceItemPos% = %UserEntry%
GoSub, FillListFromArray
Return
;------------------------------------------------------------
RemoveDuplicates:
;This uses a complex method, Sort could also be used
Gui, Submit, NoHide
KeptItemPos := ListBox%TargetList%
GoSub, SplitUpString
ItemToRemove := ArrayOfAllEntries%KeptItemPos%
If KeptItemPos = 1
{
StringReplace, ListBoxCont%TargetList%, ListBoxCont%TargetList%, %ItemToRemove%|,, All
}
If KeptItemPos <> 1
{
StringReplace, ListBoxCont%TargetList%, ListBoxCont%TargetList%, |%ItemToRemove%,, All
}
;StringReplace, OutputVar, InputVar, SearchText [, ReplaceText, ReplaceAll?]
;ArrayOfAllEntries%KeptItemPos% = %ItemToRemove%
If ListBoxCont%TargetList% =
{
ListBoxCont%TargetList% = %A_LoopField%
}
Else ;If ListBoxCont%TargetList% <>
{
ListBoxCont%TargetList% := ListBoxCont%TargetList% . "|" . ItemToRemove
}
GoSub, SplitUpString
GoSub, FillListFromArray
Return
;------------------------------------------------------------
SwitchItems:
Gui, Submit, NoHide
TargetItemPos1 := ListBox%TargetList%
GoSub, SplitUpString
TargetItemCont1 := ArrayOfAllEntries%TargetItemPos1%
MsgBox, 0, SwitchItems, Select a second item in the same list that you want to switch with the first. `nPress OK when ready
Gui, Submit, NoHide
TargetItemPos2 := ListBox%TargetList%
GoSub, SplitUpString
TargetItemCont2 := ArrayOfAllEntries%TargetItemPos2%
;Swap the values
ArrayOfAllEntries%TargetItemPos1% = %TargetItemCont2%
ArrayOfAllEntries%TargetItemPos2% = %TargetItemCont1%
;GoSub, SplitUpString
GoSub, FillListFromArray
Return
;------------------------------------------------------------
MoveItemToOtherList:
Gui, Submit, NoHide
ItemToMovePos := ListBox%TargetList%
GoSub, SplitUpString
ItemToMove := ArrayOfAllEntries%ItemToMovePos%
GoSub, TargetList%OtherList%
GoSub, SplitUpString
If ListBoxCont%TargetList% =
ListBoxCont%TargetList% = %ItemToMove%
Else ;If ListBoxCont%TargetList% <>
ListBoxCont%TargetList% := ListBoxCont%TargetList% . "|" . ItemToMove
GoSub, SplitUpString
GoSub, FillListFromArray
GoSub, TargetList%OtherList%
GoSub, RemoveItem
;GoSub, TargetList%OtherList%
GoSub, SplitUpString
GoSub, FillListFromArray
;GoSub, TargetList%OtherList%
Control, Choose, %ItemToMovePos%, ListBox%TargetList%, %AppWinTitle%
Return
;------------------------------------------------------------
CopyItem:
Gui, Submit, NoHide
ItemToMovePos := ListBox%TargetList%
GoSub, SplitUpString
ItemToMove := ArrayOfAllEntries%ItemToMovePos%
GoSub, TargetList%OtherList%
GoSub, SplitUpString
If ListBoxCont%TargetList% =
ListBoxCont%TargetList% = %ItemToMove%
Else ;If ListBoxCont%TargetList% <>
ListBoxCont%TargetList% := ListBoxCont%TargetList% . "|" . ItemToMove
GoSub, SplitUpString
GoSub, FillListFromArray
GoSub, TargetList%OtherList%
;GoSub, RemoveItem
;GoSub, TargetList%OtherList%
GoSub, SplitUpString
GoSub, FillListFromArray
;GoSub, TargetList%OtherList%
Control, Choose, %ItemToMovePos%, ListBox%TargetList%, %AppWinTitle%
Return
;------------------------------------------------------------
AddUserEntry:
InputBox, UserEntry, Add User Item, Enter some text to add to list %TargetList%, , 300, 200,
GuiControl, 1:, ListBox%TargetList%, %UserEntry%
If ListBoxCont%TargetList% =
{
ListBoxCont%TargetList% = %UserEntry%
}
Else ;If ListBoxCont%TargetList% <>
{
ListBoxCont%TargetList% := ListBoxCont%TargetList% . "|" . UserEntry
}
Return
;------------------------------------------------------------
ImportListFromFile:
SelectImports:
FileSelectFile, UserImportFile, 3,, Please Select a File to Import to the Key Lists, *.txt
If UserImportFile =
{
MsgBox, 0, Importing Error, There was no file to import `nImport Aborted ; Prompts user to select file for import
Return
}
Gui, 3:Show,,Importing using Delimiters
Return
ContImport:
Gui, 3:Submit
Loop, read, %UserImportFile% ;,%UserImportFile%
{
Loop, parse, A_LoopReadLine, %UserDelimiter%, %UserOmit%
{
GuiControl, 1:, ListBox%TargetList%, %A_LoopField%
If ListBoxCont%TargetList% =
{
ListBoxCont%TargetList% = %A_LoopField%
}
Else ;If ListBoxCont%TargetList% <>
{
ListBoxCont%TargetList% := ListBoxCont%TargetList% . "|" . A_LoopField
}
}
}
Return
;------------------------------------------------------------
GuiDropFiles:
Loop, parse, A_GuiControlEvent, `n
{
StringSplit, FileListArray, A_loopField, `.
If FileListArray%FileListArray0% Not In %AllowedExtList%
Continue
Else If FileListArray%FileListArray0% In %ExcludedExtList%
Continue
Else
{
;GuiControl,1:, ListBox%TargetList%, %RootPath%\%A_LoopField%
If ListBoxCont%TargetList% =
{
ListBoxCont%TargetList% = %A_LoopField%
}
Else ;If ListBoxCont%TargetList% <>
{
ListBoxCont%TargetList% := ListBoxCont%TargetList% . "|" . A_LoopField
}
}
}
GoSub, SplitUpString
GoSub, FillListFromArray
Return
;############################################################
;############################################################
SplitUpString:
SplitVar := ListBoxCont%TargetList%
StringSplit, ArrayOfAllEntries, SplitVar, |
Return
;------------------------------------------------------------
FlipEntriesInArray:
PosValue := ListBox%TargetList%
; Get selected entry from Array
CurrentEntry := ArrayOfAllEntries%PosValue% ;%LstToDo%
; Put entry from new position in Array into current position
ArrayOfAllEntries%PosValue% := ArrayOfAllEntries%NewPosition%
; Put selected entry into new position in Array
ArrayOfAllEntries%NewPosition% = %CurrentEntry%
Return
;-------------------------------------------------------------
; Build string from array and assign it to the listbox control
FillListFromArray:
FillString =
Loop, %ArrayOfAllEntries0%
{
Entry := ArrayOfAllEntries%A_Index%
FillString = %FillString%|%Entry%
}
GuiControl,1:, ListBox%TargetList%, %FillString%
StringTrimLeft, FillString, FillString, 1
ListBoxCont%TargetList% = %FillString%
Return
;--------------------------------------------------------------
RemoveSelection:
ItemToRemove := ArrayOfAllEntries%ItemToRemovePos%
If ItemToRemovePos = 1
{
StringReplace, ListBoxCont%TargetList%, ListBoxCont%TargetList%, %ItemToRemove%|
}
If ItemToRemovePos <> 1
{
StringReplace, ListBoxCont%TargetList%, ListBoxCont%TargetList%, |%ItemToRemove%
}
;Used to remove selected item if its the only item remaining in a list
If ArrayOfAllEntries0 <= 1
{
StringReplace, ListBoxCont%TargetList%, ListBoxCont%TargetList%, %ItemToRemove%
}
Return
Exit:
GuiClose:
ExitApp
F9::Reload
F10::ListVars
|
_________________ my lame sig 
Last edited by Invalid User on Wed Apr 20, 2005 9:26 pm; edited 7 times in total |
|
| Back to top |
|
 |
DrSamRaza_1
Joined: 15 Apr 2005 Posts: 8 Location: Pakistan
|
Posted: Tue Apr 19, 2005 1:01 am Post subject: Very Nice |
|
|
Dear Invalid User
It is very nice effort on your part to write a helpful tutorial for Novice Coders like my self. It is elaborate and practical. I know it must have been a pain to write a long document for other's sake.
Someone once said and I quote
"Smart people Write books. Smarter people Read them "
So in this case I am smarter than you are. Just kidding.
Now to the nitty gritty.
I have some questions and few Comments and Suggestions if you don't mind.
Comment # 1:
I have experienced that when you use v to give a GUI control a value, it some times happens, specially when you have to return to the GUI without Reload that you get an error message stating that one variable can be used once per GUI.
Example # 1:
Suppose I have A GUI that has to use two buttons with the same value
Like
| Code: |
Gui Add, Edit, w200 x10 y10 vmyEdit1, xyz
Gui Add, Edit, w200 xp+0 yp+30 vmyEdit2, xyz
Gui Add, Button, Xp+210 yp-30 , OK
Gui Add, Button, Xp+100 yp+30 , OK
|
Now if I have to use both buttons, I can not use
and have them both do different kind of subroutine. The script won't allow two simmilar Labels.
Suggestion # 1:
I Have found a Workaround like this
| Code: |
Gui Add, Edit, w200 x10 y10 , xyz
Gui Add, Edit, w200 xp+0 yp+30, xyz
Gui Add, Button, Xp+210 yp-30 gOK1 , OK
Gui Add, Button, Xp+100 yp+30 gOK2, OK
|
And Further, I use GuiControlGet to get the value of the Edit control instead of through vmyEdit
like this
| Code: |
Gui Add, Edit, w200 x10 y10, xyz
Gui Add, Edit, w200 xp+0 yp+30, xyz
Gui Add, Button, Xp+210 yp-30 gOK1, OK
Gui Add, Button, Xp+100 yp+30 gOK2, OK
Gui Show,, MY Title
Return
OK1:
Gui Submit
GuiControlGet, myEdit1,, Edit1
GuiControlGet, myEdit2,, Edit2
Do Something Here
Return
OK2:
Gui Submit
GuiControlGet, myEdit1,, Edit1
GuiControlGet, myEdit2,, Edit2
Do Something Else Here
Return
|
In this way a Control can be utillized as many times as needed without showing the above mentioned error message.
Specially when you need a value in the Edit control and show a message which gives you choice to retry. like this
| Code: |
If myEdit1 =
{
msgBox 20, My Title, OoopS! You forgot to write the xyz. `n`nRetry ?
IfMsgBox, Yes, Return
ExitApp
}
|
Now if the user presses Yes to Retry putting some value, and control was designed with a v the error message pops up stating that one GUI value can not be used more than one time in a script.
But if above example is used, Edit 1 or Edit 2 can be used countless number of times.
I may be wrong but I find this method work better than assigning the v to a control and using Button labels.
Question # 1:
What do you think ? _________________ Intelligence helps, but hard work is the key to Success |
|
| Back to top |
|
 |
Invalid User
Joined: 14 Feb 2005 Posts: 442 Location: Texas, Usa
|
Posted: Tue Apr 19, 2005 3:13 am Post subject: |
|
|
For your first problem with the buttons each button can contain the same text and each proform a differnt subroutine, like the following | Code: |
Gui, Add, Button, gSub1, Ok
Gui, Add, Button, gSub2, Ok
Gui, Show
Return
Sub1:
MsgBox, You pressed the first OK button
Return
Sub2:
MsgBox, You preseed the second OK Button
Return |
I think that should solve that. But it looks like you knew that!
I know the error msg your talking about and I get it when I show a gui that has a vVarName attached to a control thats gui is already present to the user. When showing it a second time you should get that error msg. I prevent this by disabling the control that was used to show it the first time so that a user cant show that same gui twice, preventing this error msg. when the second gui is closed i reenable the control again.
We each use a different method to achieve the same result. we could compare and test each method to see which runs faster but I think it may be a waste of time since both method are very fast. But if the situation relies on that function occuring over a duration of milliseconds then there may be good reason to test which run faster.
conclusion: I think both methods are fine. As each person is unique so is there style of programming. While I use mine, you use yours. And each is fine. So I dont think it really matters either way. Thanks for the feed back. _________________ my lame sig  |
|
| Back to top |
|
 |
TheLostBoy
Joined: 18 Apr 2005 Posts: 14 Location: WI, USA
|
Posted: Wed Apr 20, 2005 9:33 am Post subject: |
|
|
VERY NICE!!... heh.. lets just say.. um... "I'm usin' it"  _________________ "It was when I found out I could make mistakes that I knew I was on to something."
--Ornette Coleman |
|
| Back to top |
|
 |
toralf
Joined: 31 Jan 2005 Posts: 3841 Location: Bremen, Germany
|
Posted: Wed Apr 20, 2005 1:09 pm Post subject: |
|
|
Hi,
Thank you for posting this. It will be very helpfull for newbies.
I have some remarks, though. I hope you don't mind:
1) The following lines are not needed in the SplitUpString, since the split overrides all items. If you want to free the memory of that array, you shoudl do that in the FillListFromArray routine | Code: | If ArrayOfAllEntries0 <> 0
{
Loop, %ArrayOfAllEntries0%
{
ArrayOfAllEntries%A_Index% =
}
} |
2) instead of destoying the GUIs and rebuilding them, you could build them at start time and just show them or submit them when needed. This structures the script better and the routines of the buttons get short and easier to read.
3) In MoveCurselDown and MoveCurselUp you are using SendMessag? Why? you could as well use (for move up) | Code: | Gui,Submit,NoHide
ChoicePos:= ListBox%TargetList%
ChoicePos--
If (ChoicePos> 0)
Control, Choose, %ChoicePos%, ListBox%TargetList% |
4) The follwoing lines could be: | Code: | If A_Index = 1
{
RootPath = %A_LoopField%
}
If A_Index > 1
{
|
| Code: | If A_Index = 1
RootPath = %A_LoopField%
Else
{ |
5) It might be the case that there are several dots inside a file name, so that the your code might not work: | Code: | StringSplit, FileListArray, A_loopField, `.
If FileListArray2 Not Contains %AllowedExtList%
Continue
If FileListArray2 In %ExcludedExtList%
Continue | You could get the last extention with "FileListArray%FileListArray0%" or you could use Splitpath. And you could combine the If statements with "Else" for speedup.
6) With the following lines you add the file to the listbox and to the string. I would suggest to add the file to the string and use the existing other subroutines to put it into the listbox. I know that this is just a matter of taste, but it is then easier to understand (straight forward). The string is the master on which is operated, the listbox is just a representation. (same applies to ContImport)
| Code: | GuiControl,1:, ListBox%TargetList%, %RootPath%\%A_LoopField%
If ListBoxCont%TargetList% =
{
ListBoxCont%TargetList% = %RootPath%\%A_LoopField%
}
Else ;If ListBoxCont%TargetList% <>
{
ListBoxCont%TargetList% := ListBoxCont%TargetList% . "|" . RootPath . "\" . A_LoopField
} |
7) In your RemoveSelection, you are replacing a string. But what happens if there are multiple identical strings in the list. the routine would remove the selected. It would remove th first or all. Instead I would use a loop: | Code: | RemoveSelection:
Loop, %ArrayOfAllEntries0%
{
If (A_Index >= ItemToRemovePos)
{
i := ItemToRemovePos + 1
ArrayOfAllEntries%A_index% := ArrayOfAllEntries%i%
}
}
If (ArrayOfAllEntries0 > 0)
ArrayOfAllEntries0--
return |
8) For FillListFromArray I would suggest to use:
| Code: | FillListFromArray:
FillString =
Loop, %ArrayOfAllEntries0%
{
Entry := ArrayOfAllEntries%A_Index%
FillString = %FillString%|%Entry%
}
GuiControl,1:, ListBox%TargetList%, %FillString%
StringTrimLeft, FillString, FillString, 1
ListBoxCont%TargetList% = %FillString%
|
9) Personally I prever to stay either with arrays or with strings. Since I prefer to work with arrays for lists, due to their capabilities for manipulations, I would work on arrays all the time and only use the string to fill up the list (or in other cases - like sort). But this would would require big change to your script, and it is only a matter of taste.
just my 2 cents _________________ Ciao
toralf  |
|
| Back to top |
|
 |
Laszlo
Joined: 14 Feb 2005 Posts: 4078 Location: Pittsburgh
|
Posted: Wed Apr 20, 2005 5:54 pm Post subject: |
|
|
toralf writes | Quote: | | ... I would work on arrays all the time... | It should depend on the application. I use lists for ini file settings, which often change in the middle; for lists of active windows: when some are closed, they have to be removed from the list, when a function processes one, it gets pushed back in the list at the other end; removing repetitions, while keeping the original order, and so on. With lists these can be simpler, with arrays these operations, or even a simple search require loops, and moving most of their elements to new locations. The code is longer and more complicated. Furthermore, array elements are just dynamic variables, accessing them requires a search in internal AHK tables, creating array elements requires moving large parts of these tables. Accordingly, arrays are not necessarily faster than lists.
On the other hand, arrays are better suited for translation tables, character substitution, databases, graphics, etc. So, use always, what fits to the task. If you employ my low level list function library, handling lists in scripts becomes very easy. Invalid User's nice GUI approach could have been built on those functions, too, making it much shorter and easier to maintain. |
|
| Back to top |
|
 |
AGU Guest
|
Posted: Wed Apr 20, 2005 6:02 pm Post subject: |
|
|
Do I read some lines of code from my ToDo v0.1 application?
If so, I'm happy that InvalidUser found them helpful.  |
|
| Back to top |
|
 |
Invalid User
Joined: 14 Feb 2005 Posts: 442 Location: Texas, Usa
|
Posted: Wed Apr 20, 2005 8:33 pm Post subject: |
|
|
yes agu, your code is in here and thanks to you and toraf is planned in the document that will go with this. Thanks both for code. it saved me some time already having these subroutines written _________________ my lame sig  |
|
| Back to top |
|
 |
Invalid User
Joined: 14 Feb 2005 Posts: 442 Location: Texas, Usa
|
Posted: Wed Apr 20, 2005 9:23 pm Post subject: |
|
|
@toralf! Dang man, all being pushing about it I am OFFENDED
nah, I am kidding, Thanks for the feed back lets see here
#1, I didnt know wheather the higher values of an array would be redefined as blank. So I used this to make sure, I removed this section and it still works fine. Thanks
#2 Thanks I didnt realize I was doing that. Kinda tired.
#3 This code came from another script that required send msg. So I simply adapted it to this. However for a novice or newb (like myself) Using your code may be much easyier to understand, I changed that. Thanks
#4 Changed this, Uses less code and I think it runs faster too. I should have see this one! Thanks
#5 I didnt think of that, I should have caught that too. I would have if I had used the ahk install files on my pc to test that filter. Changed code to use arrays to determine File extension for filter, Thanks
#6 Fixed, That I can admit to doing wrong, those routines were developed before SplitUpString and FillListFromArray were. Thanks for noticing such little details
#7 I could not get this to work by just copy and pasting into the script, Is this code tested? And I realized while testing it that something else would have to be delveloped as StringSearch has two options like ya said.
#8 hmm Looks good, works good, and its shorter. Thank you.
#9 I am a crackpot, what can I say. "there are three ways to skin a cat, The good way, the bad way, and the other way" I just made that up, but it fits.
Thanks for all the feedback _________________ my lame sig  |
|
| Back to top |
|
 |
toralf
Joined: 31 Jan 2005 Posts: 3841 Location: Bremen, Germany
|
Posted: Thu Apr 21, 2005 4:24 am Post subject: |
|
|
Sorry for #7) (wasn't tested) I think you have to replace | Code: | | i := ItemToRemovePos + 1 | with this _________________ Ciao
toralf  |
|
| Back to top |
|
 |
Invalid User
Joined: 14 Feb 2005 Posts: 442 Location: Texas, Usa
|
Posted: Thu Apr 21, 2005 6:19 am Post subject: |
|
|
It doesnt work  _________________ my lame sig  |
|
| Back to top |
|
 |
toralf
Joined: 31 Jan 2005 Posts: 3841 Location: Bremen, Germany
|
Posted: Thu Apr 21, 2005 1:23 pm Post subject: |
|
|
Have you split up the string?
And filled the array back in to the listbox after the remove routine? _________________ Ciao
toralf  |
|
| Back to top |
|
 |
Invalid User
Joined: 14 Feb 2005 Posts: 442 Location: Texas, Usa
|
Posted: Thu Apr 21, 2005 8:52 pm Post subject: |
|
|
I gott 'er fixed thanks _________________ my lame sig  |
|
| Back to top |
|
 |
|
|
You can post new topics in this forum You can reply to topics in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|