In the below code, a string is passed to the function at the bottom. The message box at line 204 tells me that the sting (stored in %MyEntry%) is indeed there. But down at line 244, the variable seems to be empty. I've also confirmed that it is empty at the bottom of the function. Of course, nothing is returned from the function.
The only thing I can think of, is that the Return at line 239 is purging the variable.... (?)
Any ideas how I can fix this?
Spoiler
Not working code....
Code: Select all
#NoEnv
#SingleInstance Force
SetTitleMatchMode, 2
SetWorkingDir %A_ScriptDir%
SetBatchLines -1
!+a:: ;Alt+Shift+w but gets called from master script.
WinGetActiveTitle, myWinTarget ; Get name of active Window so we can wait for it later.
WinGetPos, X, Y, W, H, A ; "A" to get the active window's pos.
X := X + (W * 0.05) ; Use these with GUI Show, below.
Y := Y + (H * 0.2)
;Menu, Tray, Icon, Swiss-knife.ico
Gui, Destroy
Gui, -MinimizeBox +alwaysOnTop
Gui, Font, s10
Gui, Add, Edit, x14 y8 w220 h25 vStudentName, Student ; Box to type in name.
Gui, Add, Radio, xs y40 w80 h20 vGender checked, &Male ; Radio group for gender.
Gui, Add, Radio, xp+80 y42 w80 h20 , &Female
Gui, Add, Radio, xp+80 y42 w80 h20 , &Neutral
;Gui, Font, s8
;Gui Add, Text, x257 y6 w123 h120 +wrap cGray, [n] = name`n[y] = He She They`n[m] = Him Her Them`n[r] = His Her Their`n[s] = His Hers Theirs
;Gui, Font, s10
Gui Add, Tab3, x12 y64 vCurrTab, Notices|Tests
Gui Tab, 1 ;====Notices==========================================================
IniRead, AllSchools, SchoolList.ini ; Gets `n-delimited list from ini file.
AllSchools := StrReplace(AllSchools,"`n","|",SchRows) ; Must|convert|to|this.
SchRows++ ; The number of strReplacements +1
Gui, Add, ListBox, r%SchRows% w330 vSchChoice Choose1, %AllSchools%
global AllSections := ""
IniRead, AllSections, NoticeDefinitions.ini
AllNotices := ""
Loop, Parse, AllSections, `n, `r
If !RegExMatch(A_LoopField, "\Q-Options\E") ; Exclude ini sections with -Options at the end.
AllNotices .= A_LoopField "`n"
global NoteChoice := ""
AllNotices := StrReplace(AllNotices,"`n","|",NoteRows)
NoteRows++
;Gui, Add, ListBox, r%NoteRows% w330 sort vNoteChoice gDblClick, %AllNotices%
Gui, Add, ListBox, r%NoteRows% w330 vNoteChoice gDblClick, %AllNotices% ; Removed sort
Gui, Add, Button, w65 h30 Section, Insert
Gui, Add, Button, ys x+5 w60 h30, Schools
Gui, Add, Button, ys x+5 w60 h30, Notices
Gui, Add, Button, ys x+5 w60 h30, Esc
Gui Tab, 2 ;====Tests======================================================
IniRead, MySuffixes, TestSuffixes.ini
MySuffixes := StrReplace(MySuffixes,"`n","|")
Gui, Add, ComboBox, w330 vSuffChoice Choose1, %MySuffixes%
IniRead, AllTests, TestBank.ini
AllTests := StrReplace(AllTests,"`n","|",TestRows)
TestRows++
Gui, Add, ListBox, r%TestRows% w330 sort vTestChoice gDblClick, %AllTests%
Gui, Add, Button, w65 h30 Section, Insert
Gui, Add, Button, ys x+5 w60 h30, Suffix
Gui, Add, Button, ys x+5 w60 h30, Tests
Gui, Add, Button, ys x+5 w60 h30, Esc
Gui Tab ;=====End of Tabs================================================
Gui Show, x%X% y%Y%, MultiTool 2.0 v5-5-2021
Return
ButtonEsc:
GuiEscape:
GuiClose:
ExitApp
DblClick:
IfNotEqual A_GuiControlEvent,DoubleClick
Return
Else
ButtonInsert:
Gui, Submit
IfEqual, CurrTab, Notices ; Checks which tab is being used.
{
IniRead, MyEntry, NoticeDefinitions.ini, %NoteChoice% ; From notice type, goes back to INI, gets notice content.
}
IfEqual, CurrTab, Tests
{
IniRead, MyEntry, TestBank.ini, %TestChoice%,
ifNotEqual, SuffChoice, ; Only gets Suffix Description if comboBox is not empty.
IniRead, MySuffDesc, TestSuffixes.ini, %SuffChoice%
MyEntry := StrReplace(MyEntry,"[sd]",MySuffDesc)
MyEntry := StrReplace(MyEntry,"[sf]",SuffChoice A_Space)
}
;======== check for options ========================================================
If InStr(MyEntry, "<Options>") ; Options tag found in expansion text.
{
;MsgBox right before function, myEntry is: %MyEntry%
MyEntry := myOptionsFunc(MyEntry)
;MsgBox right after function, myEntry is: %MyEntry%
}
;=======end of options==========
IniRead, MyContactInfo, SchoolList.ini, %SchChoice%, ContactInfo ; From school choice, gets contact info.
IniRead, MySchPhone, SchoolList.ini, %SchChoice%, SchPhone
MyEntry := StrReplace(MyEntry,"[c]",MyContactInfo)
MyEntry := StrReplace(MyEntry,"[p]",MySchPhone)
IfEqual, Gender, 1 ; Checks the results of the gender radio buttons group and assigns variables.
{
varHeShe = he
varHimHer = him
varHisHer = his
varHisHers = his
}
IfEqual, Gender, 2
{
varHeShe = she
varHimHer = her
varHisHer = her
varHisHers = hers
}
IfEqual, Gender, 3
{
varHeShe = they
varHimHer = them
varHisHer = their
varHisHers = theirs
}
MyEntry := StrReplace(MyEntry,"[n]",StudentName) ; Makes the replacements.
MyEntry := StrReplace(MyEntry,"[y]",varHeShe) ; Gender pronouns.
MyEntry := StrReplace(MyEntry,"[m]",varHimHer)
MyEntry := StrReplace(MyEntry,"[r]",varHisHer)
MyEntry := StrReplace(MyEntry,"[s]",varHisHers)
MyEntry := StrReplace(MyEntry,"!","{!}") ; These special characters need {braces} to type correctly.
MyEntry := StrReplace(MyEntry,"#","{#}")
MyEntry := StrReplace(MyEntry,"+","{+}")
IfEqual, Gender, 3
{
MyEntry := StrReplace(MyEntry,"they is","they are") ; Fix gramar is gender neutral.
MyEntry := StrReplace(MyEntry,"they has","they have")
}
MyEntry := RegExReplace(MyEntry, "^\w|(?:\.|:)\s+\K\w", "$U0") ; Makes sure most sentences are capitalized.
IfEqual, CurrTab, Notices
{
MyEntry =`n%MyEntry% ; Adds an new-line at beginning so below regex will work.
MyEntry := RegExReplace(MyEntry,"(\n)+[ a-zA-Z0-9]+=") ; Removes all Key names from notice definitions.
;CulledEntry := RegExReplace(MyEntry,"(\n)+[ a-zA-Z0-9,/&+.\-#]+=") ; Removes all Key names. Added special chars 9-2-18.
StringReplace, MyEntry, MyEntry,`n, , All ; Gets rid of any leftover <Enter>s.
}
gui, Hide
winwaitactive, %myWinTarget% ; Wait for the previously active Window.
SendEvent %MyEntry% ; Types notice or test into text field(s)
;========= Notes about SEND modes ============
;SendInput is faster but you can't see progress of typing.
;Send is the same as SendEvent. It is more visual but prone to errors.
;SendPlay doesn't seem to work... Maybe because UAC is active.
ExitApp
;========= Other Buttons go to here if clicked ===============
; The excellent opensource and free Notepad3 from: https://www.rizonesoft.com/documents/notepad3/
ButtonSchools:
run, %A_ScriptDir%\Notepad3\Notepad3.exe "%A_ScriptDir%\SchoolList.ini",, UseErrorLevel
If ErrorLevel
run, SchoolList.ini ; If Notepad3 is not found, will be prompted to choose default ini opener.
return
ButtonNotices:
run, %A_ScriptDir%\Notepad3\Notepad3.exe "%A_ScriptDir%\NoticeDefinitions.ini",, UseErrorLevel
If ErrorLevel
Run, NoticeDefinitions.ini
return
ButtonSuffix:
run, %A_ScriptDir%\Notepad3\Notepad3.exe "%A_ScriptDir%\TestSuffixes.ini",, UseErrorLevel
If ErrorLevel
run, TestSuffixes.ini
return
ButtonTests:
run, %A_ScriptDir%\Notepad3\Notepad3.exe "%A_ScriptDir%\TestBank.ini",, UseErrorLevel
If ErrorLevel
run, TestBank.ini
return
;@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
myOptionsFunc(MyEntry){
global
MsgBox top of function myEntry is:`n`n %MyEntry% ; ### Variable contains string here (as expected) ###
OptSection := ""
Loop, Parse, AllSections, `n, `r
If RegExMatch(A_LoopField, NoteChoice . "-Opt")
OptSection .= A_LoopField
If RegExMatch(OptSection, "-Pun")
vPun = 1
IniRead, AllOptions, NoticeDefinitions.ini, %OptSection% ; must get list of keys ;var,file,sect
vCount=
myOptions=
Gui, +Owner
Gui, o:Destroy
Gui, o:-MinimizeBox +alwaysOnTop
Gui, o:Add, Text,, Select one or more options:
Loop, Parse, AllOptions, `n,`r ; Parses list.
{
fchar := SubStr(A_LoopField, 1, 1)
If fchar is Number
{
item := SubStr(A_LoopField, 3, 99)
}
else
{
item := A_LoopField
}
;MsgBox, fchar: %fchar%`nitem : %item%
Gui, o:Add, CheckBox, Checked%fchar% vCheckbox%a_index%, %item% ;Dynamically make one checkbox per item.
;vCount = %a_index%
}
Gui, o:Add, Button, default xm w50 gMyOpts, Use
;Gui, o:Add, Button, yp x+5 w50 gCancelOpts, Cancel
Gui, o:Show,x%X% y%Y% , Option Items
Return
MyOpts: ; Go here when user clicks Okay button.
Gui, o:Submit
MsgBox after submit myEntry is`n`n %MyEntry% ; ### Variable No Longer contains string :- / ###
vCount=
Loop, parse, AllOptions, `n
{
fchar := SubStr(A_LoopField, 1, 1)
If Checkbox%a_index% <> 0
{
If fchar is Number
{
item := SubStr(A_LoopField , 3, 9999)
}
else
{
item := A_LoopField
}
IfEqual, vPun, 1
{
myOptions = %myOptions%, %item%
}
else
{
myOptions = %myOptions% %item%
}
vCount++
}
}
IfEqual, vPun, 1
{
myOptions := SubStr(myOptions, 3, 999999)
IfEqual, vCount, 2
myOptions := StrReplace(myOptions,", " . item," and " . item)
myOptions := StrReplace(myOptions,", " . item,", and " . item)
}
;MsgBox bottom of function. myEntry %MyEntry%,`n`n myOptions %myOptions%
myEntry := StrReplace(MyEntry,"<Options>",myOptions) ; Replace Options tag with checked items.
Return myEntry
;CancelOpts:
;ExitApp
}