Custom GUI to replace Msgbox

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Crashm87
Posts: 48
Joined: 25 Jul 2016, 13:12

Custom GUI to replace Msgbox

08 Mar 2017, 16:29

Hello,

I made a custom GUI to replace my messagebox so I could change the font, but I can't get the controls of the buttons to work the same way they do when inside a loop. My messagebox code is:

Code: Select all

	MsgBox,3, Customer Storage Information ,% "Row number: " c.row "`n"
	. "Customer Number :  " cnumber "`n"
	. "Customer Name :    " cname "`n"
	. "Tire Size :        " tiresize "`n"
	. "Brand :            " brand "`n" ;" " rims "`n"
	. "VIN :              " vin "`n"
	IfMsgBox Cancel
{
	ExitApp
}
IfMsgBox Yes
{
	Break
}
IfMsgBox No
{
	c :=	myRng.FindNext(c)
	continue
}
When I press NO, it loops back through an excel spreadsheet and finds the next instance in the database.

I made this GUI:

Code: Select all

	Gui, font
	Gui, Add, Button, x27 y149 w88 h26 gyes, &Yes
	Gui, Add, Button, x123 y149 w88 h26 gno, &No
	Gui, Add, Button, x221 y149 w88 h26 gcancel, Cancel
	Gui, Add, Text, x22 y19  h20 +Right, CUSTOMER NUMBER: %cnumber%
	Gui, Add, Text, x22 y39  h20 +Right, CUSTOMER NAME: %cname%
	Gui, Add, Text, x22 y59  h20 +Right, TIRE SIZE: %tiresize%
	Gui, Add, Text, x22 y79  h20 +Right, BRAND: %brand%
	Gui, Add, Text, x22 y99  h20 +Right, VIN: %vin%
	Gui, font, s12 +bold ;+underline
	Gui, Add, Text, x222 y29 w80 h22 +Center 0x1000, LOC 
	Gui, font, s%size%
	Gui, Add, Text, x222 y50 w80 h30 +Center 0x1000, %loc%
	; Generated using SmartGUI Creator for SciTE
	Gui, Show, w327 h185, Customer Information
	;~ return
		
	No:
	{
		c :=	myRng.FindNext(c)
		continue
	}
	
	yes:
	{
		break
	}
However, when pressing the buttons on the GUI, nothing happens.

Any idea what I'm missing?
4GForce
Posts: 553
Joined: 25 Jan 2017, 03:18
Contact:

Re: Custom GUI to replace Msgbox

08 Mar 2017, 17:55

Code: Select all

#singleinstance force

F10::
ExitApp

F9::Reload

F1::
	response := CustomMsgBox.Display()
	if(response == CustomMsgBox.Btn_Yes) {
		msgbox % "User clicked yes"
	}
	else if(response == CustomMsgBox.Btn_No) {
		msgbox % "User clicked no"
	}
Return

Class CustomMsgBox {
	static Btn_Yes := "Yes"
	static Btn_No := "No"
	static Result := ""
	
	Display() {
		CustomMsgBox.Create()
		CustomMsgBox.Result := ""
		loop
		{
			sleep 1
		} until (CustomMsgBox.Result)
		Gui CMB:Destroy
		Return CustomMsgBox.Result
	}
	
	Create() {
		Gui CMB:New
		Gui CMB:Add, Button, hwndMyButton, % CustomMsgBox.Btn_Yes
		fn := CustomMsgBox.ButtonClicked.Bind("")
		GuiControl +g, % MyButton, % fn
		Gui CMB:Add, Button, hwndMyButton, % CustomMsgBox.Btn_No
		GuiControl +g, % MyButton, % fn
		Gui CMB:Show, w200 h200
	}
	
	ButtonClicked() {
		CustomMsgBox.Result := A_GuiControl
	}	
}
Helgef
Posts: 4709
Joined: 17 Jul 2016, 01:02
Contact:

Re: Custom GUI to replace Msgbox

