Create a partition in GUI Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Fulminare
Posts: 369
Joined: 26 Jun 2021, 20:15

Create a partition in GUI

16 Oct 2021, 20:12

I don't know if this is possible, but anyway

This is the code I use for displaying excel data in a gui. (a name and a number)

Code: Select all

xl := ComObjCreate("excel.application")
wrkbk := xl.workbooks.open("C:\Users\user\Desktop\HI.xlsm")
Gui, Add, Progress, x0 y0 w0 h0
Gui, Add, Monthcal, x250 y10
Gui, font, s10, Verdana
Gui, Color, Yellow
for sh in xl.sheets
	if (a_index > 2)
	{
		lstrw := sh.Range("B" xl.Rows.Count).End(-4162).Row
		lstrw1 := sh.Range("A" xl.Rows.Count).End(-4162).Row
		runs :=sh.Range("B" lstrw).text
		name :=sh.Range("A" lstrw).text
		if a_Index = 3  ; the first possible value after meeting the condition "if (a_index > 2)"
			Gui, Add, Text, x1 y1 wp , %name%       %runs%		; first iteration start at y10
		else
			Gui, Add, Text, x1 y+10 wp , %name%       %runs%	; subsequent iterations at y+10 relative to previously added control
	}

Gui Show
sh := ""
xl.quit()
xl := ""

I just want the name to be displayed in one area and the number in another ( Similar to cells in excel. One entry will be shown in each cell. Like that I want the Name to be shown in one area of the GUI and Number to be shown in another area in the same line as the name )

I am using the following code for testing

Code: Select all

Gui, Add, Progress, x0 y0 w0 h0
Gui, Add, Monthcal, x250 y10
Gui, font, s10, Verdana
Gui, Color, Yellow

			Gui, Add, Text, x1 y1 wp , John 1
	

Gui Show

Can someone please guide / help me ?

Regards
User avatar
Spawnova
Posts: 554
Joined: 08 Jul 2015, 00:12
Contact:

Re: Create a partition in GUI  Topic is solved

16 Oct 2021, 22:09

Seems like you may be interested in listviews, which do pretty much exactly what you want with sorting and other features as well.

Code: Select all

;for more help with listviews check out the docs - https://www.autohotkey.com/docs/commands/ListView.htm

lines := []
lines.push({name:"John",value:1})
lines.push({name:"Samantha",value:3})
lines.push({name:"Sir Maximus",value:17})

Gui, Add, Progress, x0 y0 w0 h0
Gui, Add, Monthcal, x250 y10
Gui, font, s10, Verdana
Gui, Color, Yellow
Gui,Add,Listview,x10 y10 grid w230 h160 altsubmit gmylistview,Name|Value  ;grid option add lines, to make it similar to excel

LV_ModifyCol(2, "Integer")  ; For sorting purposes, indicate that column 2 (value) is an integer.

for k,v in lines 
	 AddNewData(v.name,v.value) ;adds name and value into the listview via helper function
AddNewData("Max",1829) ;adding a manual entry outside of the lines array

Gui Show
return



mylistview:
if (a_guievent = "Normal") { ;on normal left click
    LV_GetText(Name_Selected, A_EventInfo,1)  ; Get the text from the row's first field.
	LV_GetText(Value_Selected, A_EventInfo,2) ; Get the text from the row's second field.
    ToolTip % "You clicked row number " A_EventInfo "`nName: " Name_Selected "`nValue: " Value_Selected
	;name and value are now stored in variables (Name_Selected,Value_Selected) and can be used in other parts of the code
}
return



AddNewData(name,value) { ;helper function
	LV_Add("",name,value)
	LV_ModifyCol(1,"AutoHdr")  ; Auto-size column 1 (name) to fit the contents or the header size, whichever is bigger
	LV_ModifyCol(2,"AutoHdr")  ; Auto-size column 2 (value) to fit the contents or the header size, whichever is bigger
}


f9::reload
f8::exitapp
Fulminare
Posts: 369
Joined: 26 Jun 2021, 20:15

Re: Create a partition in GUI

16 Oct 2021, 22:39

Oh wow !
This is wonderful !

I will try tinkering with it suite my requirement

Thanks a lot :)
Fulminare
Posts: 369
Joined: 26 Jun 2021, 20:15

Re: Create a partition in GUI

17 Oct 2021, 03:09

I have somewhat understood what is going on with the listview thing.

But I am unable to add the excel data. Like the the code I use takes the last row values of each sheet and shows it in a gui. like the name and the value are shown in the GUI ( %name% %runs% )

how make it such a way that the %names% is shown in under the name tab and %runs% is shown under the value tab

I tried this

Code: Select all


xl := ComObjCreate("excel.application")
wrkbk := xl.workbooks.open("C:\Users\user\Desktop\Hi.xlsm")
for sh in xl.sheets
	if (a_index > 2)
	{
		lstrw := sh.Range("B" xl.Rows.Count).End(-4162).Row
		lstrw1 := sh.Range("A" xl.Rows.Count).End(-4162).Row
		runs :=sh.Range("B" lstrw).text
		name :=sh.Range("A" lstrw).text
		}

sh := ""
xl.quit()
xl := ""



lines := []
lines.push({name:"name",Value:%runs%})
lines.push({name:"name",Vlaue:%runs%})
lines.push({name:"name",Value:%runs%})

I wanted to show each sheet's data in a listview line

I know that is not the correct way of doing it.

can you please educate me ?
just me
Posts: 9453
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: Create a partition in GUI

17 Oct 2021, 05:54

Maybe (*not tested*):

Code: Select all

#NoEnv
SetBatchLines, -1
;for more help with listviews check out the docs - https://www.autohotkey.com/docs/commands/ListView.htm
Gui, Add, Progress, x0 y0 w0 h0
Gui, Add, Monthcal, x250 y10
Gui, Font, s10, Verdana
Gui, Color, Yellow
Gui, Add, Listview, x10 y10 Grid w230 h160 AltSubmit gMyListView, Name|Value  ;grid option add lines, to make it similar to excel
xl := ComObjCreate("excel.application")
wrkbk := xl.workbooks.open("C:\Users\user\Desktop\HI.xlsm")
for sh in xl.sheets
	if (a_index > 2)
	{
		lstrw := sh.Range("B" xl.Rows.Count).End(-4162).Row
		lstrw1 := sh.Range("A" xl.Rows.Count).End(-4162).Row
		name :=sh.Range("A" lstrw).text
		runs :=sh.Range("B" lstrw).text
		LV_Add("", name, runs)
   }
sh := ""
xl.quit()
xl := ""
LV_ModifyCol(2, "Integer")  ; For sorting purposes, indicate that column 2 (value) is an integer.
Gui, Show
Return

GuiClose:
ExitApp

MyListView:
ToolTip, %A_GuiEvent% -> %A_EventInfo%
Return
Fulminare
Posts: 369
Joined: 26 Jun 2021, 20:15

Re: Create a partition in GUI

17 Oct 2021, 06:20

Thanks a lot just me :)

It's working quite well !

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Google [Bot], Joey5, mikeyww, RandomBoy and 377 guests