HTML, CSS, batch commands, and Javascript examples that I have used in my library work. Short entries, designed as quick reference.
By Len Davidson at CUA Law Library
7/31/2015
script to install print queues
rundll32 printui.dll,PrintUIEntry /u /in /n \\ntsrva\LAW228_HP
http://blogs.technet.com/b/askperf/archive/2011/09/16/print-queue-scripting.aspx
7/23/2015
automated Word index
The vb script below will create an index of every word from a document, (directions for setting up macros)
Sub ConcordanceBuilder()
Application.ScreenUpdating = False
Dim StrIn As String, StrOut As String, StrTmp As String, StrExcl As String
Dim i As Long, j As Long, k As Long, l As Long, Rng As Range
'Define the exlusions list
StrExcl = "a,am,an,and,are,as,at,b,be,but,by,c,can,cm,d,did," & _
"do,does,e,eg,en,eq,etc,f,for,g,get,go,got,h,has,have," & _
"he,her,him,how,i,ie,if,in,into,is,it,its,j,k,l,m,me," & _
"mi,mm,my,n,na,nb,no,not,o,of,off,ok,on,one,or,our,out," & _
"p,q,r,re,s,she,so,t,the,their,them,they,this,t,to,u,v," & _
"via,vs,w,was,we,were,who,will,with,would,x,y,yd,you,your,z"
With ActiveDocument
'Get the document's text
StrIn = .Content.Text
'Strip out unwanted characters. Amongst others, hyphens and formatted single quotes are retained at this stage
For i = 1 To 255
Select Case i
Case 1 To 35, 37 to 38, 40 To 43, 45, 47, 58 To 64, 91 To 96, 123 To 127, 129 To 144, 147 To 149, 152 To 162, 164, 166 To 171, 174 To 191, 247
StrIn = Replace(StrIn, Chr(i), " ")
End Select
Next
'Delete any periods or commas at the end of a word. Formatted numbers are thus retained.
StrIn = Replace(Replace(Replace(Replace(StrIn, Chr(44) & Chr(32), " "), Chr(44) & vbCr, " "), Chr(46) & Chr(32), " "), Chr(46) & vbCr, " ")
'Convert smart single quotes to plain single quotes & delete any at the start/end of a word
StrIn = Replace(Replace(Replace(Replace(StrIn, Chr(145), "'"), Chr(146), "'"), "' ", " "), " '", " ")
'Convert to lowercase
StrIn = " " & LCase(Trim(StrIn)) & " "
'Process the exclusions list
For i = 0 To UBound(Split(StrExcl, ","))
While InStr(StrIn, " " & Split(StrExcl, ",")(i) & " ") > 0
StrIn = Replace(StrIn, " " & Split(StrExcl, ",")(i) & " ", " ")
Wend
Next
'Clean up any duplicate spaces
While InStr(StrIn, " ") > 0
StrIn = Replace(StrIn, " ", " ")
Wend
StrIn = " " & Trim(StrIn) & " "
j = UBound(Split(StrIn, " "))
l = j
For i = 1 To j
'Find how many occurences of each word there are in the document
StrTmp = Split(StrIn, " ")(1)
While InStr(StrIn, " " & StrTmp & " ") > 0
StrIn = Replace(StrIn, " " & StrTmp & " ", " ")
Wend
'Calculate the number of words replaced
k = l - UBound(Split(StrIn, " "))
'Update the output string
StrOut = StrOut & StrTmp & vbTab & k & vbCr
l = UBound(Split(StrIn, " "))
If l = 1 Then Exit For
DoEvents
Next
StrIn = StrOut
StrOut = ""
For i = 0 To UBound(Split(StrIn, vbCr)) - 1
StrTmp = ""
With .Range
With .Find
.ClearFormatting
.Text = Split(Split(StrIn, vbCr)(i), vbTab)(0)
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindStop
.Format = False
.MatchCase = False
.MatchWholeWord = True
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
.Execute
End With
Do While .Find.Found
StrTmp = StrTmp & " " & .Information(wdActiveEndPageNumber)
.Collapse (wdCollapseEnd)
.Find.Execute
Loop
End With
StrTmp = Replace(Trim(StrTmp), " ", ",")
StrOut = StrOut & Split(StrIn, vbCr)(i) & vbTab & StrTmp & vbCr
Next
'Create the concordance table on a new last page
Set Rng = .Range.Characters.Last
With Rng
.InsertAfter vbCr & Chr(12) & StrOut
.Start = .Start + 2
.ConvertToTable Separator:=vbTab, Numcolumns:=3
.Tables(1).Sort Excludeheader:=False, FieldNumber:=1, _
SortFieldType:=wdSortFieldAlphanumeric, _
SortOrder:=wdSortOrderAscending, CaseSensitive:=False
End With
End With
Application.ScreenUpdating = True
End Sub
From microsoft.com Answers
Sub ConcordanceBuilder()
Application.ScreenUpdating = False
Dim StrIn As String, StrOut As String, StrTmp As String, StrExcl As String
Dim i As Long, j As Long, k As Long, l As Long, Rng As Range
'Define the exlusions list
StrExcl = "a,am,an,and,are,as,at,b,be,but,by,c,can,cm,d,did," & _
"do,does,e,eg,en,eq,etc,f,for,g,get,go,got,h,has,have," & _
"he,her,him,how,i,ie,if,in,into,is,it,its,j,k,l,m,me," & _
"mi,mm,my,n,na,nb,no,not,o,of,off,ok,on,one,or,our,out," & _
"p,q,r,re,s,she,so,t,the,their,them,they,this,t,to,u,v," & _
"via,vs,w,was,we,were,who,will,with,would,x,y,yd,you,your,z"
With ActiveDocument
'Get the document's text
StrIn = .Content.Text
'Strip out unwanted characters. Amongst others, hyphens and formatted single quotes are retained at this stage
For i = 1 To 255
Select Case i
Case 1 To 35, 37 to 38, 40 To 43, 45, 47, 58 To 64, 91 To 96, 123 To 127, 129 To 144, 147 To 149, 152 To 162, 164, 166 To 171, 174 To 191, 247
StrIn = Replace(StrIn, Chr(i), " ")
End Select
Next
'Delete any periods or commas at the end of a word. Formatted numbers are thus retained.
StrIn = Replace(Replace(Replace(Replace(StrIn, Chr(44) & Chr(32), " "), Chr(44) & vbCr, " "), Chr(46) & Chr(32), " "), Chr(46) & vbCr, " ")
'Convert smart single quotes to plain single quotes & delete any at the start/end of a word
StrIn = Replace(Replace(Replace(Replace(StrIn, Chr(145), "'"), Chr(146), "'"), "' ", " "), " '", " ")
'Convert to lowercase
StrIn = " " & LCase(Trim(StrIn)) & " "
'Process the exclusions list
For i = 0 To UBound(Split(StrExcl, ","))
While InStr(StrIn, " " & Split(StrExcl, ",")(i) & " ") > 0
StrIn = Replace(StrIn, " " & Split(StrExcl, ",")(i) & " ", " ")
Wend
Next
'Clean up any duplicate spaces
While InStr(StrIn, " ") > 0
StrIn = Replace(StrIn, " ", " ")
Wend
StrIn = " " & Trim(StrIn) & " "
j = UBound(Split(StrIn, " "))
l = j
For i = 1 To j
'Find how many occurences of each word there are in the document
StrTmp = Split(StrIn, " ")(1)
While InStr(StrIn, " " & StrTmp & " ") > 0
StrIn = Replace(StrIn, " " & StrTmp & " ", " ")
Wend
'Calculate the number of words replaced
k = l - UBound(Split(StrIn, " "))
'Update the output string
StrOut = StrOut & StrTmp & vbTab & k & vbCr
l = UBound(Split(StrIn, " "))
If l = 1 Then Exit For
DoEvents
Next
StrIn = StrOut
StrOut = ""
For i = 0 To UBound(Split(StrIn, vbCr)) - 1
StrTmp = ""
With .Range
With .Find
.ClearFormatting
.Text = Split(Split(StrIn, vbCr)(i), vbTab)(0)
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindStop
.Format = False
.MatchCase = False
.MatchWholeWord = True
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
.Execute
End With
Do While .Find.Found
StrTmp = StrTmp & " " & .Information(wdActiveEndPageNumber)
.Collapse (wdCollapseEnd)
.Find.Execute
Loop
End With
StrTmp = Replace(Trim(StrTmp), " ", ",")
StrOut = StrOut & Split(StrIn, vbCr)(i) & vbTab & StrTmp & vbCr
Next
'Create the concordance table on a new last page
Set Rng = .Range.Characters.Last
With Rng
.InsertAfter vbCr & Chr(12) & StrOut
.Start = .Start + 2
.ConvertToTable Separator:=vbTab, Numcolumns:=3
.Tables(1).Sort Excludeheader:=False, FieldNumber:=1, _
SortFieldType:=wdSortFieldAlphanumeric, _
SortOrder:=wdSortOrderAscending, CaseSensitive:=False
End With
End With
Application.ScreenUpdating = True
End Sub
From microsoft.com Answers
7/20/2015
Exporting Outlook contacts
You can export contacts to a file that can then be imported into other applications, such as Web mail clients, Excel spreadsheets, or database applications.
The most common export file format is a comma separated value (CSV) file. If you are exporting contacts for use in another copy of Outlook, we recommend that you choose an Outlook Data File (.pst) in step 6 below.
-
Click the File tab.
-
Click Options.
-
Click Advanced.
-
Under Export, click Export.
7/15/2015
Validating user input from batch file
To prevent blank input:
To use regular expression:
:askQuestion
set /p UserName= What is your CUA user ID? || Set UserName=NothingChosen
If "%UserName%"=="NothingChosen" goto :sub_error
:sub_error
echo Error: Please type in CUA user ID
echo(
echo(
goto:askQuestion
To use regular expression:
:loop
SET /P "UserName=What is your CUA user ID?: "
echo("%UserName:"= %"|findstr /r /C:"""[0-9][0-9][a-zA-Z]*""" >nul || ( echo Error: CUA user ID starts with 2 digits & ECHO( & goto loop )
7/14/2015
Installing windows print queue on laptop
To install printers on student laptops (not on domain) the START command works best:
echo Starting printer install....
start \\printers.cua.edu\LAW150_HP4000
This will just like manual install, and will generate Windows Security popup, student must put in user name preceded by domain, and then password:
DOMAIN\userName
This will save name/password in Credentials Manager.
To install via Visual basic, computer must be on the domain:
Set WshNetwork = CreateObject("WScript.Network")
WshNetwork.AddWindowsPrinterConnection "\\printers.cua.edu\LAW400_HP9000"
echo Starting printer install....
start \\printers.cua.edu\LAW150_HP4000
This will just like manual install, and will generate Windows Security popup, student must put in user name preceded by domain, and then password:
DOMAIN\userName
This will save name/password in Credentials Manager.
To install via Visual basic, computer must be on the domain:
Set WshNetwork = CreateObject("WScript.Network")
WshNetwork.AddWindowsPrinterConnection "\\printers.cua.edu\LAW400_HP9000"
7/13/2015
Open URL with CMD file
What to open web page, and submit form via CMD script:
set /p UserName= What is your CUA user ID?
echo(
start "" http://test.law.cua.edu/form/printer-install.asp?name=%UserName%^&explanation=Library_Prnt_v3b^&OS=Windows^&Submit=Submit"
The URL has variable, enclosed by % %, and &'s which must be escaped via ^
http://test.law.cua.edu/form/printer-install.asp.asp?name=%UserName%&explanation=Library_Prnt_v3b&OS=Windows&Submit=Submit"
set /p UserName= What is your CUA user ID?
echo(
start "" http://test.law.cua.edu/form/printer-install.asp?name=%UserName%^&explanation=Library_Prnt_v3b^&OS=Windows^&Submit=Submit"
The URL has variable, enclosed by % %, and &'s which must be escaped via ^
http://test.law.cua.edu/form/printer-install.asp.asp?name=%UserName%&explanation=Library_Prnt_v3b&OS=Windows&Submit=Submit"
7/09/2015
nslookup command
From Microsoft.com
Commands: (identifiers are shown in uppercase, [] means optional) NAME - print info about the host/domain NAME using default server NAME1 NAME2 - as above, but use NAME2 as server help or ? - print info on common commands set OPTION - set an option all - print options, current server and host [no]debug - print debugging information [no]d2 - print exhaustive debugging information [no]defname - append domain name to each query [no]recurse - ask for recursive answer to query [no]search - use domain search list [no]vc - always use a virtual circuit domain=NAME - set default domain name to NAME srchlist=N1[/N2/.../N6] - set domain to N1 and search list to N1, N2, and so on root=NAME - set root server to NAME retry=X - set number of retries to X timeout=X - set initial time-out interval to X seconds type=X - set query type (for example, A, ANY, CNAME, MX, NS, PTR, SOA, SRV) querytype=X - same as type class=X - set query class (for example, IN (Internet), ANY) [no]msxfr - use MS fast zone transfer ixfrver=X - current version to use in IXFR transfer request server NAME - set default server to NAME, using current default server lserver NAME - set default server to NAME, using initial server finger [USER] - finger the optional NAME at the current default host root - set current default server to the root ls [opt] DOMAIN [> FILE] - list addresses in DOMAIN (optional: output to FILE) -a - list canonical names and aliases -d - list all records -t TYPE - list records of the given type (for example, A, CNAME, MX, NS, PTR, and so on) view FILE - sort an 'ls' output file and view it with pg exit - exit the program
7/02/2015
SQL for patron fines
Looking to run SQL query to get patron fine info (from Sierra Listerv)
As David Noe reported, the descriptions you seek are based on
fine.charge_code and are described in Sierra
DNA.
This is one of those occasions when code descriptions are not stored in
sibling tables that can be easily joined to. In this case, you must use a CASE
statement to manually describe all possible descriptions for the codes – and
hope that Innovative doesn’t add extra codes in the future. To test for this
possibility, I use the ELSE clause to write out ‘unexpected code’ followed by
the new code.
select
p.id,
p.home_library_code,
p.record_num,
p.mblock_code,
n.last_name,
n.first_name,
p.owed_amt,
f.assessed_gmt,
CASE
WHEN f.charge_code = '1' THEN 'Manual Charge'
WHEN f.charge_code = '2' THEN 'Overdue'
WHEN f.charge_code = '3' THEN 'Replacement'
WHEN f.charge_code = '4' THEN 'Adjustment (OVERDUEX)'
WHEN f.charge_code = '5' THEN 'Lost'
WHEN f.charge_code = '6' THEN 'Overdue Renewed'
WHEN f.charge_code = '7' THEN 'Rental'
WHEN f.charge_code = '8' THEN 'Rental Adjustment
(RENTALX)'
WHEN f.charge_code = '9' THEN 'Debit'
WHEN f.charge_code = 'a' THEN 'Notice'
WHEN f.charge_code = 'b' THEN 'Credit Card'
WHEN f.charge_code = 'p' THEN 'Program Registration'
ELSE 'unexpected code '||f.charge_code
END
AS "Charge Type",
f.description,
f.item_charge_amt
from sierra_view.fine as f
join sierra_view.patron_view as p
on p.id = f.patron_record_id
join sierra_view.patron_record_fullname as n
on n.patron_record_id = p.id
;
As an example of a code which has a properly configured sibling table
that describes the codes, we can use your fourth column, p.mblock_code. To see descriptions
instead of codes in that column you could add a join to
sierra_view.mblock_property_myuser and then display the ‘name’ column from that
table. No ugly CASE statement required. Unfortunately, we have no alternative
for charge_code
select
p.id,
p.home_library_code,
p.record_num,
m.name,
n.last_name,
n.first_name,
p.owed_amt,
f.assessed_gmt,
CASE
WHEN f.charge_code = '1' THEN 'Manual Charge'
WHEN f.charge_code = '2' THEN 'Overdue'
WHEN f.charge_code = '3' THEN 'Replacement'
WHEN f.charge_code = '4' THEN 'Adjustment (OVERDUEX)'
WHEN f.charge_code = '5' THEN 'Lost'
WHEN f.charge_code = '6' THEN 'Overdue Renewed'
WHEN f.charge_code = '7' THEN 'Rental'
WHEN f.charge_code = '8' THEN 'Rental Adjustment
(RENTALX)'
WHEN f.charge_code = '9' THEN 'Debit'
WHEN f.charge_code = 'a' THEN 'Notice'
WHEN f.charge_code = 'b' THEN 'Credit Card'
WHEN f.charge_code = 'p' THEN 'Program Registration'
ELSE 'unexpected code '||f.charge_code
END
AS
"Charge Type",
f.description,
f.item_charge_amt
from sierra_view.fine as f
join sierra_view.patron_view as p
on p.id = f.patron_record_id
join sierra_view.patron_record_fullname as n
on n.patron_record_id = p.id
JOIN sierra_view.mblock_property_myuser AS m
ON m.code = p.mblock_code
;
--
Brent Searle
Library Systems Manager
Langara College
Subscribe to:
Posts (Atom)