Showing posts with label VB. Show all posts
Showing posts with label VB. Show all posts

Sunday, September 20, 2015

VBS Shutdown Timer

When running time comsuming processes I often wish to shutdown automatically after a given time. There are several applications on the internet but I was not really happy with the ones I found. So, I put together a really small VB-Script which in fact does the job perfectly.

Dim Shell : Set Shell = CreateObject("WScript.Shell")

argument_t = inputbox("Time in Seconds:", "Shutdown", "3600")

Shell.Run "C:/Windows/system32/shutdown.exe -f -s -t " & _
argument_t, 0

MsgBox "Press OK if you want to cancel the Shutdown..", _
vbInformation + vbOkayonly, "Cancel Shutdown"

Shell.Run "C:/Windows/system32/shutdown.exe -a", 0

I put the vbs file on my disk and a shortcut to it on the Desktop. You can choose the time until shutdown with an input box.



Read more »

Visual Basic - IF THEN Usage in ArcGis Field Calculator

Recently I had to do some statistics on a numerical field in an attribute table and I had to classify this field according to a set of intervals for this purpose. I had to learn that there is no tool for this. So I had to use the fieldcalculator with the appropiate IF THEN VBA-Syntax:

Here is how it can be done (one of many ways):

data: date_long is date in long format, which is aimed
to be clasiffied into 3 classes {<1850; <1900; >= 1900}
values are returned in field date_class which must
be added to the attribute table first.

Open attribute table and choose the
FIELD CALCULATOR:


Box "Pre-Logic VBA Script Code"
(!) check "Advanced" (!)
***********************************************
Dim dc as Integer
IF [date_long] < 1850 THEN
   dc = 1
ElseIf [date_long] < 1900 THEN
   dc = 2
Else dc = 3
EndIf
***********************************************

Box "date_class ="
***********************************************
dc
***********************************************


Resulting attribute table:
***********************************************
date_long    date_class
1945        3
1886        2
1929        3
1927        3
1927        3
1927        3
1927        3
1929        3
1840        1
1939        3
1884        2
1853        2
...        ...
***********************************************

If you just needed graphical representation of classes you sure would have used the symbology and its classifications options but whenever you need the values for further calculations the above or alternative methods using the field calculator will be useful.
Read more »