CuppaJoe
CuppaJoe

Reputation: 1

AHK GUI IF statement needed

Created an AHK Calculator GUI that when you select copy it will copy all information to paste. I would like to edit the script to not copy a section if that section is blank. GUI is set up for 3 levels but sometimes I only use 1 or 2 levels and with current script I have to delete the empty text after pasting. I would like to only copy the levels filled in. Below is the code for just the copy section of the GUI. Also attached photo example of what it currently looks like when I paste with current script (left notepad) and what I would hopefully like it to look (right notepad). Any help would be greatly appreciated. Thanks.

Photo Example

Copy:
CopyQC =
(
QC Level 1:
    Result: %Result1%
    Lab Range: %LRange1%
    Peer Mean: %PeerMean1%
    Peer SD: %PeerSD1%
    Peer Range: %1Low% - %1High%
    Result SDs: %Result1SD%
QC Level 2:
    Result: %Result2%
    Lab Range: %LRange2%
    Peer Mean: %PeerMean2%
    Peer SD: %PeerSD2%
    Peer Range: %2Low% - %2High%
    Result SDs: %Result2SD%
QC Level 3:
    Result: %Result3%
    Lab Range: %LRange3%
    Peer Mean: %PeerMean3%
    Peer SD: %PeerSD3%
    Peer Range: %3Low% - %3High%
    Result SDs: %Result3SD%
)
Gui, 6: Add, Edit, vCopy, %CopyQC%
Gui, 6: Show
Send, ^c
Gui, 6: Destroy
return

Not to knowledgeable with IF statements or if that would be best scenario here.

Upvotes: 0

Views: 57

Answers (1)

Mister Robato
Mister Robato

Reputation: 196

Here, comments are added on end of lines with ; for explanation:

  1. Initialize CopyQC to empty string.
  2. Add 3 IF statements, each checks if Result# is not empty.
  3. If the Result# is not empty, concatenate the results to CopyQC variable.
  4. StringTrimRight removes the last new line.
CopyQC := ""  ; Init CopyQC
If (Result1)  ; IF Result1 NOT Empty
{
    CopyQC .= 
    (LTrim
    "QC Level 1:
        Result: " Result1 "
        Lab Range: " LRange1 "
        Peer Mean: " PeerMean1 "
        Peer SD: " PeerSD1 "
        Peer Range: " 1Low " - " 1High "
        Result SDs: " Result1SD "
    "
    )  ; Concatenate QC1 To CopyQC
}
If (Result2)  ; IF Result2 NOT Empty
{
    CopyQC .= 
    (LTrim
    "QC Level 2:
        Result: " Result2 "
        Lab Range: " LRange2 "
        Peer Mean: " PeerMean2 "
        Peer SD: " PeerSD2 "
        Peer Range: " 2Low " - " 2High "
        Result SDs: " Result2SD "
    "
    )  ; Concatenate QC2 To CopyQC
}
If (Result3)  ; IF Result3 NOT Empty
{
    CopyQC .= 
    (LTrim
    "QC Level 3:
        Result: " Result3 "
        Lab Range: " LRange3 "
        Peer Mean: " PeerMean3 "
        Peer SD: " PeerSD3 "
        Peer Range: " 3Low " - " 3High "
        Result SDs: " Result3SD "
    "
    )  ; Concatenate QC3 To CopyQC
}
StringTrimRight, CopyQC, CopyQC, 1  ; Remove Last New Line

Upvotes: 0

Related Questions