08 Mar 2017, 18:41

See Loop, g-label.
Try this,

Code: Select all

	Gui, font
	Gui, Add, Button, x27 y149 w88 h26 gyes, &Yes
	Gui, Add, Button, x123 y149 w88 h26 gno, &No
	Gui, Add, Button, x221 y149 w88 h26 gcancel, Cancel
	Gui, Add, Text, x22 y19  h20 +Right, CUSTOMER NUMBER: %cnumber%
	Gui, Add, Text, x22 y39  h20 +Right, CUSTOMER NAME: %cname%
	Gui, Add, Text, x22 y59  h20 +Right, TIRE SIZE: %tiresize%
	Gui, Add, Text, x22 y79  h20 +Right, BRAND: %brand%
	Gui, Add, Text, x22 y99  h20 +Right, VIN: %vin%
	Gui, font, s12 +bold ;+underline
	Gui, Add, Text, x222 y29 w80 h22 +Center 0x1000, LOC 
	Gui, font, s%size%
	Gui, Add, Text, x222 y50 w80 h30 +Center 0x1000, %loc%
	; Generated using SmartGUI Creator for SciTE
	Gui, Show, w327 h185, Customer Information
	return
		
	No:
		MsgBox, no
		c :=	myRng.FindNext(c)
	return
	
	yes:
		MsgBox, Yes
	return
Crashm87
Posts: 48
Joined: 25 Jul 2016, 13:12

Re: Custom GUI to replace Msgbox

09 Mar 2017, 08:39

Thanks for the answers.
@Helgef, that is working, it displays the messagebox, however doesn't continue looping when I press no, which I can't figure out.

@4GForce, I implemented yours into the middle of my loop, and same thing, I can get a msgbox to appear, but I can't get loop to continue when pressing No.

The loop works perfect everytime when I use a standard messagebox.
4GForce
Posts: 553
Joined: 25 Jan 2017, 03:18
Contact:

Re: Custom GUI to replace Msgbox

09 Mar 2017, 10:03

Crashm87 wrote:... but I can't get loop to continue when pressing No.
The loop works perfect everytime when I use a standard messagebox.
What loop ? I didn't see any loop ...
Crashm87
Posts: 48
Joined: 25 Jul 2016, 13:12

Re: Custom GUI to replace Msgbox

09 Mar 2017, 10:13

Sorry, here is the entire script.

Code: Select all

#SingleInstance Force



FilePath := "C:\Users\Tammy\Desktop\2016 SUMMER TIRES FINAL.xlsx"
oExcel := ComObjCreate("Excel.Application")
;~ oExcel.Workbooks.Open(FilePath)
;~ oExcel.Visible := true
oWorkbook := ComObjGet(FilePath)
dataBase := oWorkbook.WorkSheets("Sheet1")


InputBox, LookFor, Search, Enter Search Criteria
myRng := dataBase.Range["A2:A200"]


if	!c :=	myRng.Find(LookFor)
{
	MsgBox, 4, Warning, No matches found. Do you want to see database?
	IfMsgBox Yes
	{
		oExcel.Visible := true
	}
	Else
		GoTo, Cancel
	return
}

first :=	c.Address

