|
POST
|
Sub CopyFields(pInRow As IRow, pOutRow As IRow)
Dim lInFld As Long
Msgbox (pInRow.Fields.FieldCount) <--- INSERT THIS LINE
For lInFld = 0 To pInRow.Fields.FieldCount �?? 1 <--- This line causes trouble!
Dim lOutFld As Long
lOutFld = pOutRow.Fields.FindField(pInRow.Fields.Field(lInFld).Name)
If lOutFld > -1 Then
If pInRow.Fields.Field(lInFld).Editable Then
If pInRow.Fields.Field(lInFld).Type <> esriFieldTypeGeometry Then
pOutRow.Value(lOutFld) = pInRow.Value(lInFld)
End If
End If
End If
Next lInFld
End Sub
... View more
01-31-2011
11:12 AM
|
0
|
0
|
758
|
|
POST
|
Does this happen during the first time around the loop? and also, is the fieldcount = 0 off the bat?
... View more
01-31-2011
11:00 AM
|
0
|
0
|
758
|
|
POST
|
Wow, that's a long list of questions. Alright... let me try to address some of them. >> If a sub doesn't return a value like a function, then how can they be using a sub instead to do what a function does? -- Well, they're are both used to structure code and if necessary repeat blocks of code. A sub doesn't have to RETURN a value explicitly to the original SUB it was called from to change or assign a value. (Google search ByVal vs ByRef). Ex. Say you have a form with a textbox that is used to display some result from a calculation (a number). So you have a click event (a command button in the form). A click event is a sub (which stands for subroutine) itself. Private Sub cmdBtnCalc_Click()
Call CalculateValue
End Sub
Private Sub CalculateValue
Dim Num1 as Integer
Set Num1 = 2
Dim Num2 as Integer
Set Num2 = 6
Set frmTest.TBCalcValue.Text = Num1 * Num2
End Sub
So in the above code, the textbox would be changed to display 12. I just performed a calculation using a SUB. The same code could be modified to change the textbox using a function: Private Sub cmdBtnCalc_Click()
Dim Num1 as Integer
Set Num1 = 2
Dim Num2 as Integer
Set Num2 = 6
frmTest.TBCalcValue.Text = CalculateValue (Num1, Num2)
End Sub
Private Function CalculateValue (ByVal Num1 as Integer, ByVal Num2 as Integer) as Integer
CalculateValue = Num1 * Num2
End Function
The two examples of code I've used essentially do the same thing but in different ways using different methods. It's up to you as a programmer to determine what the best and most efficient course of action is for your programming needs. >> If it is a Sub or Function that will be called on many times either in a single module or multiple modules, it should be stored in a public module. (or stored in ThisDocument at Project level?) How do you know when to use a module or ThisDocument (which is a module)? -- Generally, if you think you might have to use procedures (subs) and functions anywhere in the program either in modules, forms, or ThisDocument, or all of em multiple times, it's a good idea to go Public. Just to be safe. But if it is staying within a module, then make it Private. As in, if you have a block of code which is only used in a certain form, then have that code in the FORM code and make it private. However, if you need that same code for MULTIPLE FORMS, then put that code in a MODULE, and make it PUBLIC so it can be accessed by ALL THE FORMS in your program. If you put something in the PROJECT Level and save that document, the code is only applied to that specific document. If you have it under NORMAL then it is universal to any document you open within that program. So if you want ArcMap TO Open to your company's specific map template each time you open a new instance of a ArcMap, then you would put this code in NORMAL. If you have a certain project you're working on that requires VBA coding to change/update the date textbox in your map to the current date and time then you would put such code in the PROJECT level and save it. Anyway the other questions: 1. Sub or function will do for this. Again, depends on your needs. 2. Function generally (nothing is really set in stone..but it'd be good practise). 3. Sub 4. Conditional statements are separate from Subs and Functions. They are another form of code blocks that go WITHIN Subs or Functions. They simply allow you manipulate or do whatever you want to the data based on a condition. It isn't exclusive to neither Sub or Function.... Say you're passing 2 numbers to be calculated in a function. When in that Function, you can check to see if a number is less than 10. If it is, it will calculate using a different formula and return a value back to the procedure it was called from. (Functions can also be called from other Functions). In GIS, I've never used reports so perhaps someone else can comment on that. But the structure and passing variables from one form (which is a module) to another is basically the same. If you have a click event, then you for sure have at least 1 SUB in your program. >>What if you have a set of procedures that all run on an Event? Would you put it in a Public Module and call on the Module instead of the (subs & functions) Ex. a specialized Buffering method that a company want's all employees to use and you would put it on the Toolbar (IUEditBoxControl). Would be saved in ThisDocument under Normal (Global) -- A Module is just a holder or container for all of your code. So if you want to run a bunch of procedures sequentially, then you would call them from a click event one by one. EX: Private Sub cmdBtn_Click()
Call Sub1
Call Sub2
Call Sub3
End Sub For the template question refer to this link. It has the ArcMap VBA code to add a textbox to the Layout view. You have to specify the X Y location on the map document though. http://edndoc.esri.com/arcobjects/9.0/Samples/ArcMap/AddTextElement.htm Cheers,
... View more
01-31-2011
09:26 AM
|
0
|
0
|
4067
|
|
POST
|
With ArcGIS10 you need the Engine license to use mapcontrols. It's something everyone is complaining about. There are some ways around it. http://forums.arcgis.com/threads/22020-Migrating-from-9.3.1-to-10-may-be-impossible-if-you-use-mapcontrols-in-ArcMap cheers,
... View more
01-28-2011
10:41 AM
|
0
|
0
|
264
|
|
POST
|
That's correct. The code above needs a layer assigned..but since you don't need that, try this code. It's actually a snippet in included with the ESRI .NET SDK so it should be in your VS IDE. ' This snippet is intended to be inserted at the base level of a Class.
' It is not intended to be nested within an existing Function or Sub.
'
'''<summary>Deletes from a specified directory that match a certain pattern.</summary>
'''
'''<param name="filePath">A System.String that is the file and path from where to delete files. Example: "C:\temp"</param>
'''<param name="pattern"> A System.String that is the pattern for files to delete. Example: "*.txt" or "myfile.*" or "*.*"</param>
'''
'''<remarks>All files meeting the pattern will be deleted from the specified directory.</remarks>
Public Sub DeleteFilesFromDir(ByVal filePath As System.String, ByVal pattern As System.String)
Dim directoryInfo As System.IO.DirectoryInfo = New System.IO.DirectoryInfo(filePath)
Dim files As System.IO.FileInfo() = directoryInfo.GetFiles(pattern)
For Each file As System.IO.FileInfo In files
file.Delete()
Next
End Sub
... View more
01-28-2011
10:32 AM
|
0
|
0
|
1340
|
|
POST
|
That code you've posted is universal to VB... It doesn't have to be ArcGIS. But basically, the Variable declared at the top (Private) is only exposed to that module. Other modules cannot see nor use that Variable. However, it is a global variable within the module. The Public Subs in that code is exposed to the entire program and all of it's modules. Those subs can be used in any form/module/class. "Private strName As String" is the same as writing "Dim strName as String" You cannot however write the former inside a code block (a Sub or a Function)... you have to use Dim. Cheers,
... View more
01-28-2011
09:51 AM
|
0
|
0
|
4067
|
|
POST
|
This is the old VBA code to delete the shapefile. Add the appropriate references and modify the code to suit your needs in .NET. Private Sub DeleteDataset()
Dim pMxDocument As IMxDocument
Dim pMap As IMap
Dim pFeatureLayer As IFeatureLayer
Dim pFeatureClass As IFeatureClass
Dim pDataset As IDataset
Dim pActiveView As IActiveView
Set pMxDocument = ThisDocument
Set pMap = pMxDocument.FocusMap
' Define the dataset to be deleted.
Set pFeatureLayer = pMap.Layer(0)
Set pFeatureClass = pFeatureLayer.FeatureClass
' Remove the layer from the active map.
pMap.DeleteLayer pFeatureLayer
' Delete the dataset.
Set pDataset = pFeatureClass
pDataset.Delete
' Refresh the map.
Set pActiveView = pMap
pActiveView.Refresh
End Sub Cheers,
... View more
01-28-2011
09:43 AM
|
0
|
0
|
1340
|
|
POST
|
Well, VBA is the same across pretty much all platforms. The interfaces used in each program differ but the language and the structure is the same. For instance, ThisDocument in Access references the current document being worked on and ThisDocument in ArcMap references to the current Map document being worked on. Think of Subs (also called Procedures) and Functions as blocks of code that do specific tasks. You only need to launch these things when they are necessary. You do this by calling them sub. Say you have a listbox in Access that needs to be populated with a bunch of records from a certain column in a table. However, you only do this when the user presses a button on the form. So you would put that code in a Sub Private Sub PopulateListbox Put the code to populate the list box here. End Sub you would call the above listbox from the ClickEvent of the button on the form that the user pressed. A function is pretty much like a programmable calculator (though, it can be used for other things as well besides calculations). But it has to return something.
Private Function Pythagorean(ByVal intA As Integer, ByVal intB As Integer) As Double
Dim answer As Double
answer = (intA ^ 2) + (intB ^ 2)
Pythagorean = answer
End Function So if you want to populate a variable from within a Sub by using a function, you can. Private Sub PythTheory
Dim A as Integer
Dim B as Integer
Dim C as Integer
Set A = 2
Set B = 3
' This is where you call the function to calculate C (from above)
Set C = Pythagorean(A, B)
' so you pass the function 2 and 3 and it will return the sum of the squares.
End Sub It's very important you grasp these basic rules of programming before you attempt ArcObjects as it is far more complex. This is an excellent book I used to help me when I was learning ArcObjects. There might be a PDF of the book on the web.. or you can use Google Books. http://www.amazon.ca/Programming-ArcObjects-VBA-Task-Oriented-Approach/dp/0849392837 Cheers,
... View more
01-27-2011
11:02 AM
|
0
|
0
|
4067
|
|
POST
|
Hey Virginia, Try out this link... http://www.your-save-time-and-improve-quality-technologies-online-resource.com/vba-private-sub.html I'm assuming you use VBA (since you mentioned ThisDocument). I use VB.NET but the concepts are pretty similar with regards to ArcObjects. In any given program you might have a number of Procedures (Sub) or Functions. If you have your code in a modular fashion (broken up into components), then you have to decide whether to make it Public or Private. If you plan to use a repetitive bit of code to return a value (say A + B = C, where you send the function values of A and B and it returns C) throughout many modules in the same program, you would make this a PUBLIC Function. If you only plan to use it in the same module, then you are better of making it Private. This applies for variables as well. If you declare a GLOBAL variable as Public or Private, then you're just assigning the extent of that variable within your program. Any procedure WITHOUT Public or Private is the same as PUBLIC. And here's a link to illustrate the answer to your final question: http://www.getdotnetcode.com/gdncstore/free/Articles/Sub%20Statement%20vs%20Function%20Statement.htm Hope that helps, Cheers
... View more
01-27-2011
06:46 AM
|
0
|
0
|
4067
|
|
POST
|
What I did was simply modified the interface to have the Snippet Finder in my tool bar (command button). Works the same!
... View more
01-27-2011
03:11 AM
|
0
|
0
|
1637
|
|
POST
|
Hey All, Please refer to the attached screenshot for further clarification. I'm trying to make a simple application that searches items from a listbox (the listbox is populated with the layer names using ArcObjects code from another module). However, when i attempt to work with the objects of the form (the listboxes and such), I get this annoying error. Does anyone have any thoughts on how to fix this error or even clarify for me what is actually happening. Thanks,
... View more
01-26-2011
09:39 AM
|
0
|
3
|
1243
|
|
POST
|
The company I'm currently working for is looking to upgrade to 10 in the near future and this will definitely be a deterrent. Wonder what motivated this requirement for an additional license for map controls...
... View more
01-26-2011
08:50 AM
|
0
|
0
|
553
|
|
POST
|
Alex, you have bailed me out yet again on these forums! Thank you! Furthermore, if I were to be dealing with just tabular data (without any spatial attributes), would it be better (more efficient) to use the OLEdB connection interface in .NET (ADO.NET)?. Thanks,
... View more
01-25-2011
05:11 AM
|
0
|
0
|
969
|
|
POST
|
It's been a while since I've used any of those interfaces but I think AccessWorkspaceFactory is used more for tabular data while oleDBWorkspaceFactory works with GeoDatabases which can store features. Perhaps someone else can elaborate on this further (or correct me because I might be wrong). I'm kind of curious now too.
... View more
01-25-2011
04:32 AM
|
0
|
0
|
969
|
| Title | Kudos | Posted |
|---|---|---|
| 1 | 08-30-2013 09:41 AM | |
| 4 | 01-09-2018 12:33 PM | |
| 2 | 10-06-2014 03:14 PM | |
| 2 | 08-13-2015 09:45 AM | |
| 1 | 08-14-2015 08:51 AM |
| Online Status |
Offline
|
| Date Last Visited |
08-12-2023
04:34 AM
|