【文章內(nèi)容簡介】
ment ? 創(chuàng)建用戶交互窗體( Form) ?構建比 message boxes and input boxes更復雜的用戶界面 Introduction to Programming ArcObjects with VBA Copyright 169。 2020, 2020 ESRI. All rights reserved. 252 Working with forms ? Form = window of controls + associated code Form Designer Properties window Toolbox Code module Introduction to Programming ArcObjects with VBA Copyright 169。 2020, 2020 ESRI. All rights reserved. 253 Setting properties at design time ? Select a control ? View or change properties with the Properties window ?Appearance: Caption, Font, BackColor ?Behavior: TabIndex, Locked, Enabled ?NAME Introduction to Programming ArcObjects with VBA Copyright 169。 2020, 2020 ESRI. All rights reserved. 255 Writing code for a form ? UserForms 由一個設計器和一個代碼模塊組成 ? 雙擊一個 control 去展開它的代碼 ?Each control on a form has several event procedures Code Module Form Designer Introduction to Programming ArcObjects with VBA Copyright 169。 2020, 2020 ESRI. All rights reserved. 256 Using control properties at run time ? Get/Set properties with code while the form is running ? Syntax: ?Controls are objects Private Sub cmdApply_Click() strFTemp = ( * 9 / 5 ) + 32 = Fahrenheit: amp。 strFTemp End Sub Introduction to Programming ArcObjects with VBA Copyright 169。 2020, 2020 ESRI. All rights reserved. 257 When: Form and control events ? Code runs when an event fires ? Different controls have different sets of events ?Form events Introduction to Programming ArcObjects with VBA Copyright 169。 2020, 2020 ESRI. All rights reserved. 259 When: Map document events ? Available in the ThisDocument module ? Normal, base template, or current map (.mxd) ? Event procedures for the MxDocument object ?Open, close, new, change, etc. Object List Procedure List Introduction to Programming ArcObjects with VBA Copyright 169。 2020, 2020 ESRI. All rights reserved. 261 Saving your work ? Save modules with a document ?ArcCatalog normal template ?ArcMap normal template ?ArcMap template (*.mxt) ?Map document (*.mxd) ? Export modules ?Form file (*.frm): designer and code ?Standard and class modules ?Can be imported into other projects Introduction to Programming ArcObjects with VBA Copyright 169。 2020, 2020 ESRI. All rights reserved. 262 Exercise 3 overview ? Create a form ? Set initial control properties ? Test and debug the form ? Work with preset variables ?Application ?ThisDocument ? Save your work Copyright 169。 2020, 2020 ESRI. All rights reserved. Introduction to Programming ArcObjects with VBA Using variables( III) Introduction to Programming ArcObjects with VBA Copyright 169。 2020, 2020 ESRI. All rights reserved. 264 在 VBA中使用變量 ? 變量定義 ? 使用變量 : 申明 , 賦值 , 比較 ? 過程的參數(shù)傳值和返回值 ? 比較兩個變量的值 ? 分支 : 判斷語句 ? 變量的作用域 Introduction to Programming ArcObjects with VBA Copyright 169。 2020, 2020 ESRI. All rights reserved. 265 Variables ? An empty box for storing values ?Of a specific type (integer, date, string, etc.) ?The value stored can change 39。the VB version of: a178。 + b178。 = c178。, is … dblCSquare = (dblA * dblA) + (dblB * dblB) ?轉(zhuǎn)換溫度的計算 … intTempCelsius = InputBox (Enter temperature (C): ) intTempFahrenheit = (intTempCelsius * ) + 32 Introduction to Programming ArcObjects with VBA Copyright 169。 2020, 2020 ESRI. All rights reserved. 266 Working with variables ? Declaring: Create a variable ? Setting: Store a value ? Evaluating: Get the value MsgBox myDog myDog = Sparky Dim myDog As String myDog Sparky myDog Sparky myDog Sparky A Introduction to Programming ArcObjects with VBA Copyright 169。 2020, 2020 ESRI. All rights reserved. 268 Dim (dimension) statement ? 申明一個變量 ? 指定變量的類型 39。Declare variables Dim strFilePathName As String Dim datSparkysBirthday As Date Dim intCount As Integer 39。Other ways to declare variables (to be discussed later).. Private strFilePathName As String Public datSparkysBirthday As Date Static intCount As Integer Introduction to Programming ArcObjects with VBA Copyright 169。 2020, 2020 ESRI. All rights reserved. 270 變量賦值 ? 直接賦值或通過返回值賦值 ?如果是一個功能過程的返回值賦值,使用圓括號 39。Assign values directly intCount = 23 39。Assign a function return value strFilePathName = InputBox(File to open: ) 39。Assign an object property strMapName = ! Introduction to Programming ArcObjects with VBA Copyright 169。 2020, 2020 ESRI. All rights reserved. 272 Function procedures ? Functions return a value ?… by assigning a value to the function name ?Syntax for calling a function: Value = Function ( arguments ) 39。Call the TotalPrice function Private Sub Purchase() dblPrice = InputBox (Enter price before tax:) dblTotal = TotalPrice(dblPrice) MsgBox Here is the price including tax: amp。 dblTotal End Sub 39。The function procedure TotalPrice Private Function TotalPrice(Price As Double) As Double TotalPrice = Price * End Function Introduction to Programming ArcObjects with VBA Copyright 169。 2020, 2020 ESRI. All rights reserved. 274 比較變量的值 ? Use relational operators ( , , , = ) ?Return a Boolean result (true/false) ? Functions ?IsDate ?IsNumeric ?IsNull ?TypeName intAnswer = MsgBox (Delete File?, vbYesNo) MsgBox intAnswer = vbYes MsgBox Number? amp。 IsNumeric(VagueVariable) strType = TypeName (VagueVariable) MsgBox Variable is of data type amp。 strType Introduction to Programming ArcObjects with VBA Copyright 169。 2020, 2020 ESRI. All rights reserved. 276 判斷語句 : The If Then statement ? 根據(jù)條件分支執(zhí)行 ?Use a Boolean expression ?作出決定如何執(zhí)行 If intLayerCount 1 Then MsgBox There are no layers in your map!, vbExclaimation End If 39。Syntax example: If a condition is true Then 39。do something... End If ? Introduction to Programming ArcObjects with VBA Copyright 169。 2020