Loop
{
	count++
	cnumber := c.value
	cname := c.offset(0,1).value
	tiresize := c.offset(0,3).value
	brand := c.offset(0,2).value
	vin := c.offset(0,6).value	
	loc := c.offset(0,7).value
	rims := c.offset(0,4).value
	cnumber := round(cnumber)
	;~ tiresize := round(tiresize)
	
	if loc is number
	{
		loc := round(loc)
		loc := "TR" . loc
		size := 20
	}
	else
	{
		size := 12
	}
	
	Gui, font
	Gui, Add, Button, x27 y149 w88 h26 gyes, &Yes
	Gui, Add, Button, x123 y149 w88 h26 gno, &No
	Gui, Add, Button, x221 y149 w88 h26 gcancel, Cancel
	Gui, Add, Text, x22 y19  h20 +Right, CUSTOMER NUMBER: %cnumber%
	Gui, Add, Text, x22 y39  h20 +Right, CUSTOMER NAME: %cname%
	Gui, Add, Text, x22 y59  h20 +Right, TIRE SIZE: %tiresize%
	Gui, Add, Text, x22 y79  h20 +Right, BRAND: %brand%
	Gui, Add, Text, x22 y99  h20 +Right, VIN: %vin%
	Gui, font, s12 +bold ;+underline
	Gui, Add, Text, x222 y29 w80 h22 +Center 0x1000, LOC 
	Gui, font, s%size%
	Gui, Add, Text, x222 y50 w80 h30 +Center 0x1000, %loc%
	; Generated using SmartGUI Creator for SciTE
	Gui, Show, w327 h185, Customer Information
	return
		
	No:
		MsgBox, no  ;testing
		c :=	myRng.FindNext(c)
		continue
	return
	
	yes:
		MsgBox, Yes  ; testing
		break
	return
	
	;~ MsgBox,3, Customer Storage Information ,% "Row number: " c.row "`n"
	;~ . "Customer Number :  " cnumber "`n"
	;~ . "Customer Name :    " cname "`n"
	;~ . "Tire Size :        " tiresize "`n"
	;~ . "Brand :            " brand "`n" ;" " rims "`n"
	;~ . "VIN :              " vin "`n"
	IfMsgBox Cancel
{
	ExitApp
}
IfMsgBox Yes
{
	Break
}
IfMsgBox No
{
	c :=	myRng.FindNext(c)
	continue
}
}	Until	(c.Address=first)
4GForce
Posts: 553
Joined: 25 Jan 2017, 03:18
Contact:

Re: Custom GUI to replace Msgbox

09 Mar 2017, 13:14

Crashm87 wrote:Sorry, here is the entire script.
Labels in a loop :sick:
Hard to fully test without the excel file but I tested the loop part and this works ...

Code: Select all

#SingleInstance Force

FilePath := "C:\Users\Tammy\Desktop\2016 SUMMER TIRES FINAL.xlsx"
oExcel := ComObjCreate("Excel.Application")
;~ oExcel.Workbooks.Open(FilePath)
;~ oExcel.Visible := true
oWorkbook := ComObjGet(FilePath)
dataBase := oWorkbook.WorkSheets("Sheet1")

InputBox, LookFor, Search, Enter Search Criteria
myRng := dataBase.Range["A2:A200"]

if	!c :=	myRng.Find(LookFor)
{
	MsgBox, 4, Warning, No matches found. Do you want to see database?
	IfMsgBox Yes
	{
		oExcel.Visible := true
	}
	Else
		ExitApp		; cancel label didn't exist ?!
	return
}

first :=	c.Address

Loop
{
	count++
	cnumber := c.value
	cname := c.offset(0,1).value
	tiresize := c.offset(0,3).value
	brand := c.offset(0,2).value
	vin := c.offset(0,6).value	
	loc := c.offset(0,7).value
	rims := c.offset(0,4).value
	cnumber := round(cnumber)
	;~ tiresize := round(tiresize)
	
	if loc is number
	{
		loc := round(loc)
		loc := "TR" . loc
		size := 20
	}
	else
	{
		size := 12
	}
	
	response := CustomMsgBox.Display()
	if(response == CustomMsgBox.Btn_Yes) {
		msgbox % "User clicked yes"
		break
	}
	else if(response == CustomMsgBox.Btn_No) {
		msgbox % "User clicked no"
		c := myRng.FindNext(c)
		continue
	}
	
} Until (c.Address=first)

