DropDownList

遇到了问题?请先进行搜索(中文和英文),然后在此提问

Moderators: arcticir, tmplinshi

Marcosa1020
Posts: 125
Joined: 23 Sep 2015, 19:15

DropDownList

22 Apr 2016, 21:37

Hello,

這裡有兩個DropDownList,分別是vcard1 & vcard2.
假設A為1, B為2, APPLE為3, SAMSUNG為4
vcard1 選A, vcard2選 APPLE,我希望按Output 輸出3
vcard1 選A, vcard2選 SAMSUNG,我希望按Output 輸出4
vcard1 選B, vcard2選 APPLE,我希望按Output 輸出6
vcard1 選B, vcard2選 SAMSUNG,我希望按Output 輸出8

請各位指點,我該如何實現呢? 感謝喔。


Gui +AlwaysOnTop
;Gui, +E0x08000000 ;WS_EX_NOACTIVATE = 0x08000000
Gui, Font, S10 C000000 , Tahoma
Gui, Show, x131 y91 h153 w321,Test
Gui, Font, S09 cFF0000 , Tahoma
Gui, Add, Tab, x-2 y0 w325 h153 , Home

Gui, Font, S12 c000000 , Verdana
Gui, Add, Button, x98 y120 w62 h30 ,Output
Gui, Font, S10 c000000 , Verdana

Gui, Add, DropDownList, x2 y122 w94 h120 vcard1, A|B|
Gui, Add, DropDownList, x2 y87 w94 h30 vcard2, APPLE|SAMSUNG

#Persistent
WinGet, a_ID, ID, A
SetTimer, aa, 500
return

aa:
WinGet, a1_ID, ID, A
If ( a_ID != a1_ID )
k_ID = %a1_ID%
Return

ButtonOutput:
Gui, Submit, NoHide
Send !{Tab} %card1% ;不知道這段該怎麼寫。
return

GuiClose:
aamii
Posts: 47
Joined: 23 May 2014, 03:50

Re: DropDownList

22 Apr 2016, 23:48

在代碼頭部做好定義,按您的需求,感覺用兩個數組更閤理

Code: Select all

obj:={"A":1,"B":2,"Apple":3,"Samsung":4} 

Code: Select all

ButtonOutput:
	Gui, Submit, NoHide
	ToolTip % "輸出 = " obj[card1] * obj[card2]
	return
Marcosa1020
Posts: 125
Joined: 23 Sep 2015, 19:15

Re: DropDownList

23 Apr 2016, 01:16

Hi Aamii,

不好意思,程式如下,我開Excel file測試後出現錯誤訊息。
我想在Website or excel file 選好card1 & card2 按Output就可以將結果自動計算後輸出。
因此您所提到的定義"兩個數組"對我來說是非常重要的,當初沒想到。
還要請您費心幫我看看,感謝。

Gui +AlwaysOnTop
;Gui, +E0x08000000 ;WS_EX_NOACTIVATE = 0x08000000
Gui, Font, S10 C000000 , Tahoma
Gui, Show, x131 y91 h153 w321,Test
Gui, Font, S09 cFF0000 , Tahoma
Gui, Add, Tab, x-2 y0 w325 h153 , Home

Gui, Font, S12 c000000 , Verdana
Gui, Add, Button, x98 y120 w62 h30 ,Output
Gui, Font, S10 c000000 , Verdana

Gui, Add, DropDownList, x2 y122 w94 h120 vcard1, A|B|
Gui, Add, DropDownList, x2 y87 w94 h30 vcard2, APPLE|SAMSUNG
obj:={"A":1,"B":2,"Apple":3,"Samsung":4} ;這段出現錯誤訊息

#Persistent
WinGet, a_ID, ID, A
SetTimer, aa, 500
return

aa:
WinGet, a1_ID, ID, A
If ( a_ID != a1_ID )
k_ID = %a1_ID%
Return

ButtonOutput:
Gui, Submit, NoHide
ToolTip % "輸出 = " obj[card1] * obj[card2] ;本來這段我是用Send !{Tab} %card1% 還能輸出Card1,不過不能計算Card * Card2。
return

GuiClose:
ExitApp
aamii
Posts: 47
Joined: 23 May 2014, 03:50

Re: DropDownList

23 Apr 2016, 02:08

没有明白“出现什么讯息错误”。下面以“输出到Excel”为例。

Code: Select all

Gui +AlwaysOnTop
;Gui, +E0x08000000 ;WS_EX_NOACTIVATE = 0x08000000
Gui, Font, S10 C000000 , Tahoma
Gui, Show, x131 y91 h153 w321,Test
Gui, Font, S09 cFF0000 , Tahoma
Gui, Add, Tab, x-2 y0 w325 h153 , Home
Gui, Font, S12 c000000 , Verdana
Gui, Add, Button, x98 y120 w62 h30 ,Output
Gui, Font, S10 c000000 , Verdana

