版權(quán)說(shuō)明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡(jiǎn)介
1、<p><b> 中文5270字</b></p><p> 畢業(yè)設(shè)計(jì)(論文)外文資料翻譯</p><p> 系 (院): </p><p> 專業(yè)班級(jí): 計(jì)算機(jī)科學(xué)與技術(shù) </p><p> 姓 名:
2、 </p><p> 學(xué) 號(hào): </p><p> 外文出處: http://edndoc.esri.com/ </p><p> 附 件: 1.外文資料翻譯譯文;2.外文原文。 </p><p> 注:請(qǐng)將該封
3、面與附件裝訂成冊(cè)。</p><p> 附件1:外文資料翻譯譯文</p><p><b> VBA的開發(fā)環(huán)境</b></p><p> 本文主要討論怎樣在VBA開發(fā)環(huán)境中進(jìn)行編程,通過(guò)對(duì)路徑、目錄以及場(chǎng)景所顯示的對(duì)象的訪問(wèn),來(lái)對(duì)它們進(jìn)行控制和操作。代碼通過(guò)設(shè)置和獲取它們接口的屬性來(lái)操作對(duì)象,例如,設(shè)置窗口的最大化和最小化;代碼還可以通過(guò)運(yùn)用
4、接口的方法來(lái)操作對(duì)象,例如,可以在多線中添加一個(gè)點(diǎn);另外,代碼還可以設(shè)置一個(gè)區(qū)域的值。當(dāng)一個(gè)事件發(fā)生時(shí),代碼隨之而運(yùn)行。例如,當(dāng)用戶打開一個(gè)文檔,點(diǎn)擊一個(gè)按鈕,或是通過(guò)修改一個(gè)正在編輯的草圖來(lái)更新數(shù)據(jù)時(shí),都會(huì)引發(fā)代碼的運(yùn)行。</p><p> 在我們學(xué)習(xí)VBA開發(fā)環(huán)境之前,我們先來(lái)了解一下有關(guān)VBA的一些概念。</p><p> 什么Visual Basic for Applicati
5、on 呢?Visual Basic for Application 是Microsoft Visual Basic 系列的一部分。Microsoft Visual Basic 系列還包括Visual Basic 開發(fā)系統(tǒng)(主要有學(xué)習(xí)版本、專業(yè)版本和企業(yè)版本)和 Visual Basic 腳本版本(VBScript)。VBA是一個(gè)嵌入式的編程開發(fā)環(huán)境,它可以幫助開發(fā)者借助Microsoft Visual Basic的能力來(lái)解決客戶端的問(wèn)題
6、。開發(fā)者通過(guò)使用基于VBA的應(yīng)用,可以自動(dòng)的延伸應(yīng)用的函數(shù)功能??s短開發(fā)客戶端業(yè)務(wù)的解決問(wèn)題的周期性。</p><p> Visual Basic、VBA以及VBScript之間的區(qū)別是什么?我們什么時(shí)候使用其中的一種應(yīng)用而取代另一種應(yīng)用呢?Visual Basic是一個(gè)用于建立單獨(dú)的軟件部件的標(biāo)準(zhǔn)獨(dú)立工具,例如,我們可以用它來(lái)編輯可執(zhí)行的程序,COM 部件和動(dòng)態(tài)插件控制。同時(shí),當(dāng)你必須建立一個(gè)用于解決損傷的特
7、殊的方法時(shí),Visual Basic是非常有效的。</p><p> 在已經(jīng)存在一個(gè)現(xiàn)有的應(yīng)用的情況下,VBA能夠提供和Visual Basic一樣有效的工具。而且,對(duì)于已經(jīng)符合你的大部分需求的特定軟件而言,VBA是最好的選擇。</p><p> VBScript 是Visual Basic 語(yǔ)言中幾個(gè)比較低級(jí)的版本,它是被設(shè)計(jì)為專門用于在WEB網(wǎng)頁(yè)上使用的語(yǔ)言。當(dāng)腳本通常能夠被用語(yǔ)簡(jiǎn)
8、單自動(dòng)化時(shí),VBA是最先進(jìn)的科技,特別是對(duì)于一些特殊的應(yīng)用自動(dòng)化而言。不同于VBA ,VBScript沒(méi)有一個(gè)集成開發(fā)環(huán)境。</p><p> 微軟的哪些應(yīng)用程序包括Visual Basic for Application呢?VBA6.3在微軟Office XP中是一個(gè)核心部件,它主要集成在 Microsoft Access, Microsoft Excel, Microsoft FrontPage, Micr
9、osoft Outlook, Microsoft PowerPoint, and Microsoft Word 中。而VBA5.0主要用于Microsoft Office 97和98中 的Access, Excel, PowerPoint, 以及 Word 中。 </p><p><b> VBA的開發(fā)環(huán)境</b></p><p> 首先你將會(huì)看見(jiàn)VBA開發(fā)環(huán)境的
10、外觀,在這里你將會(huì)做一些工作,這些工作特別適用于ESRI應(yīng)用程序。參考Visual Basic的附注,當(dāng)你點(diǎn)擊在Visual Basic 關(guān)于VBA編輯的幫助菜單時(shí),在線幫助文件顯示了一些關(guān)于在用戶借口上的一般的幫助,概念性的主題,如何操作的主題,參考主題的語(yǔ)言, 以及特定Visual Basic編輯者和用戶的形式和控制的信息。</p><p> 在VBA開發(fā)環(huán)境中,你能夠添加模組,類模組和用戶模式到包含在每一
11、個(gè)壓縮綜合信息系統(tǒng)應(yīng)用程序文件中的默認(rèn)項(xiàng)目中去。一個(gè)項(xiàng)目能夠組成和你的工作需求一樣多的模組,類模組和用戶模式。一個(gè)項(xiàng)目是一些項(xiàng)目的集合,在這些項(xiàng)目中你可以添加相關(guān)的代碼。一個(gè)模組是一套由你的代碼執(zhí)行指令的過(guò)程目錄的申明。一個(gè)類模組是一個(gè)特別的模組,它包括了一個(gè)類的定義,以及它的屬性和方法的定義。一個(gè)用戶模式是一個(gè)包含了用戶接口控制的容器,比如命令按鈕和文本框。</p><p> 壓縮框有一個(gè)和自身文檔相聯(lián)系的默
12、認(rèn)的項(xiàng)目,該文檔一自身的名稱列在項(xiàng)目瀏覽器中。另外,你會(huì)在項(xiàng)目瀏覽器中看到其他項(xiàng)目,它就是標(biāo)準(zhǔn)文檔(Normal.mxt)</p><p> 標(biāo)準(zhǔn)文檔實(shí)際上是一個(gè)用于所以穩(wěn)當(dāng)?shù)哪0?。它總是嵌入在文檔之中。它包含了所有用戶能看見(jiàn)的用戶接口的因素和ArcID 的類模組,在這些模組中包含了所有應(yīng)用命令的用戶標(biāo)識(shí)符。</p><p> 因?yàn)槿魏我恍╆P(guān)于Normal的修改都會(huì)在你創(chuàng)造或打開一個(gè)文
13、檔時(shí)的每個(gè)時(shí)刻受到影響,所以當(dāng)對(duì)Normal進(jìn)行修改時(shí)你應(yīng)該格外小心些。</p><p> 在ArcMap中,用戶能夠通過(guò)打開一個(gè)非默認(rèn)的模板開始執(zhí)行。這些模板在新的對(duì)話框中是多用途的。從一個(gè)開發(fā)者的角度來(lái)看,這是一個(gè)基礎(chǔ)性的模板,它是一個(gè)可以裝載一個(gè)附加項(xiàng)目到文檔里的文檔文件,它作為模板項(xiàng)目以文件名的方式被列于項(xiàng)目瀏覽器中。這個(gè)項(xiàng)目能夠在模組、類模組、模型以及其它任何特定的組塊中存儲(chǔ)代碼,比如具有數(shù)據(jù)的圖表,
14、或是具有幀界面的頁(yè)等等?;诨灸0宓娜魏涡薷幕蚴歉淖兌紩?huì)在自身的文檔中受到影響。</p><p> 在ArcCatalog中,Normal(Normal.gxt)是出現(xiàn)在項(xiàng)目瀏覽器中的唯一的項(xiàng)目。在ArcCatalog中沒(méi)有默認(rèn)的項(xiàng)目,而且你不能裝載任何模板。當(dāng)然你可以在模組、類模組或是模型中的Normal.gxt中添加代碼,但是當(dāng)在一次產(chǎn)生改變時(shí),一定要小心。</p><p> 一
15、旦你已經(jīng)開始使用了Visual Basic編輯器,你可以插入一個(gè)模組、類模組或是用戶模式。然后,在項(xiàng)目代碼窗中的一個(gè)已經(jīng)存在的事件進(jìn)程中插入一個(gè)進(jìn)程或是添加代碼。在這個(gè)項(xiàng)目代碼窗口中,你可以書寫、顯示、編輯代碼??梢哉f(shuō),你有多少的模組、類模組和用戶模式,你就可以打開多少個(gè)與之相對(duì)應(yīng)的代碼窗口。所以,你可以很方便的在不同的代碼窗口中瀏覽和復(fù)制、粘貼代碼。另外,為了添加自己的模組,你可以從光盤中導(dǎo)入其它的模組、類模組或是用戶模式。</
16、p><p> 如果你的工作需要,你可以參考自己的項(xiàng)目來(lái)添加一個(gè)額外的對(duì)象庫(kù)或類型庫(kù)。這會(huì)在你的代碼中產(chǎn)生另外一些可利用的應(yīng)用對(duì)象。一旦一個(gè)引用已經(jīng)建立,被引用的對(duì)象就會(huì)在開發(fā)環(huán)境的對(duì)象瀏覽器中顯示出來(lái)。</p><p><b> 開始使用VBA</b></p><p> 要在ArcMap和ArcCatalog中開始使用VBA開始編程,你要先打
17、開Visual Basic編輯器。</p><p> 開始使用Visual Basic編輯器</p><p> 啟動(dòng)ArcMap和ArcCatalog。</p><p> 點(diǎn)擊工具菜單,指向宏,然后點(diǎn)擊Visual Basic編輯器。你也可以使用快捷鍵Alt+F11來(lái)顯示Visual Basic編輯器。使用項(xiàng)目瀏覽器在Visual Basic編輯器中的各個(gè)項(xiàng)目
18、項(xiàng)目中進(jìn)行控制操作。它顯示了文檔的模組、類模組和用戶形式的清單條目。</p><p> 在一個(gè)模組中添加一個(gè)宏</p><p> ArcMap和ArcCatalog都提供一個(gè)快捷的方式在一個(gè)模組中創(chuàng)建一個(gè)簡(jiǎn)單的宏。</p><p> 點(diǎn)擊工具菜單,指向宏,然后點(diǎn)擊宏。</p><p> 在宏名文本框中輸入你想創(chuàng)建的宏的宏名。如果你不詳
19、創(chuàng)建一個(gè)特殊的模組名,應(yīng)用程序會(huì)自動(dòng)創(chuàng)建一個(gè)叫“modulexx”的模組,而且在這個(gè)模組中存儲(chǔ)你想創(chuàng)建的那個(gè)宏。如果在你指定一個(gè)模組后沒(méi)有再模組在被特別的指定,而且一個(gè)模組已經(jīng)屬于激活狀態(tài),則該宏就會(huì)被放置在那個(gè)模組中。在一個(gè)宏名前面有一個(gè)名稱和一個(gè)點(diǎn),用以在一個(gè)模組中以特定的名稱存儲(chǔ)宏。如果模組并不存在,則實(shí)例會(huì)自動(dòng)創(chuàng)建這個(gè)模組。</p><p> 點(diǎn)擊在宏的位置下拉列表框中的下拉箭頭,選在你想創(chuàng)建該宏的VB
20、A項(xiàng)目。</p><p> 按下Enter鍵或是點(diǎn)擊“創(chuàng)建”</p><p> 宏的子進(jìn)程的框價(jià)結(jié)構(gòu)酒會(huì)出現(xiàn)在代碼窗口中。</p><p><b> 添加模組和類模組</b></p><p> 所有的ArcGIS應(yīng)用文檔都包括了類模組ThisDocument,這是一個(gè)客戶對(duì)象,它能夠表示和VBA項(xiàng)目相聯(lián)系的特定的
21、文檔。這個(gè)文檔對(duì)象在ArcMap中被稱為MxDocument,而在ArcCatalog中則被稱為GxDocument。而Idocument接口提供了進(jìn)入文檔標(biāo)題、類型、累加器,命令集,父應(yīng)用以及Visual Basic項(xiàng)目的入口。</p><p> 模組和類模組能包括不止一個(gè)進(jìn)程:子進(jìn)程、函數(shù)或?qū)傩?。?dāng)你插入一個(gè)進(jìn)程時(shí),你可以選擇進(jìn)程類型和它的范圍。插入一個(gè)進(jìn)程就像創(chuàng)建一個(gè)代碼模板到你輸入代碼的地方一樣。<
22、;/p><p> 每一個(gè)進(jìn)程都有它私有的和公共的范圍。具有私有范圍的進(jìn)程叫做私有進(jìn)程。它對(duì)于那些只包括一個(gè)進(jìn)程的并且具有相同名稱的模組而言是有限制的。如果你聲明了一個(gè)進(jìn)程是公有的,則其他程序和模組也可以調(diào)用它。</p><p> 在進(jìn)程中的變量也許是局部的或是全局的。全局變量在整個(gè)代碼執(zhí)行的時(shí)間內(nèi)都存在,而局部變量只有當(dāng)在進(jìn)程中定義聲明運(yùn)行時(shí)才有效。而當(dāng)下一次你在次執(zhí)行一個(gè)進(jìn)程時(shí),所以的局
23、部變量都需要重新初始化。然而,你可以在一個(gè)進(jìn)程中,通過(guò)定義局部變量在整個(gè)代碼周期中為靜態(tài)變量,來(lái)保持局部變量的值,因此,這樣可以固定它們的值。</p><p> 在已經(jīng)存在的模組中添加進(jìn)程</p><p> 在項(xiàng)目瀏覽器中,雙擊ArcMap對(duì)象,ArcCatalog對(duì)象或是模組文件夾,然后選擇一個(gè)模組的名稱,通過(guò)點(diǎn)擊“View Code ”按鈕可以查看模組的試圖是否屬于激活狀態(tài)。<
24、;/p><p> 點(diǎn)擊“插入”按鈕,然后點(diǎn)擊“進(jìn)程”。</p><p> 在“名稱”文本框中輸入進(jìn)程的名稱。</p><p> 點(diǎn)擊“類型”單選按鈕,通過(guò)點(diǎn)擊選擇進(jìn)程的類型:子進(jìn)程,函數(shù)或是屬性。</p><p> 點(diǎn)擊“范圍”單選按鈕,選擇是其范圍是公有或是私有。</p><p> 聲明所有局部變量為靜態(tài)變量,
25、檢查“All Local variables as Statics”這個(gè)檢測(cè)框。</p><p> 點(diǎn)擊OK,VBA在一個(gè)進(jìn)程里的函數(shù)框顯示在輸入代碼的窗口里,這個(gè)函數(shù)框包括了你所添加進(jìn)程的代碼的起始行和最后一行的內(nèi)容。</p><p><b> 在進(jìn)程中輸入代碼。</b></p><p> 關(guān)于進(jìn)程的更多信息,可以在Microsoft
26、Visual Basic在線幫助里獲得參考。</p><p><b> 添加用戶模式</b></p><p> 如果你想要自己的代碼給用戶提示信息,或者,當(dāng)用戶請(qǐng)求一個(gè)ArcGIS應(yīng)用命令、工具或是對(duì)一些事件的回復(fù)時(shí),你想要顯示一些行為執(zhí)行的結(jié)果,那么就要使用VBA的用戶模式。用戶模式提供一個(gè)聯(lián)系,你可以利用這個(gè)聯(lián)給一系列的集成控制提供入口。一些控制和UICont
27、rols很相似,它們都可以適用于特定對(duì)話框命令標(biāo)簽。有了這些控制,除了文本框和命令按鈕以外,你還可以使用一些附加的控制。一個(gè)用戶模式是一個(gè)包含用戶接口控制的容器,比如命令按鈕和文本框。一個(gè)控制是一個(gè)顯示在一個(gè)用戶模式上的Visual Basic對(duì)象,它具有自己的屬性,方法和事件。使用這些控制來(lái)接收用戶的輸入,顯示輸出,觸發(fā)事件進(jìn)程。同時(shí)也可以將該模式設(shè)置為模組的形式,這樣用戶必須在使用任何應(yīng)用之前進(jìn)行回復(fù),或者也可以設(shè)置為非模型形式,這
28、樣當(dāng)遇到接下來(lái)的代碼時(shí)就會(huì)自動(dòng)執(zhí)行。</p><p> 在用戶模式下添加和啟動(dòng)編碼</p><p> 在項(xiàng)目瀏覽器中,選擇你想添加在一個(gè)用戶模式里的項(xiàng)目。</p><p> 點(diǎn)擊“插入”按鈕,然后點(diǎn)擊“UserForm”。</p><p> VBA插入一個(gè)用戶模式在你的項(xiàng)目中,然后自動(dòng)顯示控制工具框。</p><p
29、> 在工具框中選擇你想添加給用戶的控制工具。</p><p> 對(duì)用戶模式或是上面的控制進(jìn)行編碼。</p><p> 為了顯示用戶模式或是控制的代碼窗口,可以雙擊用戶模板或是各個(gè)控制。然后在事件和進(jìn)程中選擇你想出發(fā)的事件,然后可以在代碼窗口的響應(yīng)事件的代碼區(qū)域內(nèi)書寫代碼?;蛘咧苯釉谝粋€(gè)模組或類模組中插入一個(gè)進(jìn)程,然后在進(jìn)行編碼。</p><p> 如果
30、想在ArcMap或是ArcCatalog期間里對(duì)一些行為做出回復(fù)時(shí),引用它的“Show”方法,例如:</p><p> UserForm1.Show vbModeless 'show modeless</p><p> 關(guān)于VBA項(xiàng)目管理的技術(shù)</p><p> 依靠相關(guān)的技術(shù)可以使工作合理化,這樣在ArcGIS應(yīng)用VBA環(huán)境中的工作將更有效,從而減少
31、了每次啟動(dòng)一個(gè)新任務(wù)而需要的工作量。</p><p> 再次使用模組,類模組和用戶模式</p><p> 在普通模板,項(xiàng)目或是模板項(xiàng)目中添加一個(gè)已經(jīng)存在的模組或是模式時(shí),點(diǎn)擊項(xiàng)目瀏覽器中的目標(biāo)對(duì)象的名稱,然后從“文件”菜單中選擇“導(dǎo)入文件”。這樣可以選擇任意的VBA模組,用戶模式或是類模組來(lái)添加一個(gè)復(fù)制的文件到你的項(xiàng)目中去。同樣也可以從已有的項(xiàng)目中導(dǎo)出一些條目,從項(xiàng)目選擇想要導(dǎo)入到項(xiàng)目
32、瀏覽器的項(xiàng)目,從“文件”菜單中選擇“導(dǎo)出文件”,然后添加到保存該文件的地方。導(dǎo)出一個(gè)項(xiàng)目并不意味著從項(xiàng)目中將其移走。</p><p><b> 移動(dòng)項(xiàng)目項(xiàng)目</b></p><p> 當(dāng)要移動(dòng)一個(gè)項(xiàng)目時(shí),肯定要從項(xiàng)目中將其刪除。但是,如果該項(xiàng)目存在磁盤上時(shí),這個(gè)行為并沒(méi)有刪除這個(gè)文件。在移走一個(gè)項(xiàng)目之前,要保證在其它模組和用戶模式中保留的代碼和已經(jīng)移走的代碼沒(méi)有關(guān)
33、系。要移走一個(gè)項(xiàng)目,首先在項(xiàng)目瀏覽器中搜索出該項(xiàng)目,然后從“文件”菜單中選擇“移動(dòng)名稱”。在移動(dòng)該項(xiàng)目前,將會(huì)被詢問(wèn)是否真的要導(dǎo)出該項(xiàng)目。如果在該對(duì)話框中選擇“是”,則“導(dǎo)出文件”對(duì)話框就會(huì)打開。如果選擇“否”,則VBA就刪除了該項(xiàng)目。</p><p><b> 保護(hù)代碼</b></p><p> 為了防止用戶修改或是查看代碼,可以鎖住一個(gè)項(xiàng)目,模板項(xiàng)目或者甚至是
34、Normal。當(dāng)鎖住一個(gè)項(xiàng)目時(shí),必須在項(xiàng)目瀏覽器中設(shè)置一個(gè)在進(jìn)入該項(xiàng)目前就能看見(jiàn)的密碼。如果想要鎖住一個(gè)項(xiàng)目,可以在項(xiàng)目瀏覽器中右擊該項(xiàng)目,模板項(xiàng)目或是Normal,然后在出現(xiàn)的內(nèi)容菜單中點(diǎn)擊該屬性項(xiàng)目。在屬性對(duì)話框中,點(diǎn)擊“保護(hù)”標(biāo)簽,并且選擇“Lock Project for Viewing”。輸入一個(gè)密碼并且進(jìn)行確認(rèn)。最后,保存ArcMap 和ArcCatalog文件。這樣,當(dāng)再一次打開或是別人打開該文件時(shí),該功臣就被鎖住了。如果
35、其他人想要查看或是編輯該項(xiàng)目時(shí),必須輸入相關(guān)密碼才可以。</p><p><b> 保存一個(gè)VBA項(xiàng)目</b></p><p> VBA項(xiàng)目被存儲(chǔ)在一個(gè)作為基本模板的文件(*.mxt)中,這個(gè)文件或者是普通模板,或者是一個(gè)文檔(*.mxd)。當(dāng)用戶從一個(gè)基本模板中創(chuàng)建一個(gè)新的ArcMap 文檔時(shí),該文檔就會(huì)參考這個(gè)基本模板和它所以的項(xiàng)目。要保存ArcMap 文檔和
36、VBA項(xiàng)目時(shí),從ArcMap 的“文件”菜單中選擇“保存”或是從Visual Basic編輯器里的“文件”菜單中選擇“保存為”這兩個(gè)命令都可以將所有的項(xiàng)目和項(xiàng)目都保存在文件中。在保存好文件之后,它的文件名就會(huì)在瀏覽器中的項(xiàng)目名后面的括號(hào)里顯示出來(lái)。如果要將該文檔另存為一個(gè)模板,則從ArcMap 的“文件”菜單中選擇“另存為”,而且特別指出ArcMap 模板為該文件的存儲(chǔ)類型。</p><p><b>
37、 運(yùn)行代碼</b></p><p> 當(dāng)代碼建立和完善后,你就可以在VBA里運(yùn)行,這樣可以檢測(cè)和調(diào)試。這一部分討論在設(shè)計(jì)階段的Visual Basic編輯器里運(yùn)行代碼。關(guān)于運(yùn)行和調(diào)試VBA程序,比如添加斷點(diǎn),添加注釋,逐步執(zhí)行等信息可以在Visual Basic在線幫助中查詢。</p><p> 在Visual Basic編輯器或是宏對(duì)話框中運(yùn)行代碼</p>
38、<p> 點(diǎn)擊“工具”菜單,選擇“宏”</p><p> 在宏列表中,點(diǎn)擊想要運(yùn)行的宏。</p><p> 如果想要運(yùn)行的宏不在該列表中,則必須保證已經(jīng)選擇了適當(dāng)?shù)捻?xiàng)目:在宏對(duì)話框中的Normal,項(xiàng)目或是模板項(xiàng)目。私有的進(jìn)程在任何菜單或是對(duì)話框中都不會(huì)出現(xiàn)的。</p><p> 在Visual Basic編輯器中只運(yùn)行一個(gè)進(jìn)程</p>
39、<p> 在項(xiàng)目瀏覽器中,打開包含想要運(yùn)行的進(jìn)程的模組。</p><p> 在代碼窗中,在該進(jìn)程代碼中點(diǎn)擊一個(gè)插入點(diǎn)。</p><p> 點(diǎn)擊“運(yùn)行”菜單選擇“運(yùn)行 程序/用戶模式”。只有光標(biāo)標(biāo)住的進(jìn)程才會(huì)被執(zhí)行。</p><p><b> 完成代碼的編輯</b></p><p> 在代碼編輯完之
40、后,用戶可以從ArcMap or ArcCatalog中運(yùn)行該代碼。通過(guò)選擇“工具”菜單中的“宏”可以執(zhí)行該過(guò)程。也可以將代碼和一個(gè)命令或是工具聯(lián)系起來(lái),或者是在回復(fù)一個(gè)事件或是已經(jīng)設(shè)置的其它方式下運(yùn)行代碼。</p><p><b> 使用全局應(yīng)用對(duì)象</b></p><p> Application和ThisDocument是全局系統(tǒng)變量的例子,當(dāng)ArcMap運(yùn)
41、行時(shí),這些變量可以被在VBA中的任意的模式或類所接受。當(dāng)ArcMap打開文檔時(shí),這個(gè)變量是自動(dòng)設(shè)置到當(dāng)前文檔中的。當(dāng)VBA中的程序進(jìn)入當(dāng)前文檔時(shí),可以使用ThisDocument作為快捷鍵。這里有個(gè)使用Application或ThisDocument的例子</p><p> Dim pMxDoc as IMxDocument</p><p> Set pMxDoc =Applicati
42、on.Document</p><p><b> 'or</b></p><p> Set pMxDoc =ThisDocument</p><p> 附件1:外文原文(復(fù)印件)</p><p> Visual Basic for Applications Development Environment&
43、lt;/p><p> The Visual Basic Environment (General) </p><p> http://edndoc.esri.com/arcobjects/8.3/GettingStarted/VBASpecifics.htm</p><p> This topic discusses how to program in the V
44、BA environment to control either ArcMap, ArcCatalog, or ArcScene by accessing the objects they expose. Your code manipulates the objects by getting and setting properties on their interfaces, such as setting the MaximumS
45、cale and MinimumScale of a Map's FeatureLayer; invoking methods on the interfaces, such as adding a vertex to a polyline; or setting a field's value. The code runs when an event occurs, for example, when a user o
46、pens a document, clicks </p><p> Before we learn the knowledge of Visual Basic for Application Development Environment, we firstly learn the conception of Visual Basic for Application.</p><p>
47、 What is Visual Basic for Applications?</p><p> Microsoft Visual Basic for Applications (VBA) is part of the Microsoft Visual Basic family that also includes the Microsoft Visual Basic development system (L
48、earning Edition, Professional Edition, and Enterprise Edition) and Visual Basic Scripting Edition (VBScript). VBA is an embeddable programming environment designed to enable developers to build custom solutions using the
49、 full power of Microsoft Visual Basic. Developers using applications that host VBA can automate and extend the application</p><p> What are the differences between Visual Basic, VBA, and VBScript? When woul
50、d we use one over another?</p><p> Visual Basic is a stand-alone tool for creating separate software components, such as executable programs, COM components and ActiveX Controls, and is useful when you must
51、 build a specialized solution from scratch.VBA offers the same powerful tools as Visual Basic in the context of an existing application, and is the best option for customizing software that already meets most of your n
52、eeds.VBScript is a lightweight version of the Visual Basic language, and is designed specifically for use o</p><p> Which Microsoft applications include Visual Basic for Applications?</p><p>
53、 Visual Basic for Applications 6.3 is a core component in Microsoft Office XP, and is integrated into Microsoft Access, Microsoft Excel, Microsoft FrontPage, Microsoft Outlook, Microsoft PowerPoint, and Microsoft Word.
54、VBA 5.0 is included with Microsoft Office 97 (Access, Excel, PowerPoint, and Word) as well as Microsoft Project 98.</p><p> The VBA development environment</p><p> First you'll see the asp
55、ects of the VBA development environment in which you'll do your work that are specific to the ESRI applications. Consult the Visual Basic Reference, the online help file that displays when you click Microsoft Visual
56、Basic Help in the Help menu of the VBA Editor for generic help on the user interface, conceptual topics, how-to topics, language reference topics, customizing the Visual Basic Editor, and user forms and controls.</p&g
57、t;<p> In the VBA development environment you can add modules, class modules, and user forms to the default project contained in every ArcGIS application document. A project can consist of as many modules, class
58、modules, and user forms as your work requires. A project is a collection of items to which you add code. A module is a set of declarations followed by procedures梐 list of instructions that your code performs. A class mod
59、ule is a special type of module that contains the definition of a class, in</p><p> ArcMap has a default project associated with its document that's listed in the Project Explorer as Project followed by
60、 its filename. In addition, you'll see another project listed in the Project Explorer called Normal (Normal.mxt).</p><p> Normal is, in fact, a template for all documents. It's always loaded into th
61、e document. It contains all the user-interface elements that users see, as well as the class module named ArcID, which contains all the UIDs for the application's commands.</p><p> Since any modificatio
62、ns made to Normal will be reflected every time you create or open a document, you should be careful when making changes to Normal.</p><p> In ArcMap, users can start by opening a template other than the def
63、ault template. These templates are available to them in the New dialog box. From a developer's perspective this is a base template, a document that loads an additional project into the document; it is listed in the P
64、roject Explorer as the TemplateProject followed by its filename. This project can store code in modules, class modules, forms, and any other customizations, such as maps with data, page layout frames, and so on. Any m<
65、;/p><p> In ArcCatalog, Normal (Normal.gxt) is the only project that appears in the Project Explorer. There is no default Project in ArcCatalog, and you can't load any templates. You can, of course, add co
66、de to Normal.gxt inside modules, class modules, or forms, but again, be careful when making changes.</p><p> Once you've invoked the Visual Basic Editor, you can insert a module, class module, or user f
67、orm. Then you insert a procedure or enter code for an existing event procedure in the item's Code window, where you can write, display, and edit code. You can open as many Code windows as you have modules, class modu
68、les, and user forms, so you can easily view the code and copy and paste between Code windows. In addition to creating your own modules, you can import other modules, class modules, or user fo</p><p> If you
69、r work requires it, you can add an external object library or type library reference to your project. This makes another application's objects available in your code. Once a reference is set, the referenced objects a
70、re displayed in the development environment's Object Browser.</p><p> Getting started with VBA</p><p> To begin programming with VBA in ArcMap or ArcCatalog, you start the Visual Basic Edi
71、tor.</p><p> To start the Visual Basic Editor</p><p> Start ArcMap or ArcCatalog. </p><p> Click the Tools menu, point to Macros, then click Visual Basic Editor. You can also use
72、 the shortcut keys Alt+F11 to display the Visual Basic Editor. To navigate among the projects in the Visual Basic Editor, use the Project Explorer. It displays a list of the document's modules, class modules, and use
73、r forms. </p><p> To add a macro to a module</p><p> ArcMap and ArcCatalog both provide a shortcut for creating a simple macro in a module.</p><p> Click the Tools menu, point to
74、 Macros, then click Macros. </p><p> Type the name of the macro you want to create in the Macro name text box. If you don't specify a module name, the application creates a module called modulexx and st
75、ores the macro in that module. If no module is specified after you specify a module, and a module is already active, the macro is placed in that module. Preceding a macro's name with a name and a dot stores it in a m
76、odule with the specified name. If the module doesn't exist, the application creates it. </p><p> Click the dropdown arrow of the Macros in the combo box and choose the VBA project in which you want to c
77、reate the macro. </p><p> Press the Enter key or click Create. </p><p> The stub for a Sub procedure for the macro appears in the Code window. </p><p> Adding modules and class m
78、odules</p><p> All ArcGIS application documents contain the class module ThisDocument, a custom object that represents the specific document associated with a VBA project. The document object is called MxDo
79、cument in ArcMap and GxDocument in ArcCatalog. The IDocument interface provides access to the document's title, type, accelerator table, command bars collection, parent application, and Visual Basic project.</p>
80、;<p> Modules and class modules can contain more than one type of procedure: sub, function, or property. You can choose the procedure type and its scope when you insert a procedure. Inserting a procedure is like
81、creating a code template into which you enter code.</p><p> Every procedure has either private or public scope. Procedures with private scope are limited to the module that contains them梠nly a procedure wit
82、hin the same module can call a private procedure. If you declare the procedure public, other programs and modules can call it.</p><p> Variables in your procedures may either be local or global. Global vari
83、ables exist during the entire time the code executes, whereas local variables exist only while the procedure in which they are declared is running. The next time you execute a procedure, all local variables are reinitial
84、ized. However, you can preserve the value of all local variables in a procedure for the code's lifetime by declaring them static, thereby fixing their value.</p><p> To add a procedure to an existing mo
85、dule</p><p> In the Project Explorer, double-click the ArcMap Objects, ArcCatalog Objects, or Modules folder, then choose the name of a module. Ensure that the code view of the module is active by clicking
86、the View Code button. </p><p> Click the Insert menu and click Procedure. </p><p> Type the name of the procedure in the Name text box. </p><p> Click the Type dropdown arrow and
87、 click the type of procedure: Sub, Function, or Property. </p><p> Click the Scope dropdown arrow and click Public or Private. </p><p> To declare all local variables static, check the All Loc
88、al variables as Statics check box. </p><p> Click OK. VBA stubs in a procedure into the item's Code window into which you can enter code. The stub contains the first and last lines of code for the type
89、of procedure you've added. </p><p> Enter code into the procedure. </p><p> For more information about procedures, see the Microsoft Visual Basic online help reference.</p><p>
90、; Adding user forms</p><p> If you want your code to prompt the user for information, or you want to display the result of some action performed when the user invokes an ArcGIS application command or tool,
91、or in response to some other event, use VBA's user forms. User forms provide a context in which you can provide access to a rich set of integrated controls. Some of these controls are similar to the UIControls that a
92、re available as part of the Customize dialog box's Commands tab. In addition to text boxes or command butto</p><p> To add and start coding in a user form</p><p> In the Project Explorer,
93、select the Project to which you want to add a user form. </p><p> Click the Insert menu and click UserForm. </p><p> VBA inserts a user form into your project and opens the Controls Toolbox. &
94、lt;/p><p> Click the controls that you want to add to the user in from the Controls Toolbox. </p><p> Add code to the user form or to its controls. </p><p> For more information abo
95、ut adding controls, see the Microsoft Visual Basic online help reference.</p><p> To display the Code window for a user form or control, double-click the user form or control. Then, choose the event you wan
96、t your code to trigger from the dropdown list of events and procedures in the Code window and start typing your code. Or, just as in a module or class module, insert a procedure and start typing your code.</p><
97、;p> To display the form during an ArcMap or ArcCatalog session in response to some action, invoke its Show method, as in this example:</p><p> UserForm1.Show vbModeless 'show modeless</p><
98、;p> Some VBA project-management techniques</p><p> To work efficiently in the ArcGIS application's VBA development environment, and reduce the amount of work you have to do every time you start a ne
99、w task, make use of several techniques that will streamline your work:</p><p> Reusing modules, class modules, and user forms</p><p> To add an existing module or form to the Normal template,
100、the Project, or a TemplateProject, click the name of the destination in the Project Explorer, then choose Import File from the File menu. You can choose any VBA module, user form, or class module to add a copy of the fil
101、e to your project. To export an item from your project so that it is available for importing into other projects, select the item you want to export in the Project Explorer, choose Export File from the File menu, then na
102、vi</p><p> Removing project items</p><p> When you remove an item, it is permanently deleted from the project list梱ou can't undo the Remove action; however, this action doesn't delete
103、a file if it exists on disk. Before removing an item, make sure remaining code in other modules and user forms doesn't refer to code in the removed item. To remove an item, select it in the Project Explorer, then cho
溫馨提示
- 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒(méi)有圖紙預(yù)覽就沒(méi)有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 眾賞文庫(kù)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。
最新文檔
- vba for autocad 開發(fā)手冊(cè)
- 設(shè)置php開發(fā)環(huán)境外文翻譯(綠皮書)
- vba開發(fā)autocad實(shí)現(xiàn)參數(shù)化繪圖
- 使用vba進(jìn)行solidworks開發(fā)指南
- autocad二次開發(fā)(vba)
- 環(huán)境成本【外文翻譯】
- 外文翻譯基于asp的開發(fā)
- 環(huán)境會(huì)計(jì)【外文翻譯】
- 軟件開發(fā)外文翻譯
- 培訓(xùn)與開發(fā)【外文翻譯】
- 基于VBA的堤防CAD系統(tǒng)的研究與開發(fā).pdf
- 外文翻譯----struts開發(fā)的最佳實(shí)踐
- 外文翻譯----培訓(xùn)與開發(fā)
- 環(huán)境會(huì)計(jì)【外文翻譯】 (2)
- 環(huán)境與行為外文翻譯
- 環(huán)境貿(mào)易措施【外文翻譯】
- 貿(mào)易與環(huán)境【外文翻譯】
- 軟件開發(fā)外文翻譯(節(jié)選)
- 員工培訓(xùn)與開發(fā)外文翻譯
- 貿(mào)易增長(zhǎng)與環(huán)境【外文翻譯】
評(píng)論
0/150
提交評(píng)論