Class CustomMsgBox {
	static Btn_Yes := "Yes"
	static Btn_No := "No"
	static Result := ""
	
	Display() {
		CustomMsgBox.Create()
		CustomMsgBox.Result := ""
		loop
		{
			sleep 1
		} until (CustomMsgBox.Result)
		Gui CMB:Destroy
		Return CustomMsgBox.Result
	}
	
	Create() {
		Gui CMB:New
		Gui CMB:Add, Button, hwndMyButton, % CustomMsgBox.Btn_Yes
		fn := CustomMsgBox.ButtonClicked.Bind("")
		GuiControl +g, % MyButton, % fn
		Gui CMB:Add, Button, hwndMyButton, % CustomMsgBox.Btn_No
		GuiControl +g, % MyButton, % fn
		Gui CMB:Show, w200 h200
	}
	
	ButtonClicked() {
		CustomMsgBox.Result := A_GuiControl
	}	
}
Crashm87
Posts: 48
Joined: 25 Jul 2016, 13:12

Re: Custom GUI to replace Msgbox

09 Mar 2017, 16:22

4GForce wrote:
Crashm87 wrote:Sorry, here is the entire script.
Labels in a loop :sick:
Hard to fully test without the excel file but I tested the loop part and this works ...

Code: Select all

#SingleInstance Force

FilePath := "C:\Users\Tammy\Desktop\2016 SUMMER TIRES FINAL.xlsx"
oExcel := ComObjCreate("Excel.Application")
;~ oExcel.Workbooks.Open(FilePath)
;~ oExcel.Visible := true
oWorkbook := ComObjGet(FilePath)
dataBase := oWorkbook.WorkSheets("Sheet1")

InputBox, LookFor, Search, Enter Search Criteria
myRng := dataBase.Range["A2:A200"]

if	!c :=	myRng.Find(LookFor)
{
	MsgBox, 4, Warning, No matches found. Do you want to see database?
	IfMsgBox Yes
	{
		oExcel.Visible := true
	}
	Else
		ExitApp		; cancel label didn't exist ?!
	return
}

first :=	c.Address

Loop
{
	count++
	cnumber := c.value
	cname := c.offset(0,1).value
	tiresize := c.offset(0,3).value
	brand := c.offset(0,2).value
	vin := c.offset(0,6).value	
	loc := c.offset(0,7).value
	rims := c.offset(0,4).value
	cnumber := round(cnumber)
	;~ tiresize := round(tiresize)
	
	if loc is number
	{
		loc := round(loc)
		loc := "TR" . loc
		size := 20
	}
	else
	{
		size := 12
	}
	
	response := CustomMsgBox.Display()
	if(response == CustomMsgBox.Btn_Yes) {
		msgbox % "User clicked yes"
		break
	}
	else if(response == CustomMsgBox.Btn_No) {
		msgbox % "User clicked no"
		c := myRng.FindNext(c)
		continue
	}
	
} Until (c.Address=first)

Class CustomMsgBox {
	static Btn_Yes := "Yes"
	static Btn_No := "No"
	static Result := ""
	
	Display() {
		CustomMsgBox.Create()
		CustomMsgBox.Result := ""
		loop
		{
			sleep 1
		} until (CustomMsgBox.Result)
		Gui CMB:Destroy
		Return CustomMsgBox.Result
	}
	
	Create() {
		Gui CMB:New
		Gui CMB:Add, Button, hwndMyButton, % CustomMsgBox.Btn_Yes
		fn := CustomMsgBox.ButtonClicked.Bind("")
		GuiControl +g, % MyButton, % fn
		Gui CMB:Add, Button, hwndMyButton, % CustomMsgBox.Btn_No
		GuiControl +g, % MyButton, % fn
		Gui CMB:Show, w200 h200
	}
	
	ButtonClicked() {
		CustomMsgBox.Result := A_GuiControl
	}	
}
Thanks alot. I think that is working perfect, it looks the exact amount of times my customer appears in database, so, YAY.

However, I've never seen a GUI made this way, so I am alittle confused. How do I add my information to that GUI? I tired this

