 |
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: Tue Feb 22, 2005 3:56 am Post subject: Switching Contents of delimted list |
|
|
I have a list of values in a list like "Value1|Value2|Value3|"
Is there a simple/easy way to change the list over to "Value1|Value3|Value2|"
my objective is to be able to switch/swap Values in a list. any suggestions? _________________ my lame sig  |
|
| Back to top |
|
 |
Titan
Joined: 11 Aug 2004 Posts: 5068 Location: imaginationland
|
Posted: Tue Feb 22, 2005 4:01 am Post subject: |
|
|
GuiControl |
|
| Back to top |
|
 |
Invalid User
Joined: 14 Feb 2005 Posts: 442 Location: Texas, Usa
|
Posted: Tue Feb 22, 2005 4:31 am Post subject: |
|
|
Hmm not quite I want to move a entry of a list box one up or down in the list. _________________ my lame sig  |
|
| Back to top |
|
 |
Titan
Joined: 11 Aug 2004 Posts: 5068 Location: imaginationland
|
Posted: Tue Feb 22, 2005 5:07 am Post subject: |
|
|
You could:
Use GuiControlGet to get the control's contents.
Use StringReplace... to cut off values before and including the first pipeline.
Use GuiControl to set the control the new name.
Just an idea. |
|
| Back to top |
|
 |
Invalid User
Joined: 14 Feb 2005 Posts: 442 Location: Texas, Usa
|
Posted: Tue Feb 22, 2005 5:41 am Post subject: |
|
|
Well the few attempts I did got the Gui contents, then that contents location, then its lenght, then StringReplace,,, | or what have ya...to leave me with the name of the contents that was selected in the list box, then, I tried doing string replace on the ....on crap I lost myself... have a look at this
| Code: | {
StringLen, ItemLenMin, Cur_Tasks
StringGetPos, ItemPos, Cur_TL, %Cur_Tasks%
ItemLenMin += 1 ;accounts for | delimiter in string
ItemPosMax += %ItemLenMin%
StringMid, Known_Sel_Item, Cur_TL, %ItemPos%, %ItemPosMax%
MsgBox, %Known_Sel_Item%
StringSplit, Order_Array, Cur_TL, `|
StringReplace, Known_Sel_Item, Known_Sel_Item, |,
;ListVars
Loop, %Order_Array0% ;Switch Array Elements
{
OrderArrayNum = %A_Index%
OrderArrayNum -= 1
OrderX = %Order_Array%%OrderArrayNum%
If Order_Array%A_Index% = %Known_Sel_Item%
{
Order_Array%OrderArrayNum% = %Known_Sel_Item%
Order_Array%A_Index% = %OrderX%
;StringReplace, OutputVar, InputVar, SearchText [, ReplaceText, ReplaceAll?]
Break
}
}
----------attemp1 /\ attemp 2 \/--------------------------------------------------
StringUp:
ItemLenMin =
ItemPosMax =
If List_ID = Cur
{
StringLen, ItemLenMin, Cur_Tasks
StringGetPos, ItemPos, Cur_TL, %Cur_Tasks%
ItemLenMin += 1 ;accounts for | delimiter in string
ItemPosMax += %ItemLenMin%
StringMid, Known_Sel_Item, Cur_TL, %ItemPos%, %ItemPosMax%
StringReplace, Known_Sel_Item, Known_Sel_Item, |,, All
;------------------------
Loop, Parse, Cur_TL, `|
{
Prev_Pos = %A_LoopField%
StringGetPos, Prev_PosPos, Cur_TL, %Prev_Pos%
StringLen, Prev_PosLen, Prev_Pos
StringReplace, Prev_Pos, Prev_Pos, |,,All
If A_LoopField = %Known_Sel_Item%
{
StringReplace, OutputVar, InputVar, SearchText [, ReplaceText, ReplaceAll?]
}
}
MsgBox %Cur_TL%
GuiControl,, Cur_Tasks, |%Cur_TL%
} |
neither of these work but eh _________________ my lame sig  |
|
| Back to top |
|
 |
