Select to view content in your preferred language

MsgBox problem

788
5
10-08-2010 04:55 AM
BBulla
by
Regular Contributor
Hi,

I have some code that saves data in a form to a dbf.  That all works fine.  At the end of my code I have a message box pop up to tell the users what to do next:

Sub Save
.
.
.

msgbox "Hit the Refresh Button to update Symbology."
layer.forms("frmJETTING").close
end sub

The first time I do a save this all works fine, but for any subsequent saving of the data this messagebox doesn't appear.  I have no idea why.  I don't get any error messages, and all the code after the msgbox line works.

Any ideas??
Tags (3)
0 Kudos
5 Replies
JakubSisak
Honored Contributor
It's possible your procedure is crashing before it gets to the message box. Debug and step trough the code. Put a breakpoint on the msgbox line and if the code does not pause on the breakpoint then your problem is in the code prior. Set your break point in the beginning of the procedure and use F8 to step through line by line until you find where its crashing. Optionally, you can set up a trap and set a break point inside the trap, then use "resume next" to get to the line that generated the error. (once the error has been trapped you can get the error number and description from the immediate window by typing ?err.number or ?err.desc etc.)
0 Kudos
BBulla
by
Regular Contributor
Hi Jakub,

Well the last line of code in the sub is to close the form, and that IS happening, so I'm positive that the code isn't crashing.

How do I debug my script in ArcPad Application Developer??  Or should I be using something else?  I have Visual Studio but can't seem to get it to debug a vbs.
0 Kudos
GarethWalters
Deactivated User
ArcPad Studio doesn't have the notion of BreakPoints, the best way to see what is/and is not firing is write to things to the console. eg Console.print("Going in to the loop...") or Console.print(myCalculation).

Stick these throughout your code to help your testing.

I hope this helps.

Also Could you post the whole sub routine up if you want anymore help.

Cheers,

Gareth
0 Kudos
BBulla
by
Regular Contributor
That doesn't seem like an efficient way to debug, but I guess that is the best option when using ArcPad Studio. 

Anyways, here is my code if anyone can help figure it out.  Basically after a user Identifies a piece of Sewer, a form pops up with some fields to populate.  When they hit save, this is what happens.  The msgbox near the end will only show itself the first time, then never again for subsequent save actions.  This is in the shapefile script.