Code: Select all

	Create() {
		Gui CMB:New
		Gui CMB:Add, Button, hwndMyButton, % CustomMsgBox.Btn_Yes 
		fn := CustomMsgBox.ButtonClicked.Bind("")
		GuiControl +g, % MyButton, % fn
		Gui CMB:Add, text, %cname%
		Gui CMB:Add, Button, hwndMyButton, % CustomMsgBox.Btn_No
		GuiControl +g, % MyButton, % fn
		Gui CMB:Show, w200 h200
		
and it just left a blank space between the yes and no button.

Here is a small portion of my database if that help??

https://www.dropbox.com/s/d29aqzc942v1v ... .xlsx?dl=0

Thanks for sticking with me on this one
4GForce
Posts: 553
Joined: 25 Jan 2017, 03:18
Contact:

Re: Custom GUI to replace Msgbox

09 Mar 2017, 17:24

Crashm87 wrote:However, I've never seen a GUI made this way, so I am alittle confused. How do I add my information to that GUI?
I tried to keep it simple.
I modified it a bit an commented, I did the cnumber but I was too lazy to test.
So follow the comments, you should get it. Let me know if you have questions.

Code: Select all

#SingleInstance Force

FilePath := "C:\Users\Tammy\Desktop\2016 SUMMER TIRES FINAL.xlsx"
oExcel := ComObjCreate("Excel.Application")
;~ oExcel.Workbooks.Open(FilePath)
;~ oExcel.Visible := true
oWorkbook := ComObjGet(FilePath)
dataBase := oWorkbook.WorkSheets("Sheet1")

InputBox, LookFor, Search, Enter Search Criteria
myRng := dataBase.Range["A2:A200"]

if	!c :=	myRng.Find(LookFor)
{
	MsgBox, 4, Warning, No matches found. Do you want to see database?
	IfMsgBox Yes
	{
		oExcel.Visible := true
	}
	Else
		ExitApp
	return
}

first :=	c.Address

; create the gui once then we call CustomMsgBox.Display() to update/show/hide/return result
CustomMsgBox.Create()

Loop
{
	count++
	
	; Assign the values directly to the object
	CustomMsgBox.cnumber := round(c.value)
		
	cname := c.offset(0,1).value
	tiresize := c.offset(0,3).value
	brand := c.offset(0,2).value
	vin := c.offset(0,6).value	
	loc := c.offset(0,7).value
	rims := c.offset(0,4).value
	
	;~ tiresize := round(tiresize)
	
	if loc is number
	{
		loc := round(loc)
		loc := "TR" . loc
		size := 20
	}
	else
	{
		size := 12
	}
	
	response := CustomMsgBox.Display()
	if(response == CustomMsgBox.Btn_Yes) {
		msgbox % "User clicked yes"
		break
	}
	else if(response == CustomMsgBox.Btn_No) {
		msgbox % "User clicked no"
		c := myRng.FindNext(c)
		continue
	}
	
} Until (c.Address=first)



Class CustomMsgBox {
	static Btn_Yes := "Yes"
	static Btn_No := "No"
	static Result := ""
	
	; add your variables here
	static cnumber

	; add your controls here, leave the text blank but use a V variable in the options
	Create() {
		Gui CMB:New
		Gui CMB:Margin, 25, 10
		
		; you can add stuff here
		
		fn := CustomMsgBox.ButtonClicked.Bind("")
		Gui CMB:Add, Button, hwndMyButton, % CustomMsgBox.Btn_Yes
		GuiControl +g, % MyButton, % fn
		Gui CMB:Add, Button, hwndMyButton, % CustomMsgBox.Btn_No
		GuiControl +g, % MyButton, % fn
		
		; you can add more stuff here
		Gui CMB:Add, Text, vCNumberTxt
		
	}
	
	; assign the values to the controls here so they update everytime the gui is shown
	Update() {
		GuiControl CMB:, CNumberTxt, % CustomMsgBox.cnumber
	}
	
	Display() {
		CustomMsgBox.Update()
		Gui CMB:Show, w200 h200
		CustomMsgBox.Result := ""
		loop
		{
			sleep 1
		} until (CustomMsgBox.Result)
		Gui CMB:Hide
		Return CustomMsgBox.Result
	}

	ButtonClicked() {
		CustomMsgBox.Result := A_GuiControl
	}	
}
Crashm87
Posts: 48
Joined: 25 Jul 2016, 13:12

Re: Custom GUI to replace Msgbox

09 Mar 2017, 23:40

Thanks again for the help.
I ran this, and it kept asking for static variable for vCNumberTxt, I removed the v from the front, and it displayed the GUI, but no information. I added the other comma after Add, Text, like this
Gui CMB:Add, Text, vCNumberTxt
and it showed the information. So I added the other data (cname, brand, etc.) and they all appeared in the GUI like planned.

So I changed the customer name in row 2 of my excel data to "testing name" to check to make sure it was updating, and it is not. When I press no, it still displays the same instance over and over, doesn't update to the next 'c' instance.

Any ideas?
4GForce
Posts: 553
Joined: 25 Jan 2017, 03:18
Contact:

Re: Custom GUI to replace Msgbox

10 Mar 2017, 03:19

Crashm87 wrote:I ran this, and it kept asking for static variable for vCNumberTxt
I'm sorry, that's my fault for not testing.
I did a quick fix by putting the control variables as Globals.
I also added the other controls.
Weird thing is that the myRng.Find("7508") starts at the 3rd row even tho 2nd row is 7508 ( 2nd row is still showned at the end ).
I find those hotkeys usefull for development, you can remove them if you want.

Code: Select all

#SingleInstance Force

; I'll try to fix this later even tho it's not a big deal
Global CNumberTxt, CNameTxt, BrandTxt, TiresizeTxt, RimsTxt, VinTxt, LocTxt

FilePath := "d:\lib_testScripts\testbookahk.xlsx"
myRng := ComObjGet(FilePath).WorkSheets("Sheet1").Range["A2:A9"]

F10::
ExitApp

F9::Reload

; starts a new search
F1::
	InputBox, LookFor, % "Search", % "Enter Search Criteria"
	if !(currentRow := myRng.Find(LookFor))
	{
		MsgBox, 4, % "Warning", % "No matches found.`nDo you want to see database?"
		IfMsgBox Yes
		{
			oExcel := ComObjCreate("Excel.Application")
			oExcel.Workbooks.Open(FilePath)
			oExcel.Visible := true
		}
		Return
	}

	; create the gui once then we call CustomMsgBox.Display() to update/show/hide/return result
	CustomMsgBox.Create()

	firstRow := currentRow.Address

	Loop
	{	
		; Temporary, just for debugging
		Tooltip % "Current: " . currentRow.Address, 1, 1, 1
		
		; Assign the values directly to the object
		CustomMsgBox.cnumber := Round(currentRow.value)
		CustomMsgBox.cname := currentRow.offset(0,1).value
		CustomMsgBox.brand := currentRow.offset(0,2).value
		CustomMsgBox.tiresize := currentRow.offset(0,3).value
		CustomMsgBox.rims := Round(currentRow.offset(0,4).value)
		CustomMsgBox.vin := currentRow.offset(0,6).value	
		loc := currentRow.offset(0,7).value
		if loc is number
		{
			loc := round(loc)
			loc := "TR" . loc
			size := 20
		}
		else
		{
			size := 12
		}
		CustomMsgBox.loc := loc
		
		response := CustomMsgBox.Display()
		if(response == CustomMsgBox.Btn_Yes) {
			msgbox % "User said yes on row : " . currentRow.Address
			break
		}
		else if(response == CustomMsgBox.Btn_No) {
			currentRow := myRng.FindNext(currentRow)
		}
	} Until (currentRow.Address == firstRow)

	msgbox % "Search ended"
	Tooltip,,1
Return

Class CustomMsgBox {
	static Btn_Yes := "Yes"
	static Btn_No := "No"
	static Result := ""
	
	; add your variables here
	static cnumber, cname, brand, tiresize, rims, vin, loc
	
	; add your controls here, leave the text blank but use a V variable in the options
	Create() {
		Gui CMB:New, AlwaysOnTop -Caption 0x00800000, % "Results"
		Gui CMB:Color, 0x999999
		Gui CMB:Margin, 25, 10
		
		; you can add stuff here
		Gui CMB:Add, Text,xm y+m w50, % "CNumber: "
		Gui CMB:Add, Text,x+m w150 vCNumberTxt
		Gui CMB:Add, Text,xm y+m w50, % "CName: "
		Gui CMB:Add, Text,x+m w150 vCNameTxt
		Gui CMB:Add, Text,xm y+m w50, % "Brand: "
		Gui CMB:Add, Text,x+m w150 vBrandTxt
		Gui CMB:Add, Text,xm y+m w50, % "Tiresize: "
		Gui CMB:Add, Text,x+m w150 vTiresizeTxt
		Gui CMB:Add, Text,xm y+m w50, % "Rims: "
		Gui CMB:Add, Text,x+m w150 vRimsTxt
		Gui CMB:Add, Text,xm y+m w50, % "Vin: "
		Gui CMB:Add, Text,x+m w150 vVinTxt
		Gui CMB:Add, Text,xm y+m w50, % "Loc: "
		Gui CMB:Add, Text,x+m w150 vLocTxt
		
		; the buttons
		fn := CustomMsgBox.ButtonClicked.Bind("")
		Gui CMB:Add, Button,xm+50 y+m w50 hwndMyButton, % CustomMsgBox.Btn_Yes
		GuiControl +g, % MyButton, % fn
		Gui CMB:Add, Button,x+m wp hwndMyButton, % CustomMsgBox.Btn_No
		GuiControl +g, % MyButton, % fn
	}
	
	; assign the values to the controls here so they update everytime the gui is shown
	Update() {
		GuiControl CMB:, CNumberTxt, % CustomMsgBox.cnumber
		GuiControl CMB:, CNameTxt, % CustomMsgBox.cname
		GuiControl CMB:, BrandTxt, % CustomMsgBox.brand
		GuiControl CMB:, TiresizeTxt, % CustomMsgBox.tiresize
		GuiControl CMB:, RimsTxt, % CustomMsgBox.rims
		GuiControl CMB:, VinTxt, % CustomMsgBox.vin
		GuiControl CMB:, LocTxt, % CustomMsgBox.loc
	}
	
	Display() {
		CustomMsgBox.Update()
		Gui CMB:Show
		CustomMsgBox.Result := ""
		loop
		{
			sleep 1
		} until (CustomMsgBox.Result)
		Gui CMB:Hide
		Return CustomMsgBox.Result
	}

	ButtonClicked() {
		CustomMsgBox.Result := A_GuiControl
	}	
}
lexikos
Posts: 9635
Joined: 30 Sep 2013, 04:07
Contact:

Re: Custom GUI to replace Msgbox

10 Mar 2017, 05:10

Crashm87 wrote:However, I've never seen a GUI made this way, so I am alittle confused.
The GUI is made the same way as usual, with the GUI command. The code is just organised into a class and methods, which you're likely unfamiliar with. I was somewhat disappointed to see that the replies introduced more complexity without actually addressing your initial misunderstanding. That is,
4GForce wrote:Labels in a loop
Consider how the code flows (how it executes, and how execution moves around the code), not how it looks on screen.

For example,

Code: Select all

Loop {
   ...
   Gui, Show, w327 h185, Customer Information
   return
   ...
}
I think you already realised this wouldn't work; the Gui would be shown and then the code would return, ending the loop. So you've commented out return.

Code: Select all

Loop {
    ...
   Gui, Show, w327 h185, Customer Information
   ;~ return
		
   No:
   {
      c := myRng.FindNext(c)
      continue
   }
   ...
}
Now, the inner set of braces are irrelevant; they have no effect at all.

What do you think will happen after Gui Show executes?

c := myRng.FindNext(c) will happen, and then continue.

When you click the No button, the No sub will run. But at that point, there's a sub running, not a loop. You can't continue a sub.

I suppose that the solution is to:
  • Move the subroutines outside the loop (i.e. to their own dedicated place in the script).
  • Don't use loop-related commands in the subroutines; instead, set a variable to indicate what response the user gave via the Gui (i.e. Yes, No, etc.).
  • Wait for the Gui to close with WinWaitClose. Once it is closed, check the response variable.
4GForce
Posts: 553
Joined: 25 Jan 2017, 03:18
Contact:

Re: Custom GUI to replace Msgbox

10 Mar 2017, 11:34

lexikos wrote:I was somewhat disappointed to see that the replies introduced more complexity without actually addressing your initial misunderstanding. That is,
4GForce wrote:Labels in a loop
I suppose that the solution is to:
  • Move the subroutines outside the loop (i.e. to their own dedicated place in the script).
  • Don't use loop-related commands in the subroutines; instead, set a variable to indicate what response the user gave via the Gui (i.e. Yes, No, etc.).
  • Wait for the Gui to close with WinWaitClose. Once it is closed, check the response variable.
Yeah, Lexikos is right, I went a bit off track with this one.
Crashm87
Posts: 48
Joined: 25 Jul 2016, 13:12

Re: Custom GUI to replace Msgbox

10 Mar 2017, 12:06

Thank you both very much.

4GForce, your last post worked perfectly. Thank you very much, I think I am starting to understand the classes for making that GUI.
4GForce wrote:Yeah, Lexikos is right, I went a bit off track with this one.
It was the classes I didn't understand, but it is nice to know that there is another way of doing this.
lexikos wrote:
Crashm87 wrote:However, I've never seen a GUI made this way, so I am alittle confused.
The GUI is made the same way as usual, with the GUI command. The code is just organised into a class and methods, which you're likely unfamiliar with. I was somewhat disappointed to see that the replies introduced more complexity without actually addressing your initial misunderstanding. That is,
4GForce wrote:Labels in a loop
Consider how the code flows (how it executes, and how execution moves around the code), not how it looks on screen.

For example,

Code: Select all

Loop {
   ...
   Gui, Show, w327 h185, Customer Information
   return
   ...
}
I think you already realised this wouldn't work; the Gui would be shown and then the code would return, ending the loop. So you've commented out return.

Code: Select all

Loop {
    ...
   Gui, Show, w327 h185, Customer Information
   ;~ return
		
   No:
   {
      c := myRng.FindNext(c)
      continue
   }
   ...
}
Now, the inner set of braces are irrelevant; they have no effect at all.

What do you think will happen after Gui Show executes?

c := myRng.FindNext(c) will happen, and then continue.

When you click the No button, the No sub will run. But at that point, there's a sub running, not a loop. You can't continue a sub.

I suppose that the solution is to:
  • Move the subroutines outside the loop (i.e. to their own dedicated place in the script).
  • Don't use loop-related commands in the subroutines; instead, set a variable to indicate what response the user gave via the Gui (i.e. Yes, No, etc.).
  • Wait for the Gui to close with WinWaitClose. Once it is closed, check the response variable.

Thanks for the help with the labels, that makes alot of sense now that the subroutine is killing the loop. I am testing this now!
4GForce
Posts: 553
Joined: 25 Jan 2017, 03:18
Contact:

Re: Custom GUI to replace Msgbox

10 Mar 2017, 16:38

Crashm87 wrote: 4GForce, your last post worked perfectly. Thank you very much, I think I am starting to understand the classes for making that GUI.
Glad to hear it ! At least you learned a little about classes =p

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Bing [Bot], DRS and 98 guests