bar( ) 函式

用set 當選擇選單標題時,on 當從選單中選擇一個選單項時,on

bar( ) 函式
返回最近一次選擇的選單項的編號。該選單項選自 DEFINE POPUP 命令定義的選單,或是一個 Visual FoxPro 選單。

語法

BAR( )

返回值類型

數值型

說明

DEFINE BAR 給選單上的每一個選單項賦予一個編號。當從選單中選擇一個選單項時,BAR( ) 返回該選單項對應的編號。根據 BAR( ) 的返回值,一個程式可以分支調用其他例程。
如果沒有活動選單,或者用戶按下 Esc 鍵退出選單,那么 BAR( ) 返回 0。

bar( ) 函式示例

下面的示例使用 bar( ) 將一個選單項的編號傳遞給一個過程。用set sysmenu save 命令將當前系統選單欄保存到記憶體中,然後用 set sysmenu to 命令刪除所有系統選單標題。define pad 命令創建了兩個選單標題,define popup 為每一個選單標題創建一個選單,define bar 在每一個選單上創建選單項。當選擇選單標題時,on pad 使用 activate popup 命令激活相應選單。當從選單中選擇一個選單項時,on selection popup 使用 bar( ) 和 popup( ) 把選單項編號和選單標題傳遞給 choice 過程,choice 過程將顯示所選選單項的編號及其所屬的選單的名稱。若選擇 card info 選單的 exit 項,原來的 visual foxpro 系統選單將由 set sysmenu to default 命令恢復。

*** name this program bar_exam.prg ***
clear
set sysmenu save
set sysmenu to
define pad padconv of _msysmenu ;
prompt '\<conversions' color scheme 3 ;
key alt+c, ''
define pad padcard of _msysmenu ;
prompt 'card \<info' color scheme 3 ;
key alt+i, ''
on pad padconv of _msysmenu activate popup popconv
on pad padcard of _msysmenu activate popup popcard
define popup popconv margin relative shadow color scheme 4
define bar 1 of popconv prompt 'ar\<ea' key ctrl+e, '^e'
define bar 2 of popconv prompt '\<length' ;
key ctrl+l, '^l'
define bar 3 of popconv prompt 'ma\<ss' ;
key ctrl+s, '^s'
define bar 4 of popconv prompt 'spee\<d' ;
key ctrl+d, '^d'

define bar 5 of popconv prompt '\<temperature' ;
key ctrl+t, '^t'
define bar 6 of popconv prompt 't\<ime' ;
key ctrl+i, '^i'
define bar 7 of popconv prompt 'volu\<me' ;
key ctrl+m, '^m'
*** here is where the popconv menu uses the bar( ) function
*** to pass a bar number to the PROCEDURE called choice below.
on selection popup popconv;
do choice in bar_exam with bar( ), popup( )
define popup popcard margin relative shadow color scheme 4
define bar 1 of popcard prompt '\<view charges' ;
key alt+v, ''
define bar 2 of popcard prompt 'view \<payments' ;
key alt+p, ''

define bar 3 of popcard prompt 'vie\<w users' ;
key alt+w, ''

define bar 4 of popcard prompt '\-'
define bar 5 of popcard prompt '\<charges ';
key alt+c
define bar 6 of popcard prompt '\-'

define bar 7 of popcard prompt 'e\<xit ';
key alt+x

*** here is where the popcard menu uses the bar( ) function
*** to pass a bar number to the procedure called choice below.
on selection popup popcard;
do choice in bar_exam with bar( ), popup( )
*** the procedure choice uses the gnbar parameter
*** to contain the value passed by the bar( ) function.
procedure choice
parameters gnbar, gcpopup
wait window 'you chose bar #' + ltrim(str(gnbar)) + ;
' from popup ' + gcpopup nowait
set sysmenu to default
endif

相關詞條

相關搜尋

熱門詞條

聯絡我們