Add Numbers to SubMenu?

Get help with using AutoHotkey and its commands and hotkeys
ahklearner
Posts: 283
Joined: 23 Jan 2015, 01:49

Add Numbers to SubMenu?

16 May 2015, 00:08

I am designing a menu with submenus I would like to have each submenu start with an alphabet!

As you can see #3 is coming in all submens, I would like to have alphabets.

In place of ?????, what should i place.

Any help would be appreciated.

Code: Select all

Loop, parse, Clipboard, `n, `r,
{
 	StringLeft, FirstChar, A_LoopField, 1
Loop, 26
	{
	CurrentChar := 64 + A_Index
	CurrentChar := Chr(CurrentChar)
	if FirstChar = %CurrentChar%
	Menu, Submenu%CurrentChar%, Add, %?????%%A_Space%%A_LoopField%, MyMenuHandlerTMP
	
	MyIndex := A_Index+0
	if FirstChar = %MyIndex%
	Menu, Submenu1, Add, %A_LoopField%, MyMenuHandlerTMP
	}
}
Attachments
MyMenu.jpg
hd0202
Posts: 61
Joined: 04 Oct 2013, 03:07
Location: Germany near Cologne

Re: Add Numbers to SubMenu?

17 May 2015, 09:24

This is my suggestion:

Code: Select all

prevchar =
ind = 0
Loop, parse, Clipboard, `n, `r,
{
 	StringLeft, FirstChar, A_LoopField, 1
	if (firstchar <> prevchar and prevchar <> "")
	{
		Menu, Mymenu, Add, %prevchar%%a_space%Submenu, :Submenu%prevchar%
		ind = 0
	}
	if !firstchar
		break
	prevchar := firstchar
	ind++
	CurrentChar := 64 + ind
	CurrentChar := Chr(CurrentChar)
	Menu, Submenu%prevChar%, Add, %currentchar%%A_Space%%A_LoopField%, MyMenuHandlerTMP
}
return

myMenuHandlertmp:
MsgBox You selected %A_ThisMenuItem% in %A_ThisMenu%.
return
Hubert
ahklearner
Posts: 283
Joined: 23 Jan 2015, 01:49

Re: Add Numbers to SubMenu?

17 May 2015, 09:36

Hi
Whenever the script is executed it is GOOD, but when you assign a key and press it many times the menus are getting loop added?
any fix like resetting menu :oops:
thanks in advance.
Attachments
MyMenu2.jpg
ahklearner
Posts: 283
Joined: 23 Jan 2015, 01:49

Re: Add Numbers to SubMenu?

17 May 2015, 10:19

Could you please explain me, what exactly is this line doing: :crazy:

Code: Select all

if (firstchar <> prevchar and prevchar <> "")
hd0202 wrote:This is my suggestion:

Code: Select all

prevchar =
ind = 0
Loop, parse, Clipboard, `n, `r,
{
 	StringLeft, FirstChar, A_LoopField, 1
	if (firstchar <> prevchar and prevchar <> "")
	{
		Menu, Mymenu, Add, %prevchar%%a_space%Submenu, :Submenu%prevchar%
		ind = 0
	}
	if !firstchar
		break
	prevchar := firstchar
	ind++
	CurrentChar := 64 + ind
	CurrentChar := Chr(CurrentChar)
	Menu, Submenu%prevChar%, Add, %currentchar%%A_Space%%A_LoopField%, MyMenuHandlerTMP
}
return

myMenuHandlertmp:
MsgBox You selected %A_ThisMenuItem% in %A_ThisMenu%.
return
Hubert
ahklearner
Posts: 283
Joined: 23 Jan 2015, 01:49

Re: Add Numbers to SubMenu?

17 May 2015, 11:34

Hey after spending long hour and adding some log statements :oops: ,
I realized you are a true genious hd0202 :clap:
Really HatsOff to you hd0202 :thumbup:
Thanks again for your help, I know this has been confusing! :crazy:

ahklearner wrote:Could you please explain me, what exactly is this line doing: :crazy:

Code: Select all

if (firstchar <> prevchar and prevchar <> "")
hd0202 wrote:This is my suggestion:

Code: Select all

prevchar =
ind = 0
Loop, parse, Clipboard, `n, `r,
{
 	StringLeft, FirstChar, A_LoopField, 1
	if (firstchar <> prevchar and prevchar <> "")
	{
		Menu, Mymenu, Add, %prevchar%%a_space%Submenu, :Submenu%prevchar%
		ind = 0
	}
	if !firstchar
		break
	prevchar := firstchar
	ind++
	CurrentChar := 64 + ind
	CurrentChar := Chr(CurrentChar)
	Menu, Submenu%prevChar%, Add, %currentchar%%A_Space%%A_LoopField%, MyMenuHandlerTMP
}
return

myMenuHandlertmp:
MsgBox You selected %A_ThisMenuItem% in %A_ThisMenu%.
return
Hubert
ahklearner
Posts: 283
Joined: 23 Jan 2015, 01:49

Re: Add Numbers to SubMenu?

17 May 2015, 12:12

Hey sorry to bother you again hd0202!

I have some menus starting from numerals [0-9], I would like them to be added to one SubMenu0
How can I do it your way!

Thanks in advance for your help and support.
ahklearner
Posts: 283
Joined: 23 Jan 2015, 01:49

Re: Add Numbers to SubMenu?

17 May 2015, 12:55

ahklearner wrote:Hey sorry to bother you again hd0202!

I have some menus starting from numerals [0-9], I would like them to be added to one SubMenu0
How can I do it your way!

Thanks in advance for your help and support.
; ---------------------------------------------; ---------------------------------------------
Hi hd0202,

Is this what you would have suggested.
OR you have something to amaze me :think:

Code: Select all

	if FirstChar in 1,2,3,4,5,6,7,8,9,0
	{
	Menu, Submenu0, Add, %A_LoopField%, MyMenuHandlerTMP
	Menu, MyMenu, Add, 0 Submenu, :Submenu0
	continue
	}

Code: Select all

prevchar =
ind = 0
Loop, parse, Clipboard, `n, `r,
{
 	StringLeft, FirstChar, A_LoopField, 1
; ---------------------------------------------	
	if FirstChar in 1,2,3,4,5,6,7,8,9,0
	{
	Menu, Submenu0, Add, %A_LoopField%, MyMenuHandlerTMP
	Menu, MyMenu, Add, 0 Submenu, :Submenu0
	continue
	}
; ---------------------------------------------

	if (firstchar <> prevchar and prevchar <> "")
	{
		Menu, Mymenu, Add, %prevchar%%a_space%Submenu, :Submenu%prevchar%
		ind = 0
	}
	
	if !firstchar
	break
	prevchar := firstchar
	ind++
	CurrentChar := 64 + ind
	CurrentChar := Chr(CurrentChar)
	
	Menu, Submenu%prevChar%, Add, %currentchar%%A_Space%%A_LoopField%, MyMenuHandlerTMP
}

Return to “Ask For Help”

Who is online

Users browsing this forum: Google [Bot], Scr1pter, TheBeginner and 185 guests