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
}
}