ArcPad Scripting Object Model
ShowOpen Method
See Also  Example  Send comments on this topic.
DefExt
Optional. A String that represents the DefExt.
Filter
Optional. A String that represents the Filter.
Title
Optional. A String that represents the Title.
Flags
Optional. A Long that represents the Flags.
CommonDialog Object : ShowOpen Method

Glossary Item Box

Description

Displays the standard Open dialog box.

Syntax

object.ShowOpen ( [DefExt] [,Filter] [,Title] [,Flags] )

Parameters

DefExt
Optional. A String that represents the DefExt.
Filter
Optional. A String that represents the Filter.
Title
Optional. A String that represents the Title.
Flags
Optional. A Long that represents the Flags.

Return Type

Variant

Remarks

DefExt is a string representing the file extension that is appended to the filename if the user fails to type an extension. This string can be any length, but only the first three characters are appended. The string should not contain a period (.). [Optional].

Filter is string representing the filter pattern(s) that are applied and displayed in the Files of type combo box. Each filter pattern consists of a pair of strings separated by a pipe (|) (for example, "Text Files | *.txt"). The first string describes the filter (for example, "Text Files") and the second string specifies the filter pattern (for example, "*.txt"). To specify multiple filter patterns for a single description string, use a semicolon to separate the patterns (for example, "*.txt;*.doc;*.wpd"). [Optional].

Title is a string representing the dialog caption. "Open" is used if no title is specified. [Optional].

Flags is a long representing a set of bit flags that can be used to initialize the dialog box. Multiple Flags can be combined using the OR operator. [Optional].

The following Flags are supported:

Flag (hexadecimal value) Description
4 Hides the Read Only checkbox.
8 Forces the dialog box to set the current directory to what it was when the dialog box was opened
800 Specifies that the user can enter only valid paths in the File Name text box. If this flag is set and the user enters an invalid path, a warning message is displayed.
1000 Specifies that the user can enter only names of existing files in the File Name text box. If this flag is set and the user enters an invalid file name, a warning is displayed. This flag automatically sets the 8 flag.
2000 Specifies that the dialog box should prompt the user to create a file that does not currently exist.

Example

Prompts the user for a PRJ file and sets the map's coordinate system based on the selected PRJ file.
CoordinateSystem Example (VBScript)Copy Code
Sub SetMapProjection
      'Prompt the user to select a PRJ file
      Dim txtPRJFile
      txtPRJFile = CommonDialog.ShowOpen("prj", "Projection files|*.prj", "Select new map projection")
      
      'If Cancel button is pressed, exit
      If IsEmpty(txtPRJFile) Then
            Exit Sub
      End If

      'Create a CoordSys object and import the selected PRJ file
      Dim pCS
      Set pCS = Application.CreateAppObject("CoordSys")
      pCS.Import txtPRJFile
      
      'Set the map's coordsys to the selected PRJ file's coordsys
      Set Map.CoordinateSystem = pCS
      
      'Display the new map projection
      MsgBox "The map projection is now: " & vbCrlf & Map.CoordinateSystem.String, vbInformation, "Current map projection"
      
      'Clean up
      Set pCS = Nothing
End Sub
Reprojects a layer to the projection selected by the user. A new shapefile is created for the reprojected layer.
Reproject Example (VBScript)Copy Code
Sub ReProjectLayer (pLayer)
      'Get the new projection from the user
      Dim strPRJFile
      strPRJFile = CommonDialog.ShowOpen("prj", "Projection files|*.prj", "Select new projection")
      If IsEmpty(strPRJFile) Then
            Exit Sub
      End If

      'Create a CoordSys object with the selected PRJ file
      Dim pCS
      Set pCS = Application.CreateAppObject("CoordSys")
      pCS.Import(strPRJFile)

      'Get pLayer's RecordSet and Fields objects
      Dim pRS, pFields
      Set pRS = pLayer.Records
      Set pFields = pRS.Fields
      
      'Create a new shapefile to store the projected layer
      'Use pLayer's schema in the new shapefile
      Dim pNewRS, pCurrField, strNewSHPFileName
      strNewSHPFileName = Application.System.Properties("PersonalFolder") & "\" & pLayer.Name & "_prj.shp"
      Set pNewRS = Application.CreateAppObject("RecordSet")
      pNewRS.Create strNewSHPFileName, pFields.ShapeType, pCS
      For Each pCurrField In pFields
            pNewRS.Fields.Append pCurrField.Name, pCurrField.Type, pCurrField.DefinedSize, pCurrField.NumericScale
      Next
      
      'Iterate through all records in pLayer's recordset
      pRS.MoveFirst
      While Not pRS.EOF
            'Ignore records flagged for deletion
            If Not pRS.IsDeleted Then
                  'Write the current record's bookmark to the status bar
                  Application.StatusBar.Text = "#" & CStr(pRS.Bookmark)
                  'Add a new record to the new shapefile containing the current record's shape
                  'The shape's coordinates will automatically be reprojected to the projection of the new shapefile
                  pNewRS.AddNew pRS.Fields.Shape
                  'copy over all the attribute values to the new record of the new shapefile
                  For Each pCurrField In pFields
                        pNewRS.Fields(pCurrField.Name).Value = pCurrField.Value
                  Next
                  'Update the new record of the new shapefile to save the changes
                  pNewRS.Update
            End If
            pRS.MoveNext
      Wend

      'Clean up
      Set pCS = Nothing
      Set pRS = Nothing
      Set pFields = Nothing
      Set pNewRS = Nothing
      Set pCurrField = Nothing
      
      'Let the user know the process is complete
      MsgBox "Reprojection Complete.", vbInformation, "Reproject Tool"
End Sub
Gets an ArcPad map or layer file (via Open dialog box) and adds it to the current map.
ShowOpen Example (VBScript)Copy Code
Sub AddLayerExample
  Dim strDefExt, strFileFilter, strTitle, lngFlags, varResult
  'Set the arguments of the Open dialog box
  strDefExt = "apl"
  strFileFilter = "ArcPad Maps|*.apm|ArcPad Layers|*.jpg;*.shp;*.sid"
  strTitle = "Select ArcPad Data"
  lngFlags = &H1000   'only allow existing files to be specified
  'Show the Open dialog box and get the result
  varResult = CommonDialog.ShowOpen(strDefExt,strFileFilter,strTitle,lngFlags)
  'If a file is selected, add it to the map and refresh the map  
  If Not IsEmpty (varResult) Then  
    Application.Map.AddLayerFromFile (varResult)  
    Application.Map.Refresh
  End If
End Sub

See Also

© 2012 All Rights Reserved.