VBA: how to read text file

This is just example, how to read text file in Visual Basic for Applications (for example, in Excel macro).

It’s just a stub: there is no error processing here, the source file is really text file, no problems with permissions etc.

Sub read_from_text_file() txtFile = Application.GetOpenFilename("Text Files (*.txt), *.txt") If txtFile = False Then [...]

AIX: reset user password

Change the password for the user (as root):

passwd username

Reset the login counter and unlock the user:

chsec -f /etc/security/lastlog -a "unsuccessful_login_count=0" -s username chuser "account_locked=false" username

Perl: SOAP problem with dateTime

The following error message was received by Perl application: Unrecognized type ‘{http://www.w3.org/1999/XMLSchema}dateTime

The problem is caused by “dateTime” type: it was not supported in the 1999 XML Specification. The solution is to switch to 2001 schema:

 my $soap = SOAP::Lite->uri( $NAMESPACE )->proxy( $PROXY_URL )->xmlschema (’2001′);

Perl: Soap deserialization error

Sometimes the following error is displayed, if application uses the old version of CPAN SOAP module: “Client Application failed during request deserialization: no element found at line 1, column 0, byte -1 at XML/Parser.pm”

The possilbe solution is to change SOAP::Transport::HTTP module (SOAP/Transport/HTTP.pm), function “handle”:

sysread( STDIN, $buffer, $length )

should be replaced by

read( [...]

AutoIt: script for hotkeys usage

This script allows You to define the global Windows hotkeys via the configuration file.

The syntax of the config file is simple:

Hotkey,Program,Parameters

Here “Hotkey” is the combination of the keyboard key with one of the identifiers:

^ Ctrl ! Alt + Shift # Windows-Key

Example:

;Win+C – start calculator [...]

Unix: print in color

This simple procedure takes 3 arguments as the parameters:

Text Foreground color Background color

It prints the text to the terminal in selected colors.

function print_color {  local text=$1  local fg=$2  local bg=$3  case "$fg" in  red) fg="31m" ;;  green) fg="32m" ;;  yellow) fg="33m" ;;  blue) fg="34m" ;;  white) fg="37m" ;;  black) fg="30m" ;;  *) [...]

Unix: rename files to lowercase

It’s very simple to rename the files to lowercase/uppercase using awk:

Lowercase

ls -1rt | awk ‘{ printf("mv %s %s\n", $0, tolower($0)) | "sh" } END { close("sh") }’

Uppercase

ls -1rt | awk ‘{ printf("mv %s %s\n", $0, toupper($0)) | "sh" } END { close("sh") }’

Perl: get file checksum

use Digest::MD5; use IO::File; my $chk = Digest::MD5->new(); foreach my $file (@ARGV) {     $chk->addfile(IO::File->new($file));     print "$file -> ",$chk->hexdigest,"\n"; }

The additional details could be found on IBM site

Reading password in Unix shell

print -n "Enter Your password:" stty_orig=`stty -g` trap "stty ${stty_orig}; exit" 1 2 3 15 stty -echo >&- 2>&- read PASS stty ${stty_orig} >&- 2>&- trap 1 2 3 15 print

trap :catches interruptions. I.e. if the user presses Ctrl+C, the normal stty mode is set before stopping the program stty -echo :switches off the [...]

Using the clipboard in WSH

How to get the text from the clipboard

set objIE = CreateObject("InternetExplorer.Application") objIE.Navigate("about:blank") textFromClipboard = objIE.document.parentwindow.clipboardData.GetData("text") objIE.Quit WScript.Echo textFromClipboard

How to put the text into clipboard

textIntoClipboard = "Some text" & VbCrLf & "Some more text"   Set objIE = WScript.CreateObject("InternetExplorer.Application") objIE.Navigate "about:blank" Do Until objIE.ReadyState = 4     WScript.Sleep 100 Loop   objIE.document.ParentWindow.ClipboardData.SetData [...]