Posts: 62
Threads: 22
Joined: Jul 2017
11-17-2022, 01:17 PM
(This post was last modified: 11-17-2022, 01:51 PM by ScottF.
Edit Reason: Added text.
)
Hey everyone, hoping for some help on this one, searched but can't find...
From the list below, I need to get all the lines that contain ##x and put them all in a Dropdown or a Listbox for the user to choose from.
----------
Start
##2
folder#1
folder#2
EndOfList
##3
folder#3
folder#4
EndOfList
##4
folder#5
EndOfList
----------
So the listbox will have... This is what user chooses from.
##2
##3
##4
etc.
If the user chooses ##3 for example, then need to get all of group ##3 to EndOfList in bold above.
I hope I explained this properly. Thanks ahead for any help!
ScottF
Posts: 1,336
Threads: 61
Joined: Jul 2006
11-17-2022, 07:17 PM
(This post was last modified: 11-17-2022, 07:25 PM by Kevin.)
this may be more than you wanted but try this
dialog with 2 list boxes
list 1 is populated at run time
list 2 is populated on selection of list 1 item
on double left click of list2 item closes dialog and outputs selected list 2 item
Function Dialog2LBExample
str li=
;Start
;
;##2
;folder#1
;folder#2
;EndOfList
;
;##3
;folder#3
;folder#4
;EndOfList
;
;##4
;folder#5
;EndOfList
str list1 lb1text lb2text s
int lb1h lb2h
ARRAY(str) a b
findrx(li "\#\#\d*" 0 4 a)
for _i 0 a.len
,list1.addline(a[0 _i].trim 1)
str dd=
;BEGIN DIALOG
;0 "" 0x90C80AC8 0x0 0 0 224 136 "Dialog" "4"
;3 ListBox 0x54230101 0x200 0 16 96 96 ""
;4 ListBox 0x54230101 0x200 120 16 96 96 ""
;1 Button 0x54030001 0x4 116 116 48 14 "OK"
;2 Button 0x54030000 0x4 168 116 48 14 "Cancel"
;END DIALOG
;DIALOG EDITOR: "" 0x2040C00 "*" "" "" ""
str controls = "3 4"
str lb3 lb4
lb3=list1
if(!ShowDialog(dd &sub.DlgProc &controls)) ret
;lb4.replacerx("\d+ " "")
;out lb4
out lb2text
#sub DlgProc v
function# hDlg message wParam lParam
sel message
,case WM_INITDIALOG
,lb1h=id(3 hDlg)
,lb2h=id(4 hDlg)
,case WM_DESTROY
,case WM_COMMAND goto messages2
ret
;messages2
sel wParam
,case IDOK
,case IDCANCEL
,case LBN_SELCHANGE<<16|3
,_i=LB_SelectedItem(lParam lb1text)
,if(_i=-1) ret
,str pattern=F"(?s){lb1text}(.+?)EndOfList"
,SendMessage(lb2h LB_RESETCONTENT 0 0)
,findrx(li pattern 0 4 b 1)
,_s=b; _s.trim
,foreach s _s
,,LB_Add(lb2h s)
,case LBN_DBLCLK<<16|4
,_i=LB_SelectedItem(lParam lb2text)
,if(_i=-1) ret
,DT_Ok(hDlg)
ret 1
Posts: 62
Threads: 22
Joined: Jul 2017
11-17-2022, 09:44 PM
(This post was last modified: 11-17-2022, 09:48 PM by ScottF.
Edit Reason: Added text.
)
Hey Kevin,
I almost never use findrx, I need to practice using it.
One thing I was hoping to do is if the user chose say ##3
it needs to assign each line of that group to separate variables.
Then the rest of the program will process them one line at a time until
it reaches EndOfList. so in this case 2 strings: 1 for folder#3 and 1 for folder#4
Oh yeah I have a problem understanding ARRAYs and for loops.
Anyways this is good for me to study. Thank you!
I wrote the following code to help myself understand the for loop a couple years ago and
I think I made it more confusing.
Function Example___ForLoop_w_break
/ Example___ForLoop_w_break \
;; :::::::::::::::::::::::::::::::::::::::::::::
;; 2020-10-13 Tuesday - 19.56.35
;;;;© Scott_F †††
;;;
;;;;Description of Function:
;,--> Example of basic for loop with break.
;,Clears output box first thing.
;,Syntax:
;;,for i (counter) 0 ( initvalue) j (finalvalue )
SetEndThreadHotkey "F12" ;; «--‹‹ ≡KILL SWITCH≡ --- Change to any "Fxx" Function Key. Terminates this function.
str func = "Example___ForLoop_w_break" ;; <-----Change to Function name.
;out ;; Clear Output
;olm ;; Log and Clear Output
;; start
str sDataWithDollarSigns = "$82,590 $273,860 $356,450 $296,120 "
sDataWithDollarSigns + "*" ;; add stop marker to end of string. (*)
int iDollarPosCount jDataLenth iDollarCount iTotalCharCount
;;; countit
out "[]%s.[][]" func
jDataLenth = len(sDataWithDollarSigns) ;; $82,590 $273,860 $356,450 $296,120 *
for iDollarPosCount 0 jDataLenth ;; give me char num of every found $, starting at zero, through whole length of string.
,iTotalCharCount + 1 ;; count each character in the loop, up to my stop marker (not inclusive).
,if sDataWithDollarSigns[iDollarPosCount] = '$' ;; if in sDataWithDollarSigns, a dollar sign is found, then...
,,out iDollarPosCount ;; output position of each found $.
,,iDollarCount + 1 ;; total number of $ found.
,,if sDataWithDollarSigns[iDollarPosCount] = '*' ;; if the stop marker is found in the search, then...
,,,break ;; when stop is found.
out "_______[][]%i dollar signs found.[]" iDollarCount
out "Total Number of characters: %i[]" iTotalCharCount
str op =
;out "[]For Loop example with break.[][]"
;jDataLenth = len(sDataWithDollarSigns) ;; $82,590 $273,860 $356,450 $296,120 *
;for iDollarPosCount 0 jDataLenth ;; give me char num of every found $, starting at zero, through whole length of string.
;,iTotalCharCount + 1 ;; count each character in the loop, up to my stop marker (not inclusive).
;,;if s[iDollarPosCount] = '$' ;; if in sDataWithDollarSigns, a dollar sign is found, then...
;,,;out iDollarPosCount ;; output position of each found $.
;,,;iDollarCount + 1 ;; total number of $ found.
;,,;if s[iDollarPosCount] = '*' ;; if the stop marker is found in the search, then...
;,,,;break ;; when stop is found.
out op
;; bottom
;;; Basic Example:
;lpstr s = "abcd.ef"
;int i
;int j = len(s)
;for i 0 j
,;out i
,;if s[i] = '.'
,,;break
|