Gui, Add, DropDownList, x2 y122 w94 h120 vcard1, A||B
Gui, Add, DropDownList, x2 y87 w94 h30 vcard2, APPLE||SAMSUNG
obj:={"A":1,"B":2,"Apple":3,"Samsung":4} ;這段出現錯誤訊息
ox := ComObjActive("Excel.application")  ;连接excel

#Persistent
WinGet, a_ID, ID, A
SetTimer, aa, 500
return

aa:
WinGet, a1_ID, ID, A
If ( a_ID != a1_ID )
k_ID = %a1_ID%
Return

ButtonOutput:
Gui, Submit, NoHide
out:= obj[card1] * obj[card2] ;本來這段我是用Send !{Tab} %card1% 還能輸出Card1,不過不能計算Card * Card2。
ox.ActiveCell.value:=out   ;输出到Excel当前单元格
return

GuiClose:
ExitApp
Marcosa1020
Posts: 125
Joined: 23 Sep 2015, 19:15

Re: DropDownList

23 Apr 2016, 02:25

Aamii,

抱歉,測試後出現錯誤訊息,訊息如下。
您不用寫開啟Excel file這段,User會自己開; ox := ComObjActive("Excel.application") ;连接excel。
我現在苦惱的是實際上Card1 有A、B兩個選項,Card2有超過五十個選項。
User會自行開Excel 然後選 Card1 & Card2 按Output,Output輸出的數字就是我要請您幫忙的地方。
謝謝。

錯誤訊息為:
Error at line 13.
Line Text: {"A"
Error: The ;eftmost character above is illegal in an expression.
The program will exit.
aamii
Posts: 47
Joined: 23 May 2014, 03:50

Re: DropDownList

23 Apr 2016, 09:37

正常来说,

Code: Select all

obj:={"A":1,"B":2,"Apple":3,"Samsung":4} 
前面的引号,是不需要的。但即使加了,在我的电脑上,也没有显示错。
你试试下面的写法。

Code: Select all

obj:={A:1,B:2,Apple:3,Samsung:4} 
另外,我也不知道你当前在用的ahk版本,或者其他的问题,我建议,你提取官方帮助上面的一段测试一下,看有没有什么错误提示。

Code: Select all

array := {ten: 10, twenty: 20, thirty: 30}
For key, value in array
    MsgBox %key% = %value%
Marcosa1020
Posts: 125
Joined: 23 Sep 2015, 19:15

Re: DropDownList

23 Apr 2016, 10:24

真是辛苦您了,我想應該是我這邊的問題,我用的版本是v1.0.48.05版,您寫的那段在我這裡沒有輸出。
下面這段我有做一點修改,很接近我想要的功能。
當我在card1 選A, card2 選APPLE, 按Output之後會輸出1*3。
請問乘法的寫法是什麼呢? 謝謝。

Gui +AlwaysOnTop
Gui, Font, S10 C000000 , Tahoma
Gui, Show, x131 y91 h153 w321,Test
Gui, Font, S09 cFF0000 , Tahoma
Gui, Add, Tab, x-2 y0 w325 h153 , Home
Gui, Font, S12 c000000 , Verdana
Gui, Add, Button, x98 y120 w62 h30 ,Output
Gui, Font, S10 c000000 , Verdana

Gui, Add, DropDownList, x2 y50 w94 h200 vcard1, A|B
Gui, Add, DropDownList, x200 y50 w94 h200 vcard2, APPLE|SAMSUNG

#Persistent
WinGet, a_ID, ID, A
SetTimer, aa, 500
return

aa:
WinGet, a1_ID, ID, A
If ( a_ID != a1_ID )
k_ID = %a1_ID%
Return

ButtonOutput:
WinActivate, ahk_id %k_ID%
Gui, Submit, NoHide

A := "1"
B := "2"
APPLE := "3"
SAMSUNG := "4"
Send %A%*%APPLE%
return

GuiClose:
ExitApp
aamii
Posts: 47
Joined: 23 May 2014, 03:50

Re: DropDownList

23 Apr 2016, 19:48

的确是版本的问题,个人建议可以试试新版

Code: Select all

A := "1"
B := "2"
APPLE := "3"
SAMSUNG := "4"
out:=%card1% * %card2%
Send %out%
或者,干脆

Code: Select all

send  % %card1% * %card2%
以上写法在L版上通过,未在v1.0.48.05 Basic版测试。
Marcosa1020
Posts: 125
Joined: 23 Sep 2015, 19:15

Re: DropDownList

23 Apr 2016, 20:32

aamii wrote:的确是版本的问题,个人建议可以试试新版

Code: Select all

A := "1"
B := "2"
APPLE := "3"
SAMSUNG := "4"
out:=%card1% * %card2%
Send %out%
或者,干脆

Code: Select all

send  % %card1% * %card2%
以上写法在L版上通过,未在v1.0.48.05 Basic版测试。
Aamii, 感謝您幫我把問題解決了。

Return to “请求帮助”

Who is online

Users browsing this forum: No registered users and 10 guests