GUI checkbox issue Topic is solved

Get help with using AutoHotkey and its commands and hotkeys
duzymichu

GUI checkbox issue  Topic is solved

31 Mar 2017, 04:35

Hi

This is my first post. I'm a complete newbie and the script below was born out of smartgui, guide reading, trial and error. My issue is that only yesterday the script worked flawlessly. When I checked or unchecked the boxes I was given the right output after pasting it from clipboard. Today I decided to distribute the script among my colleagues and bam... Upon starting it kind of chooses randomly whether to take the checkboxes into account or not. Any help will be greatly appreciated.

Code: Select all

; SU Quickpaste

Gui,+AlwaysOnTop
gui, font, s10, Verdana
Gui, Add, Tab2, x42 y20 w390 h310 , SC created | Chasing | PO created
Gui, Add, Edit, vPR x232 y100 w160 h30
Gui, Add, Edit, vSC x232 y170 w160 h30
Gui, Add, Text, x92 y100 w110 h30 , Purchase Request
Gui, Add, Text, x92 y170 w110 h30 , Shopping Cart
Gui, Add, CheckBox, Checked x262 y230 w130 h40 vnotification, PO notification
Gui, Add, Button, default gOk x182 y280 w90 h30 , OK

Gui, Tab, 2
Gui, Add, Text, x142 y150 w90 h30 , Shopping Cart
Gui, Add, Edit, vSC2 x252 y150 w120 h30 
Gui, Add, CheckBox, x302 y240 w100 h30 vUrgent, Urgent
Gui, Add, Button, default gOk2 x182 y280 w90 h30 , OK

Gui, Tab, 3
Gui, Add, Text, x92 y100 w100 h30 , Purchase Request
Gui, Add, Text, x92 y170 w100 h30 , Purchase Order
Gui, Add, Edit, vPR2 x232 y100 w150 h30
Gui, Add, Edit, vPO x232 y170 w150 h30
Gui, Add, CheckBox, Checked x272 y240 w100 h30 vGRN, GRN notification
Gui, Add, Button, default gOk3 x182 y280 w90 h30 , OK


Gui, Show, x226 y116 h383 w483, SU Quickpaste
Return

ok:

{
Gui, submit, 

	clipboard = text (%PR%) text %SC% 
        

if notification = 1
	clipboard = 
	clipboard = some other text (%PR%) some other text %SC%.some other text.

GuiControl,,PR,
GuiControl,,SC,
Gui Minimize

		
}
return



ok2:

{
Gui, submit, 
	clipboard = text %SC2% text.


if Urgent = 1
	clipboard = 
	clipboard = some other text %SC2% some other text.			

GuiControl,,SC2,
Gui Minimize
	
} 
return


ok3:

{
Gui, submit, 

	clipboard = text (%PR2%) text %PO%. 


if GRN = 1
	clipboard = 
	clipboard = some other text (%PR2%) some other text.		

GuiControl,,PR2,
GuiControl,,PO,
Gui Minimize

} 
return


GuiClose:
ExitApp
GuiEscape:
ExitApp


User avatar
evilC
Posts: 4765
Joined: 27 Feb 2014, 12:30

Re: GUI checkbox issue

31 Mar 2017, 11:03

Code: Select all

if notification = 1
	clipboard = 
	clipboard = some other text (%PR%) some other text %SC%.some other text.	; ALWAYS RUNS, REGARDLESS OF VALUE OF notification
Your IF block does not have braces, so the 2nd clipboard = line is NOT part of the if statement and so always runs, regardless of the value of notification.

When an IF block has no {braces}, only the VERY NEXT LINE is part of the IF block

Code: Select all

if notification = 1 {
	clipboard = 
	clipboard = some other text (%PR%) some other text %SC%.some other text.
}
lexikos
Posts: 6680
Joined: 30 Sep 2013, 04:07
GitHub: Lexikos

Re: GUI checkbox issue

31 Mar 2017, 17:03

evilC wrote:if notification = 1 {
... is equivalent to if (notification = "1 {"), so the script will fail to load with an Unexpected "}" error.

Code: Select all

if (notification = 1) {
	clipboard = 
	clipboard = some other text (%PR%) some other text %SC%.some other text.
}

Code: Select all

if notification = 1
{
	clipboard = 
	clipboard = some other text (%PR%) some other text %SC%.some other text.
}
I don't believe there is any purpose in clearing the clipboard and then immediately assigning something to it. AutoHotkey always clears the clipboard prior to storing a new value, so in the above cases the clipboard is cleared twice, and then a value is stored.

Code: Select all

if notification = 1
	clipboard = some other text (%PR%) some other text %SC%.some other text.
User avatar
evilC
Posts: 4765
Joined: 27 Feb 2014, 12:30

Re: GUI checkbox issue

31 Mar 2017, 17:08

arg, caught out by trying not to change the OPs syntax too much ;)
Personally, I ALWAYS use brackets with my if statements, I even hate using just plain = instead of ==, I only use it when I need to do a case-insensitive string compare.
I find if(notification == 1){ to be way less ambiguous... Hell, in this instance, I wouldn't even do that, I would do if (notification){
duzymichal
Posts: 16
Joined: 31 Mar 2017, 04:11

Re: GUI checkbox issue

01 Apr 2017, 13:50

My apologies. When I registered to this forum I didn't notice that it logged me out before posting, thus posting as guest. I though my query was lost in moderation so I posted my question again in https://autohotkey.com/boards/viewtopic ... 81#p140481 where it was pointed out to me that you have already answered my question. Thank you very much for your responses.

Return to “Ask For Help”

Who is online

Users browsing this forum: No registered users and 262 guests