Code Red > VB(A)

VBScript for ArcPad

(1/1)

CHulse:
Does anyone here use VBS to customize Arcpad for data collection?
I've been using it for collecting tree data.

Does anyone have an example of how to parse numbers from a text string, run a calculation and replace the result in the string?

Thanks

roy_043:
I do not know Arcpad. But here is a VBS example.
To test the code: save with the .vbs extension and double-click the file.

--- Code - vb.net: ---Dim inp, matches, newVal, oldVal, reginp = InputBox("Enter text with number")Set reg = New RegExpreg.Pattern = "\d+\.?\d+(?=\D*)"   ' Change "\." to "," if required.Set matches = reg.Execute(inp)If 0 <> matches.Count Then  oldVal = matches(0).Value  newVal = oldVal + 15             ' Add 15. No need to convert oldVal to a number or newVal to a string.  MsgBox(Replace(inp, oldVal, newVal, 1, 1))Else  MsgBox("No number found")End If

CHulse:
Thanks. I was able to figure out what I needed using an array.


--- Code - vb.net: ---'' increase DBHSub DBHPLUS  Dim objTheLayer, objTheForm, objEditFormCtrls, strDBH, aa, ub  Set objTheLayer = Application.Map.Layers.item(1)  Set objTheForm = objTheLayer.Forms(1)  Set objEditFormCtrls = objTheForm.Pages("PAGE1").Controls    If (objEditFormCtrls("txtDBH").value = "") Then      objEditFormCtrls("txtDBH").value = 1    Else      'get DBH string form form field      strDBH = objEditFormCtrls("txtDBH").value      'remove all spaces      strDBH = Replace(strDBH," ","",1,-1)      'create array using comma delimeter      aa = split (strDBH, ",", -1, 1)      'get upper limit od array      ub = ubound(aa)      'convert last entry to integer and add one      aa(ub)= 1 + cint(aa(ub))      'rebuild string from array adding commas      strDBH = Join (aa, ",")      'pass new string to form field      objEditFormCtrls("txtDBH").value = strDBH    End If   'Free objects  set aa = nothing  set ub = nothing  set strDBH = Nothing  Set objEditFormCtrls = Nothing  Set objTheForm = Nothing  Set objTheLayer = NothingEnd Sub 

roy_043:
As mentioned in one of the comments in my suggestion: you do not have to use the CInt function. But If you do, wouldn't it then make sense to also use CStr?

CHulse:

--- Quote from: roy_043 on August 14, 2017, 11:12:56 AM ---As mentioned in one of the comments in my suggestion: you do not have to use the CInt function. But If you do, wouldn't it then make sense to also use CStr?

--- End quote ---

Interesting point. I don't really know. I've used something similar for excel and the type conversion was needed, so I assumed I'd need it here. I believe I've read that JOIN returns a string regardless of input, so I don’t think the CStr is needed. I'll need to test it without the Cint to see.

Navigation

[0] Message Index

Go to full version