I dunno... this is just an idea?
I used TM List Handler
not everything in the code is used, i'm just to lazy to figure out which subs are being used in the handler.
gosub TM_CreateList List Newlist1 220 44 121 97 White WindowText %font_arial 8
Menu Show
GoSub ShowEUOMENU1
start:
Set #MenuButton N/A
Loop:
if #MenuButton <> N/A
Goto #MenuButton
Goto Loop
Add:
Menu Get Regreants
gosub Getregname
Goto Start
HALT
sub getregname
if #MenuRes = 1
Set %Item Black_Pearl
if #MenuRes = 2
Set %Item Blood_Moss
if #MenuRes = 3
Set %Item Ginsing
if #MenuRes = 4
Set %Item NightShade
if #MenuRes = 5
Set %Item Mandrake_Root
if #MenuRes = 6
Set %Item Sulpher_Ash
if #MenuRes = 7
Set %Item Garlic
Menu Get Total
Set %Total #MenuRes
Set %Add_Item %Item , _ , %Total
GoSub AddSpace %Add_Item
gosub TM_AddToList Newlist1 #Result
return
;--------- EasyUO Menu Designer Code Begin ---------
sub showEUOMenu1
;menu Clear
menu Window Title EUOMenu1
menu Window Color BtnFace
menu Window Size 414 230
menu Font Transparent #true
menu Font Align Right
menu Font Name MS Sans Serif
menu Font Size 8
menu Font Style
menu Font Color WindowText
menu Font Transparent #false
menu Font Align Left
menu Text EUOLabel1 236 28 Shoping List Max
menu Font BGColor Window
menu Combo Create Regreants 28 44 105
menu Combo Add Regreants Black Pearl
menu Combo Add Regreants Blood Moss
menu Combo Add Regreants Ginsing
menu Combo Add Regreants NightShade
menu Combo Add Regreants Mandrake Root
menu Combo Add Regreants Sulpher Ash
menu Combo Add Regreants Garlic
menu Edit Total 140 44 73 Set , #spc , Amount
;menu List Create EUOListBox1 220 44 121 97
menu Font BGColor BtnFace
menu Button Add 140 72 31 17 Add
menu Button Delete 176 72 39 17 Delete
menu Show 421 270
return
;--------- EasyUO Menu Designer Code End ---------
;=================================================================
; Script Name: TrailMyx's List Handling Subs
; Author: TrailMyx
; Version: 0.20
; Shard OSI / FS: OSI / FS OK
; Revision Date: 3/12/2008
; Purpose: Take the pain out of managing lists
;
; Subroutines included:
; TM_CreateList - Creates the list
; TM_DrawList
; TM_ReDrawList
; TM_AddToList
; TM_DeleteAllItemsInList
; TM_CopyAllItemsInList
; TM_DeleteIndexedItemInList
; TM_DeleteExactItemsInList
; TM_DeleteItemsInList
; TM_SearchForExactItemInList
; TM_SearchForItemInList
; TM_CountExactItemsInList
; TM_CountItemsInList
; TM_AlphabetizeList
;
; Requirements:
;
; Locals/Globals:
; TM_window_list_ , %2 (local)
;
; Special Thanks:
;
;=================================================================
; --- Test and sample code:
;set %font_arial MS , #SPC , Ariel
;gosub showEUOMenu1
;gosub TM_CreateList List Newlist1 10 10 100 100 White WindowText %font_arial 8
;gosub TM_LoadListFromFile c:\testlist.txt ; load a list from file
;gosub TM_ReDrawList Newlist1 ; redraw list
;gosub TM_CreateList List Newlist2 110 10 100 100 White WindowText %font_arial 8
;gosub TM_AddToList Newlist1 alpha
;gosub TM_AddToList Newlist1 gamma
;gosub TM_AddToList Newlist1 beta
;gosub TM_AddToList Newlist1 monkey
;gosub TM_AlphabetizeList Newlist1 >
;gosub TM_AddToList Newlist2 monkey
;gosub TM_DeleteItemsInList Newlist1 1 #TRUE #TRUE
;gosub TM_CopyAllItemsInList Newlist1 Newlist2 #FALSE #TRUE
;gosub TM_SaveListToFile Newlist1 c:\testlist.txt
;stop
;-----------------------------------------------------------------
sub TM_LoadListFromFile
namespace push
namespace local LLFF
set !filename %1
gosub TM_FileSystem_LoadFile !filename
namespace pop
return
;-----------------------------------------------------------------
sub TM_SaveListToFile
namespace push
namespace local TM_window_list_ , %1
set !listname %1
set !filename %2
gosub TM_FileSystem_CreateFileHandle save_handle
gosub TM_FileSystem_SaveVariable local TM_window_list_ , !listname save_handle listtype
gosub TM_FileSystem_SaveVariable local TM_window_list_ , !listname save_handle listname
gosub TM_FileSystem_SaveVariable local TM_window_list_ , !listname save_handle x1
gosub TM_FileSystem_SaveVariable local TM_window_list_ , !listname save_handle y1
gosub TM_FileSystem_SaveVariable local TM_window_list_ , !listname save_handle x2
gosub TM_FileSystem_SaveVariable local TM_window_list_ , !listname save_handle y2
gosub TM_FileSystem_SaveVariable local TM_window_list_ , !listname save_handle bgcolor
gosub TM_FileSystem_SaveVariable local TM_window_list_ , !listname save_handle txtcolor
gosub TM_FileSystem_SaveVariable local TM_window_list_ , !listname save_handle font
gosub TM_FileSystem_SaveVariable local TM_window_list_ , !listname save_handle fontsize
gosub TM_FileSystem_SaveVariable local TM_window_list_ , !listname save_handle fontstyle
gosub TM_FileSystem_SaveVariable local TM_window_list_ , !listname save_handle draw
gosub TM_FileSystem_SaveVariable local TM_window_list_ , !listname save_handle list_ptr
for !j 0 !list_ptr
gosub TM_FileSystem_SaveVariable local TM_window_list_ , !listname save_handle list , !j
gosub TM_FileSystem_SaveFile save_handle !filename
set #RESULT !listname
namespace pop
return #RESULT
;-----------------------------------------------------------------
sub TM_CreateList
namespace push
namespace local TM_window_list_ , %2
namespace clear
set !listtype %1
set !listname %2
set !x1 %3
set !y1 %4
set !x2 %5
set !y2 %6
set !bgcolor %7
set !txtcolor %8
set !font %9
set !fontsize %10
if %0 >= 11
set !fontstyle %11
else
set !fontstyle N/A
set !draw #TRUE
if NODRAW in !listtype
set !draw #FALSE
if List in !listtype
set !listtype List
if Combo in !listtype
set !listtype Combo
if !draw = #TRUE
gosub TM_DrawList !listname
set !list_ptr 0
namespace pop
return
;-----------------------------------------------------------------
sub TM_DrawList
namespace push
namespace local TM_window_list_ , %1
set !temp_LPC #LPC
set #LPC 1000
set !listname %1
menu Font BGColor !bgcolor
menu Font Color !txtcolor
menu Font Size !fontsize
menu Font Name !font
if !fontstyle = N/A
menu Font Style
else
menu Font Style !fontstyle
menu !listtype create !listname !x1 !y1 !x2 !y2
set !end !list_ptr - 1
if !end >= 0
{
for !i 0 !end
menu !listtype add !listname !list . !i
}
set #LPC !temp_LPC
namespace pop
return
;-----------------------------------------------------------------
sub TM_ReDrawList
namespace push
namespace local TM_window_list_ , %1
menu delete %1
gosub TM_DrawList %1
namespace pop
return
;-----------------------------------------------------------------
sub TM_AddToList
namespace push
namespace local TM_window_list_ , %1
set !listname %1
set !item %2
set !list . !list_ptr !item
set !list_ptr !list_ptr + 1
set #RESULT !list_ptr
menu !listtype add !listname !item
namespace pop
return #RESULT
;-----------------------------------------------------------------
sub TM_DeleteAllItemsInList
namespace push
namespace local TM_window_list_ , %1
set !temp_LPC #LPC
set #LPC 1000
set !listname %1
set !redraw %2
if !list_ptr >= 0
{
for !i 0 !list_ptr
set !list . !i N/A
set !list_ptr 0
if !redraw = #TRUE
gosub TM_ReDrawList !listname
}
set #LPC !temp_LPC
namespace pop
return #RESULT
;-----------------------------------------------------------------
sub TM_CopyAllItemsInList
namespace push
namespace local TM_window_list_ , %1
set !temp_LPC #LPC
set #LPC 1000
set !listname1 %1
set !listname2 %2
set !append %3
set !redraw %4
if !append <> #TRUE
gosub TM_DeleteAllItemsInList !listname2
if !list_ptr > 0
{
set !end !list_ptr - 1
for !i 0 !end
gosub TM_AddToList !listname2 !list . !i
if !redraw = #TRUE
gosub TM_ReDrawList !listname2
}
set #LPC !temp_LPC
namespace pop
return #RESULT
;-----------------------------------------------------------------
sub TM_DeleteIndexedItemInList
namespace push
namespace local TM_window_list_ , %1
set !temp_LPC #LPC
set #LPC 1000
set !listname %1
set !index %2 - 1
set !redraw %3
if !index >= 0
{
for !i !index !list_ptr
{
set !next !i + 1
set !list . !i !list . !next
}
set !list_ptr !list_ptr - 1
if !redraw = #TRUE
gosub TM_ReDrawList !listname
}
set #LPC !temp_LPC
namespace pop
return #RESULT
;-----------------------------------------------------------------
sub TM_DeleteExactItemsInList
namespace push
namespace local TM_window_list_ , %1
set !temp_LPC #LPC
set #LPC 1000
set !listname %1
set !item %2
set !deleteall %3
set !redraw %4
set !count 0
for !j 0 !list_ptr
{
if !list . !j = !item
{
set !count !count + 1
for !i !j !list_ptr
{
set !next !i + 1
set !list . !i !list . !next
}
set !j !j - 1
set !list_ptr !list_ptr - 1
if !deleteall = #FALSE
break
}
}
if !redraw = #TRUE
gosub TM_ReDrawList !listname
set #RESULT !count
set #LPC !temp_LPC
namespace pop
return #RESULT
;-----------------------------------------------------------------
sub TM_DeleteItemsInList
namespace push
namespace local TM_window_list_ , %1
set !temp_LPC #LPC
set #LPC 1000
set !listname %1
set !item %2
set !deleteall %3
set !redraw %4
set !count 0
for !j 0 !list_ptr
{
if !item in !list . !j
{
set !count !count + 1
for !i !j !list_ptr
{
set !next !i + 1
set !list . !i !list . !next
}
set !j !j - 1
set !list_ptr !list_ptr - 1
if !deleteall = #FALSE
break
}
}
if !redraw = #TRUE
gosub TM_ReDrawList !listname
set #RESULT !count
set #LPC !temp_LPC
namespace pop
return #RESULT
;-----------------------------------------------------------------
sub TM_SearchForExactItemInList
namespace push
namespace local TM_window_list_ , %1
set !temp_LPC #LPC
set #LPC 1000
set !listname %1
set !item %2
set !highlight %3
for !i 0 !list_ptr
{
if !list . !i = !item
{
set #RESULT !i + 1
if !highlight = #TRUE
menu !listtype select !listname #RESULT
namespace pop
return #RESULT
}
}
set #LPC !temp_LPC
namespace pop
return #FALSE
;-----------------------------------------------------------------
sub TM_SearchForItemInList
namespace push
namespace local TM_window_list_ , %1
set !temp_LPC #LPC
set #LPC 1000
set !listname %1
set !item %2
set !highlight %3
for !i 0 !list_ptr
{
if !item in !list . !i
{
set #RESULT !i + 1
if !highlight = #TRUE
menu !listtype select !listname #RESULT
namespace pop
return #RESULT
}
}
set #LPC !temp_LPC
namespace pop
return #FALSE
;-----------------------------------------------------------------
sub TM_CountExactItemsInList
namespace push
namespace local TM_window_list_ , %1
set !temp_LPC #LPC
set #LPC 1000
set !listname %1
set !item %2
set !count 0
for !i 0 !list_ptr
{
if !list . !i = !item
set !count !count + 1
}
set #RESULT !count
set #LPC !temp_LPC
namespace pop
return #RESULT
;-----------------------------------------------------------------
sub TM_CountItemsInList
namespace push
namespace local TM_window_list_ , %1
set !temp_LPC #LPC
set #LPC 1000
set !listname %1
set !item %2
set !count 0
for !i 0 !list_ptr
{
if !item in !list . !i
set !count !count + 1
}
set #RESULT !count
set #LPC !temp_LPC
namespace pop
return #RESULT
;-----------------------------------------------------------------
sub TM_AlphabetizeList
namespace push
namespace local TM_window_list_ , %1
set !temp_LPC #LPC
set !eval %2
set #LPC 1000
set !listname %1
if !list_ptr < 2
goto AlphabetizeList_skip
set !end !list_ptr - 1
for !i 0 !end
{
set !next !i + 1
if !i = !end
break
for !j !next !end
{
set !iptr 0
str len !list . !i
set !ilen #STRRES
set !jptr 0
str len !list . !j
set !jlen #STRRES
set !len !ilen
if !ilen > !jlen
set !len !jlen
for !p 1 !len
{
str mid !list . !i !p 1
gosub TM_EvaluateCharacter #STRRES
set !c1 #RESULT
str mid !list . !j !p 1
gosub TM_EvaluateCharacter #STRRES
set !c2 #RESULT
if !c1 = !c2
continue
if !c1 !eval !c2
{
set !temp !list . !i
set !list . !i !list . !j
set !list . !j !temp
}
break
}
}
}
AlphabetizeList_skip:
set #LPC !temp_LPC
namespace pop
return #RESULT
;-----------------------------------------------------------------
sub TM_EvaluateCharacter
namespace push
namespace local EVAL
set !char %1
set !string ! , "#$%&'()*+,- , #DOT , /0123456789: , #SMC , <=>?@[\]^_`abcdefghijklmnopqrstuvwxyz{|}~
str pos !string !char
namespace pop
return #STRRES
;================================ File System ==================================
;-------------------------------------------------------------------------------
; %1 - Name of file handle name to create
sub TM_FileSystem_CreateFileHandle
namespace push
namespace local TM_FileSystem
set !ptr %1 , _ptr ; {userhandle}_ptr
set ! . !ptr 0 ; !{userhandle}_ptr (actual pointer)
set !handle ! . !ptr
set !handle %1 , !handle
set ! . !handle ; assume new variable
namespace pop
set !TM_Function_found #TRUE
return
;-------------------------------------------------------------------------------
; %1 = namespace location (local, global)
; %2 = namespace name
; %3 = file handle name
; %4 = variable name
sub TM_FileSystem_SaveVariable
namespace push
namespace local TM_FileSystem
set !ns_loc %1
set !ns_name %2
set !handle %3
set !var %4
set !sep
set !temp_LPC #LPC
set #LPC 1000
if !handle = handle
set !handle __ , handle
set !ptr !handle , _ptr ; {userhandle}_ptr
set !handle_copy !handle
if ! . !ptr = N/A
{
set ! . !ptr 0 ; !{userhandle}_ptr (actual pointer)
set !handle_copy ! . !ptr
set !handle_copy !handle , !handle_copy
set ! . !handle_copy ; assume new variable
}
set !handle_copy ! . !ptr
set !handle_copy !handle , !handle_copy
if !ns_loc = local && !ns_name = std
set !value % . !var
else
{
namespace copy !var from !ns_loc !ns_name
set !value ! . !var
}
gosub AddUnderscore !value ; must not have spaces in stored variables!!!
set ! . !handle_copy ! . !handle_copy , !ns_loc , !sep , !ns_name , !sep , !var , !sep , #RESULT , !sep
str len ! . !handle_copy
if #STRRES > 2000
{
set !len #STRRES
str left ! . !handle_copy 2000
set !temp #STRRES
str del ! . !handle_copy 1 2000
set ! . !handle_copy !temp
set ! . !ptr ! . !ptr + 1
set !handle_copy ! . !ptr
set !handle_copy !handle , !handle_copy
set ! . !handle_copy #STRRES
}
set !value
set !temp
set #LPC !temp_LPC
namespace pop
set !TM_Function_found #TRUE
return
;-------------------------------------------------------------------------------
; %1 = namespace location (local, global)
; %2 = namespace name
; %3 = file handle name
; %4 = array name
; %5 = starting index
; %6 = ending index
sub TM_FileSystem_SaveArray
namespace push
namespace local TM_FileSystem
set !temp_LPC #LPC
set #LPC 10000
set !ns_loc %1
set !ns_name %2
set !handle %3
set !var %4
set !start_index %5
set !end_index %6
set !sep
if !handle = handle
set !handle __ , handle
set !ptr !handle , _ptr ; {userhandle}_ptr
set !handle_copy !handle
if ! . !ptr = N/A
{
set ! . !ptr 0 ; !{userhandle}_ptr (actual pointer)
set !handle_copy ! . !ptr
set !handle_copy !handle , !handle_copy
set ! . !handle_copy ; assume new variable
}
set !handle_copy ! . !ptr
set !handle_copy !handle , !handle_copy
for !i !start_index !end_index
{
if !ns_loc = local && !ns_name = std
{
set !newvar !var , !i
set !value % . !newvar
}
else
{
set !newvar !var , !i
namespace copy !newvar from !ns_loc !ns_name
set !value ! . !newvar
}
gosub AddUnderscore !value ; must not have spaces in stored variables!!!
set ! . !handle_copy ! . !handle_copy , !ns_loc , !sep , !ns_name , !sep , !newvar , !sep , #RESULT , !sep
str len ! . !handle_copy
if #STRRES > 2000
{
set !len #STRRES
str left ! . !handle_copy 2000
set !temp #STRRES
str del ! . !handle_copy 1 2000
set ! . !handle_copy !temp
set ! . !ptr ! . !ptr + 1
set !handle_copy ! . !ptr
set !handle_copy !handle , !handle_copy
set ! . !handle_copy #STRRES
}
}
set !value
set !temp
set #LPC !temp_LPC
namespace pop
set !TM_Function_found #TRUE
return
;-------------------------------------------------------------------------------
; %1 = file handle name
; %2 = file name
sub TM_FileSystem_SaveFile
namespace push
namespace local TM_FileSystem
set !temp_LPC #LPC
set #LPC 10000
set !LINE_LENGTH 2000 ; near DOS maximum
set !handle %1
set !filename %2
if !handle = handle
set !handle __ , handle
set !ptr !handle , _ptr ; {userhandle}_ptr
for !i 0 ! . !ptr
{
set !handle_copy !handle , !i
set !str ! . !handle_copy
if !i = 0
execute cmd.exe /c echo set , #spc , ! , fileout , !i , #spc , !str > !filename
else
execute cmd.exe /c echo set , #spc , ! , fileout , !i , #spc , !str >> !filename
}
set #LPC !temp_LPC
namespace pop
set !TM_Function_found #TRUE
return
;-------------------------------------------------------------------------------
; %1 - file line variable
sub TM_ReadVariables
set !temp %1
set !fileoutindex 0
set !fileout !fileout0
TM_ReadVariables_loop1:
gosub ReadItem ns_loc
if #RESULT = #TRUE
goto TM_ReadVariables_skip1
gosub ReadItem ns_name
if #RESULT = #TRUE
goto TM_ReadVariables_skip1
gosub ReadItem var
if #RESULT = #TRUE
goto TM_ReadVariables_skip1
gosub ReadItem value
if #RESULT = #TRUE
goto TM_ReadVariables_skip1
if !ns_loc in local_LOCAL && !ns_name in std_STD
set % . !var !value
else
{
set ! . !var !value
namespace copy !var to !ns_loc !ns_name
}
goto TM_ReadVariables_loop1
TM_ReadVariables_skip1:
return
;-------------------------------------------------------------------------------
; Passes %fileout(n) as local, #RESULT
sub ReadItem
str pos !fileout
if #STRRES = 0
{
set !fileoutindex !fileoutindex + 1
if !fileout . !fileoutindex <> N/A
{
set !fileout !fileout , !fileout . !fileoutindex
str pos !fileout
}
else
{
return #TRUE
}
}
set !len #STRRES - 1
str left !fileout !len
set ! . %1 #STRRES
set !len !len + 1
str del !fileout 1 !len
set !fileout #STRRES
return #FALSE
;-------------------------------------------------------------------------------
; %2 - file name
sub TM_FileSystem_LoadFile
namespace push
namespace local TM_FileSystem
set !lpc #LPC
set #LPC 10000
set !filename %1
for !i 0 1000
set !fileout . !i N/A
call !filename
if !fileout0 = N/A
{
set #LPC !lpc
namespace pop
set !TM_Function_found #TRUE
return #TRUE ; error
}
set !index 0
gosub TM_ReadVariables ; assumes namespace TM_FileSystem
set #LPC !lpc
namespace pop
set !TM_Function_found #TRUE
return #FALSE
;-------------------------------------------------------------------------------
; %1 - string to mung
sub AddUnderscore
namespace push
namespace local AU
set !tempstring %1
AddUnderscore_loop1:
str pos !tempstring #SPC
if #STRRES <> 0
{
set !val #STRRES - 1
str left !tempstring !val
set !left #STRRES
set !val !val + 1
str del !tempstring 1 !val
set !tempstring !left , _ , #STRRES
goto AddUnderscore_loop1
}
set #RESULT !tempstring
namespace pop
return #RESULT
;-------------------------------------------------------------------------------
; %1 - string to mung
sub AddSpace
namespace push
namespace local AS
set !tempstring %1
AddSpace_loop1:
str pos !tempstring _
if #STRRES <> 0
{
set !val #STRRES - 1
str left !tempstring !val
set !left #STRRES
set !val !val + 1
str del !tempstring 1 !val
set !tempstring !left , #SPC , #STRRES
goto AddSpace_loop1
}
set #RESULT !tempstring
namespace pop
return #RESULT
; For test code:
;-----------------------------------------------------------------