sub SaveJetting

    dim facilityID, fromMH, toMH, length, diameter, material, gridNo, rodded, dragged, flushed, photoed, pluggedMain, footage, municipality, depot
    
    'take all the fields on the Jetting Form and assign them to a variable
    set facilityID = layer.forms("frmJetting").pages("Page1").controls("txtFacilityID")
    set fromMH = layer.forms("frmJetting").pages("Page1").controls("txtFrom")
    set toMH = layer.forms("frmJetting").pages("Page1").controls("txtTo")
    set length = layer.forms("frmJetting").pages("Page1").controls("txtLength")
    set diameter = layer.forms("frmJetting").pages("Page1").controls("txtDiameter")
    set material = layer.forms("frmJetting").pages("Page1").controls("txtMaterial")
    set gridNo = layer.forms("frmJetting").pages("Page1").controls("txtGridNo")
    set rodded = layer.forms("frmJetting").pages("Page1").controls("chkRodded")
    set dragged = layer.forms("frmJetting").pages("Page1").controls("chkDragged")
    set flushed = layer.forms("frmJetting").pages("Page1").controls("chkFlushed")
    set photoed = layer.forms("frmJetting").pages("Page1").controls("chkPhotoed")
    set pluggedMain = layer.forms("frmJetting").pages("Page1").controls("chkPluggedMain")
    set footage = layer.forms("frmJetting").pages("Page1").controls("chkFootage")
    set municipality = layer.forms("frmJetting").pages("Page1").controls("txtMuni")
    set depot = layer.forms("frmJetting").pages("Page1").controls("txtDepot")

    'use the ArcPad 'DataPath' as the path to all the files that need to be edited
    Dim inpath, datestring
    inpath = Preferences.Properties("DataPath")    
    
    Dim rs
    'THIS IS TO WRITE TO THE DBF
    
    Set rs = Application.CreateAppObject("Recordset")
    Call rs.Open(inpath & "\JETTING.dbf", 2)
    rs.addnew
    rs.fields("FACID").value = facilityID.value
    rs.fields("JETDATE").value = day(date) & "/" & month(date) & "/" & year(date)
    rs.fields("JETTIME").value = FormatDateTime(now(), 3)
    rs.fields("FROMMH").value = fromMH.value
    rs.fields("TOMH").value = toMH.value
    rs.fields("LENGTH").value = length.value
    rs.fields("DIAMETER").value = diameter.value
    rs.fields("MATERIAL").value = material.value
    rs.fields("GRIDNO").value = gridNo.value
    rs.fields("RODDED").value = rodded.value
    rs.fields("DRAGGED").value = dragged.value
    rs.fields("FLUSHED").value = flushed.value
    rs.fields("PHOTOED").value = photoed.value
    rs.fields("PLUGGED").value = pluggedMain.value
    rs.fields("FOOTAGE").value = footage.value
    rs.fields("SANSTORM").value = "SAN"
    rs.fields("MUNI").value = municipality.value
    rs.fields("DEPOT").value = depot.value
    rs.Update
    rs.Close
    set rs = nothing
    '**************************


    'this will update the shapefile DBF in order to change the symbology
    Set rs = Application.CreateAppObject("Recordset")
    Call rs.Open ("H:\DSM Applications\Jetting Card\GISADMIN_GravitySewer.dbf", 2)  '(inpath & "\GISADMIN_GravitySewer.dbf", 2)

    'search for the current records FacilityID
    dim dbfQuery, editRecord
    dbfQuery = "[FACILITYID] = """ & facilityID.value & """"
    editRecord = rs.find(dbfQuery)

    'edit the record by adding the current date to the JETTED field
    if (editRecord > 0) then
        rs.movefirst
        rs.move(editRecord - 1)
        rs.fields("JET").value = day(date) & "/" & month(date) & "/" & year(date)
        rs.Update
        rs.Close        
    end if

    set rs = nothing
    
    'msgbox "Hit the Refresh Button to update Symbology."

    layer.forms("frmJETTING").close   

end sub



What I am noticing is that after a user hits the 'Refresh' button I have created (allows the map to update it's symbology) then msgbox will show up the next time the user hits Save.  Here is the code for the refresh button.  It basically closes and opens the apm again.  This is in an apa.

sub refresh
     dim inpath
     inpath = Preferences.Properties("DataPath")    
      if gps.isopen = True then
         application.map.save(inpath & "\" & "Inspections.apm")
        application.map.clear
        application.map.open(inpath & "\" & "Inspections.apm")
        Application.ExecuteCommand("gpsenable") 
     else
         application.map.save(inpath & "\" & "Inspections.apm")
        application.map.clear
        application.map.open(inpath & "\" & "Inspections.apm")
     End If 
end sub
0 Kudos
EricHajek1
Regular Contributor
This is a long shot (don't know exactly what could be causing this) but you might try adding another argument to the MsgBox.

For instance:
msgbox "Hit the Refresh Button to update Symbology.", vbOKOnly

Since msgbox waits for a return value, it's possible that after the first time it's clicked it already has one (the one from last time OK was clicked). Saving the map somehow resets it I guess. Hopefully adding the vbOKOnly will make it wait for a return value. If that doesn't work, you might try one with two possible return values, such as vbOKCancel.

You could also try enclosing the Form.CLose statement in an If...Then statement (with closing the form being the only possible outcome, since the return value of a msgbox with just OK is always 1), so that it is waiting for a value before proceeding.

If (msgbox "Hit the refresh blah", vbOKOnly) = 1 Then
   form.close
End If

Syntax might be a little off... but hopefully this will help, good luck!
0 Kudos