toralf
Joined: 31 Jan 2005 Posts: 3842 Location: Bremen, Germany
|
Posted: Tue Feb 22, 2005 8:43 am Post subject: |
|
|
I had a similar problem.
I got around it by using an array for all values. On the array you can do all these nice manipulations. When it has to be given to the list the array items get stiched together to a string. Here is a snipet that worked for my case
| Code: | ;############# Move selected machine one up in list #######################
MoveMachineUpInList:
;Get position in list of selected machine
Gui, 2:Submit, NoHide
;If machine is not the top most, move it up
If (LstOfAllMachines > 1)
{
;New position is one up
NewPosition := LstOfAllMachines - 1
;Exchange machines
GoSub, ReorderMachinesInArray
;Set the new position as current to preserve selection
LstOfAllMachines = %NewPosition%
;Fill Array into Listbox
GoSub, FillListFromArray
}
return
;############# Move selected machine one down in list #####################
MoveMachineDownInList:
;Get position in list of selected machine
Gui, 2:Submit, NoHide
;If Machine is not last in list, move it down
If (LstOfAllMachines < ArrayOfAllMachines0)
{
;New position is one down
NewPosition := LstOfAllMachines + 1
;Exchange machines
GoSub, ReorderMachinesInArray
;Set the new position as current to preserve selection
LstOfAllMachines = %NewPosition%
;Fill Array into Listbox
GoSub, FillListFromArray
}
return
;############# Exchange position of Machines in Array #####################
ReorderMachinesInArray:
;Get selected Machine with position from Array
CurrentMachine := ArrayOfAllMachines%LstOfAllMachines%
;Put machine from new position in Array into current position
ArrayOfAllMachines%LstOfAllMachines% := ArrayOfAllMachines%NewPosition%
;Put selected machine into new position in Array
ArrayOfAllMachines%NewPosition% = %CurrentMachine%
return
;############# Fill Listbox with Machines from Array ######################
FillListFromArray:
;Build string from array and assign it to the listbox control and preserve the selection
ListOfAllMachines =
Loop, %ArrayOfAllMachines0%
{
Machine := ArrayOfAllMachines%A_index%
If (A_Index = LstOfAllMachines)
ListOfAllMachines = %ListOfAllMachines%|%Machine%|
else
ListOfAllMachines = %ListOfAllMachines%|%Machine%
}
If (LstOfAllMachines = ArrayOfAllMachines0)
ListOfAllMachines = %ListOfAllMachines%|
GuiControl,2:,LstOfAllMachines, %ListOfAllMachines%
return |
_________________ Ciao
toralf  |
|
| Back to top |
|
 |
Invalid User
Joined: 14 Feb 2005 Posts: 442 Location: Texas, Usa
|
Posted: Tue Feb 22, 2005 9:23 am Post subject: |
|
|
Nicely commented, thanks. That should fix my headache. maybe, I will soon find out _________________ my lame sig  |
|
| Back to top |
|
 |
Invalid User
Joined: 14 Feb 2005 Posts: 442 Location: Texas, Usa
|
Posted: Wed Feb 23, 2005 1:01 am Post subject: |
|
|
| Code: | If List_ID = Cur
{
;Get List items place number
GuiControlGet, Cur_Tasks
;If Item is not the topmost in list move it up
If (Cur_Tasks > 1)
{
NewPosition := Cur_Tasks - 1
;Get selected Item with position from Array
CurrentItem := Cur_TLArray%Cur_Tasks%
;Put machine from new position in Array into current position
Cur_TLArray%Cur_Tasks% := Cur_TLArray%NewPosition%
;Put selected machine into new position in Array
Cur_TLArray%NewPosition% = %CurrentItem%
;Set the new position as current to preserve selection
Cur_Tasks = %NewPosition%
;--------
;Build string from array and assign it to the listbox control and preserve the selection
ListOfAllMachines =
Loop, %Cur_TLArray0%
{
Machine := Cur_TLArray%A_index%
If (A_Index = Cur_Tasks)
ListOfAllMachines = %ListOfAllMachines%|%Machine%|
else
ListOfAllMachines = %ListOfAllMachines%|%Machine%
}
If (Cur_Tasks = Cur_TLArray0)
ListOfAllMachines = %ListOfAllMachines% ;|
GuiControl,, Cur_Tasks, %ListOfAllMachines%
}
Return
} |
This is what I did and it kinda does what it should but doenst quite, so I was wondering if you, toralf could have a second look. _________________ my lame sig  |
|
| Back to top |
|
 |
toralf
Joined: 31 Jan 2005 Posts: 3842 Location: Bremen, Germany
|
Posted: Wed Feb 23, 2005 10:23 am Post subject: |
|
|
Hi,
| Quote: | | This is what I did and it kinda does what it should but doenst quite, so I was wondering if you, toralf could have a second look. |
What do you mean by "it kinda does what it should but doesn't quite"? What is correct and what isn't?
By looking at the code I couldn't find anything wrong. Have you set the listbox option AltSubmit (it is required)? So that it gives you the position of the selection?
Check with MsgBox to get data of the variables along the if statement to see that they contain the correct data. _________________ Ciao
toralf  |
|
| Back to top |
|
 |
Invalid User
Joined: 14 Feb 2005 Posts: 442 Location: Texas, Usa
|
Posted: Wed Feb 23, 2005 7:32 pm Post subject: |
|
|
Yep, AltSubmit is used, the nature of its malfuction is hard to describe, I am useing the entries in the list for testing and it always seems to be the 3rd Item (just the original 3rd) that is controled. the other two are never moved up one, just the third and even if a diffeerent selection is made it still grabs the 3rd which cycles back to the bottom. I dont know its kinky on my, I am gonna have a nother long look at it and attempt clearing all the used vars in the section and see if that does the trick, but they are all redefined each time so I dont see what the deal is. _________________ 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
|