2007/06/17

How to use SendKeys to imitate the keyboard

http://www.tek-tips.com/faqs.cfm?fid=5037

How to use SendKeys to imitate the keyboard


faq707-5037
Posted: 15 Apr 04

If you perform the process using the keyboard you will note that things do not happen instantly on screen - especially the initial opening of a dialog box where the action takes place. The main problem with SendKeys is that the code usually runs faster than Windows can carry out the required activity - this is especially so if manipulating an external (not the one with the code) application or opening a dialog box or menu. We therefore need to slow the action down by using Wait statements. SendKeys also has its own "Wait" argument True or False which needs to be used correctly. One example of using it set to True is when manipulating external applications that require extra time to carry out actions. This is not always sufficient, so extra code is required.

A big key to success in this area is to break down the process into small steps. It does need a bit of trial and error to get it right. Experience shows that operators are prepared to wait a bit longer if it works. Sometimes the speed of external applications varies so much that the job is impossible using SendKeys, when using API calls with KeyUp and KeyDown work better. This area is never an exact science. See VBA Help 'SendKeys' and 'Shell' for more information.

This is some sample code to demonstrate the principle :-


    '------------------------------------------
    Sub SET_A3()
    '- change Printer setting to A3 size
    '- nb. assumes current setting is A4
    Dim AltKey As String
    Dim CtrlKey As String
    Dim ShiftKey As String
    Dim TabKey As String
    Dim EnterKey As String
    '--------------------------
    AltKey = "%"
    CtrlKey = "^"
    ShiftKey = "+"
    TabKey = "{TAB}"
    EnterKey = "~"
    '--------------------------
    '- open print dialog
    SendKeys AltKey & "(FP)", False
    '- delay 1 second
    Application.Wait Now + TimeValue("00:00:01")
    '- open printer properties
    SendKeys AltKey & "(R)", False
    '- tab to paper size
    SendKeys TabKey, False
    SendKeys TabKey, False
    '- change A4 to A3
    SendKeys "{UP}", False
    '- Enter twice
    SendKeys EnterKey, False
    SendKeys EnterKey, False
    End Sub
    '----------------------------------------------



SendKeys Statement, (VBA help)


Sends one or more keystrokes to the active window as if typed at the keyboard.

Syntax

SendKeys string[, wait]

The SendKeys statement syntax has these named arguments:

Part Description
string Required. String expression specifying the keystrokes to send.
Wait Optional. Boolean value specifying the wait mode. If False (default), control is returned to the procedure immediately after the keys are sent. If True, keystrokes must be processed before control is returned to the procedure.

Remarks

Each key is represented by one or more characters. To specify a single keyboard character, use the character itself. For example, to represent the letter A, use "A" for string. To represent more than one character, append each additional character to the one preceding it. To represent the letters A, B, and C, use "ABC" for string.

The plus sign (+), caret (^), percent sign (%), tilde (~), and parentheses ( ) have special meanings to SendKeys. To specify one of these characters, enclose it within braces ({}). For example, to specify the plus sign, use {+}. Brackets ([ ]) have no special meaning to SendKeys, but you must enclose them in braces. In other applications, brackets do have a special meaning that may be significant when dynamic data exchange (DDE) occurs. To specify brace characters, use {{} and {}}.

To specify characters that aren't displayed when you press a key, such as ENTER or TAB, and keys that represent actions rather than characters, use the codes shown below:


    Key Code
    BACKSPACE {BACKSPACE}, {BS}, or {BKSP}
    BREAK {BREAK}
    CAPS LOCK {CAPSLOCK}
    DEL or DELETE {DELETE} or {DEL}
    DOWN ARROW {DOWN}
    END {END}
    ENTER {ENTER}or ~
    ESC {ESC}
    HELP {HELP}
    HOME {HOME}
    INS or INSERT {INSERT} or {INS}
    LEFT ARROW {LEFT}
    NUM LOCK {NUMLOCK}
    PAGE DOWN {PGDN}
    PAGE UP {PGUP}
    PRINT SCREEN {PRTSC}
    RIGHT ARROW {RIGHT}
    SCROLL LOCK {SCROLLLOCK}
    TAB {TAB}
    UP ARROW {UP}
    F1 {F1}
    F2 {F2}
    F3 {F3}
    F4 {F4}
    F5 {F5}
    F6 {F6}
    F7 {F7}
    F8 {F8}
    F9 {F9}
    F10 {F10}
    F11 {F11}
    F12 {F12}
    F13 {F13}
    F14 {F14}
    F15 {F15}
    F16 {F16}


To specify keys combined with any combination of the SHIFT, CTRL, and ALT keys, precede the key code with one or more of the following codes:


    Key Code
    SHIFT +
    CTRL ^
    ALT %


To specify that any combination of SHIFT, CTRL, and ALT should be held down while several other keys are pressed, enclose the code for those keys in parentheses. For example, to specify to hold down SHIFT while E and C are pressed, use "+(EC)". To specify to hold down SHIFT while E is pressed, followed by C without SHIFT, use "+EC".

To specify repeating keys, use the form {key number}. You must put a space between key and number. For example, {LEFT 42} means press the LEFT ARROW key 42 times; {h 10} means press H 10 times.

Note You can't use SendKeys to send keystrokes to an application that is not designed to run in Microsoft Windows or Macintosh. Sendkeys also can't send the PRINT SCREEN key {PRTSC} to any application.

SendKeys Statement Example


This example uses the Shell function to run the Calculator application included with Microsoft Windows. It uses the SendKeys statement to send keystrokes to add some numbers, and then quit the Calculator. (To see the example, paste it into a procedure, then run the procedure. Because AppActivate changes the focus to the Calculator application, you can't single step through the code.). On the Macintosh, use a Macintosh application that accepts keyboard input instead of the Windows Calculator.


    Dim ReturnValue, I
    ReturnValue = Shell("CALC.EXE", 1) ' Run Calculator.
    AppActivate ReturnValue ' Activate the Calculator.
    For I = 1 To 100 ' Set up counting loop.
    SendKeys I & "{+}", True ' Send keystrokes to Calculator
    Next I ' to add each value of I.
    SendKeys "=", True ' Get grand total.
    SendKeys "%{F4}", True ' Send ALT+F4 to close Calculator.





2007/06/16

ISO 3166 Codes & Top level domains

International Country Codes


http://www.bris.ac.uk/Support/Network/ipcodes1.html




The following information was downloaded on 15 June
1995 from "http://www.ics.uci.edu/WebSoft/wwwstat/country-codes.txt">http://www.ics.uci.edu/WebSoft/wwwstat/country-codes.txt.
Additional useful information may be found in the "Table of Global and
Country Top Level Internet Domains, which is dated 16 April 1995 (as of 15
June 1995), and is stored at "http://www.isoc.org/domains.html">http://www.isoc.org/domains.html

Mark.Gould@bris.ac.uk




    AD Andorra
    AE United Arab Emirates
    AF Afghanistan
    AG Antigua and Barbuda
    AI Anguilla
    AL Albania
    AM Armenia
    AN Netherlands Antilles
    AO Angola
    AQ Antarctica
    AR Argentina
    AS American Samoa
    AT Austria
    AU Australia
    AW Aruba
    AZ Azerbaijan
    BA Bosnia and Herzegovina
    BB Barbados
    BD Bangladesh
    BE Belgium
    BF Burkina Faso
    BG Bulgaria
    BH Bahrain
    BI Burundi
    BJ Benin
    BM Bermuda
    BN Brunei Darussalam
    BO Bolivia
    BR Brazil
    BS Bahamas
    BT Bhutan
    BV Bouvet Island
    BW Botswana
    BY Belarus
    BZ Belize
    CA Canada
    CC Cocos (Keeling) Islands
    CF Central African Republic
    CG Congo
    CH Switzerland
    CI Cote D'Ivoire (Ivory Coast)
    CK Cook Islands
    CL Chile
    CM Cameroon
    CN China
    CO Colombia
    CR Costa Rica
    CS Czechoslovakia (former)
    CU Cuba
    CV Cape Verde
    CX Christmas Island
    CY Cyprus
    CZ Czech Republic
    DE Germany
    DJ Djibouti
    DK Denmark
    DM Dominica
    DO Dominican Republic
    DZ Algeria
    EC Ecuador
    EE Estonia
    EG Egypt
    EH Western Sahara
    ER Eritrea
    ES Spain
    ET Ethiopia
    FI Finland
    FJ Fiji
    FK Falkland Islands (Malvinas)
    FM Micronesia
    FO Faroe Islands
    FR France
    FX France, Metropolitan
    GA Gabon
    GB Great Britain (UK)
    GD Grenada
    GE Georgia
    GF French Guiana
    GH Ghana
    GI Gibraltar
    GL Greenland
    GM Gambia
    GN Guinea
    GP Guadeloupe
    GQ Equatorial Guinea
    GR Greece
    GS S. Georgia and S. Sandwich Isls.
    GT Guatemala
    GU Guam
    GW Guinea-Bissau
    GY Guyana
    HK Hong Kong
    HM Heard and McDonald Islands
    HN Honduras
    HR Croatia (Hrvatska)
    HT Haiti
    HU Hungary
    ID Indonesia
    IE Ireland
    IL Israel
    IN India
    IO British Indian Ocean Territory
    IQ Iraq
    IR Iran
    IS Iceland
    IT Italy
    JM Jamaica
    JO Jordan
    JP Japan
    KE Kenya
    KG Kyrgyzstan
    KH Cambodia
    KI Kiribati
    KM Comoros
    KN Saint Kitts and Nevis
    KP Korea (North)
    KR Korea (South)
    KW Kuwait
    KY Cayman Islands
    KZ Kazakhstan
    LA Laos
    LB Lebanon
    LC Saint Lucia
    LI Liechtenstein
    LK Sri Lanka
    LR Liberia
    LS Lesotho
    LT Lithuania
    LU Luxembourg
    LV Latvia
    LY Libya
    MA Morocco
    MC Monaco
    MD Moldova
    MG Madagascar
    MH Marshall Islands
    MK Macedonia
    ML Mali
    MM Myanmar
    MN Mongolia
    MO Macau
    MP Northern Mariana Islands
    MQ Martinique
    MR Mauritania
    MS Montserrat
    MT Malta
    MU Mauritius
    MV Maldives
    MW Malawi
    MX Mexico
    MY Malaysia
    MZ Mozambique
    NA Namibia
    NC New Caledonia
    NE Niger
    NF Norfolk Island
    NG Nigeria
    NI Nicaragua
    NL Netherlands
    NO Norway
    NP Nepal
    NR Nauru
    NT Neutral Zone
    NU Niue
    NZ New Zealand (Aotearoa)
    OM Oman
    PA Panama
    PE Peru
    PF French Polynesia
    PG Papua New Guinea
    PH Philippines
    PK Pakistan
    PL Poland
    PM St. Pierre and Miquelon
    PN Pitcairn
    PR Puerto Rico
    PT Portugal
    PW Palau
    PY Paraguay
    QA Qatar
    RE Reunion
    RO Romania
    RU Russian Federation
    RW Rwanda
    SA Saudi Arabia
    Sb Solomon Islands
    SC Seychelles
    SD Sudan
    SE Sweden
    SG Singapore
    SH St. Helena
    SI Slovenia
    SJ Svalbard and Jan Mayen Islands
    SK Slovak Republic
    SL Sierra Leone
    SM San Marino
    SN Senegal
    SO Somalia
    SR Suriname
    ST Sao Tome and Principe
    SU USSR (former)
    SV El Salvador
    SY Syria
    SZ Swaziland
    TC Turks and Caicos Islands
    TD Chad
    TF French Southern Territories
    TG Togo
    TH Thailand
    TJ Tajikistan
    TK Tokelau
    TM Turkmenistan
    TN Tunisia
    TO Tonga
    TP East Timor
    TR Turkey
    TT Trinidad and Tobago
    TV Tuvalu
    TW Taiwan
    TZ Tanzania
    UA Ukraine
    UG Uganda
    UK United Kingdom
    UM US Minor Outlying Islands
    US United States
    UY Uruguay
    UZ Uzbekistan
    VA Vatican City State (Holy See)
    VC Saint Vincent and the Grenadines
    VE Venezuela
    VG Virgin Islands (British)
    VI Virgin Islands (U.S.)
    VN Viet Nam
    VU Vanuatu
    WF Wallis and Futuna Islands
    WS Samoa
    YE Yemen
    YT Mayotte
    YU Yugoslavia
    ZA South Africa
    ZM Zambia
    ZR Zaire
    ZW Zimbabwe

    COM US Commercial
    EDU US Educational
    GOV US Government
    INT International
    MIL US Military
    NET Network
    ORG Non-Profit Organization
    ARPA Old style Arpanet
    NATO Nato field






http://www.nectec.or.th/net-guide/bigdummy/bdg_288.html


    ISO 3166 Codes & Top level domains

    Code Country Conn Notes main nameserver

    AD Andorra
    AE United Arab Emirates * ns.uu.net
    AF Afghanistan
    AG Antigua and Barbuda * upr1.upr.clu.edu
    AI Anguilla
    AL Albania P gwd2i.cnuce.cnr.it
    AM Armenia Ex-USSR
    AN Netherland Antilles
    AO Angola
    AQ Antarctica FI * luxor.cc.waikato.ac.nz
    AR Argentina FI B * ns.uu.net
    AS American Samoa
    AT Austria FI B * pythia.edvz.univie.ac.at
    AU Australia FI * munnari.oz.au
    AW Aruba
    AZ Azerbaidjan Ex-USSR
    BA Bosnia-Herzegovina Ex-Yugoslavia
    BB Barbados * upr1.upr.clu.edu
    BD Bangladesh
    BE Belgium FI B * ub4b.buug.be
    BF Burkina Faso * orstom.orstom.fr
    BG Bulgaria FI B * pythia.ics.forth.gr
    BH Bahrain B * Gulfnet
    BI Burundi
    BJ Benin
    BM Bermuda * ns.uu.net
    BN Brunei Darussalam
    BO Bolivia * ns.uu.net
    BR Brazil FI B * fpsp.fapesp.br
    BS Bahamas * upr1.upr.clu.edu
    BT Buthan
    BV Bouvet Island
    BW Botswana * hippo.ru.ac.za
    BY Belarus * Ex-USSR
    BZ Belize P upr1.upr.clu.edu
    CA Canada FI B * relay.cdnnet.ca
    CC Cocos (Keeling) Isl.
    CF Central African Rep.
    CG Congo
    CH Switzerland FI B * scsnms.switch.ch
    CI Ivory Coast
    CK Cook Islands
    CL Chile FI B * dcc.uchile.cl
    CM Cameroon FI * in .fr domain inria.inria.fr
    CN China PFI * iraun1.ira.uka.de
    CO Colombia B * cunixd.cc.columbia.edu
    CR Costa Rica FI B * ns.cr
    CS Czechoslovakia FI B * still works... ns.cesnet.cz
    CU Cuba * igc.org
    CV Cape Verde
    CX Christmas Island
    CY Cyprus B * pythia.ics.forth.gr
    CZ Czech Republic FI * ns.cesnet.cz
    DE Germany FI B * deins.informatik.uni-dortmund.de
    DJ Djibouti
    DK Denmark FI B * ns.dknet.dk
    DM Dominica P upr1.upr.clu.edu
    DO Dominican Republic P upr1.upr.clu.edu
    DZ Algeria *
    EC Ecuador FI B * ecua.net.ec
    EE Estonia FI * Ex-USSR uvax2.kbfi.ee
    EG Egypt PFI B * frcu.eun.eg
    EH Western Sahara
    ES Spain FI B * sun.rediris.es
    ET Ethiopia
    FI Finland FI B * funet.fi
    FJ Fiji * truth.waikato.ac.nz
    FK Falkland Isl.(Malvinas)
    FM Micronesia
    FO Faroe Islands P danpost.uni-c.dk
    FR France FI B * inria.inria.fr
    FX France (European Ter.) ???
    GA Gabon
    GB Great Britain (UK) FI * X.400 & IP ns1.cs.ucl.ac.uk
    GD Grenada P upr1.upr.clu.edu
    GE Georgia * Ex-USSR ns.eu.net
    GH Ghana
    GI Gibraltar
    GL Greenland
    GP Guadeloupe (Fr.)
    GQ Equatorial Guinea
    GF Guyana (Fr.)
    GM Gambia
    GN Guinea
    GR Greece FI B * pythia.ics.forth.gr
    GT Guatemala * ns.uu.net
    GU Guam (US)
    GW Guinea Bissau
    GY Guyana
    HK Hong Kong FI B * hp9000.csc.cuhk.hk
    HM Heard & McDonald Isl.
    HN Honduras * ns.uu.net
    HR Croatia FI * Ex-Yugo dns.srce.hr
    HT Haiti
    HU Hungary FI B * sztaki.hu
    ID Indonesia * ns.uu.net
    IE Ireland FI B * nova.ucd.ie
    IL Israel FI B * relay.huji.ac.il
    IN India FI B * sangam.ncst.ernet.in
    IO British Indian O. Terr.
    IQ Iraq
    IR Iran B *
    IS Iceland FI B * isgate.is
    IT Italy FI B * dns.nis.garr.it
    JM Jamaica * upr1.upr.clu.edu
    JO Jordan
    JP Japan FI B * jp-gate.wide.ad.jp
    KE Kenya * rain.psg.com
    KG Kirgistan Ex-USSR
    KH Cambodia
    KI Kiribati
    KM Comoros
    KN St.Kitts Nevis Anguilla P upr1.upr.clu.edu
    KP Korea (North) P
    KR Korea (South) FI B * ns.kaist.ac.kr
    KW Kuwait FI * No BITNET dns.kuniv.edu.kw
    KY Cayman Islands
    KZ Kazachstan * Ex-USSR in .su domain
    LA Laos
    LB Lebanon P
    LC Saint Lucia P upr1.upr.clu.edu
    LI Liechtenstein PFI * scsnms.switch.ch
    LK Sri Lanka * ns.eu.net
    LR Liberia
    LS Lesotho * hippo.ru.ac.za
    LT Lithuania PFI * Ex-USSR aun.uninett.no
    LU Luxembourg FI B * menvax.restena.lu
    LV Latvia FI * Ex-USSR lapsene.mii.lu.lv
    LY Libya
    MA Morocco P
    MC Monaco
    MD Moldavia Ex-USSR
    MG Madagascar
    MH Marshall Islands
    ML Mali
    MM Myanmar
    MN Mongolia
    MO Macau * hkuxb.hku.hk
    MP Northern Mariana Isl.
    MQ Martinique (Fr.)
    MR Mauritania
    MS Montserrat
    MT Malta P ns.iunet.it
    MU Mauritius
    MV Maldives
    MW Malawi
    MX Mexico FI B * mtecv1.mty.itesm.mx
    MY Malaysia FI B * mimos.my
    MZ Mozambique * hippo.ru.ac.za
    NA Namibia * rain.psg.com
    NC New Caledonia (Fr.)
    NE Niger * in .fr domain inria.inria.fr
    NF Norfolk Island
    NG Nigeria
    NI Nicaragua * ns.uu.net
    NL Netherlands FI B * sering.cwi.nl
    NO Norway FI B * nac.no
    NP Nepal
    NR Nauru
    NT Neutral Zone
    NU Niue
    NZ New Zealand FI * truth.waikato.ac.nz
    OM Oman
    PA Panama B *
    PE Peru B * rain.psg.com
    PF Polynesia (Fr.)
    PG Papua New Guinea * munnari.oz.au
    PH Philippines * ns.uu.net
    PK Pakistan * ns.uu.net
    PL Poland FI B * danpost.uni-c.dk
    PM St. Pierre & Miquelon
    PN Pitcairn
    PT Portugal FI B * ns.dns.pt
    PR Puerto Rico (US) FI B * sun386-gauss.pr
    PW Palau
    PY Paraguay * ns.uu.net
    QA Qatar
    RE Reunion (Fr.) FI * In .fr domain inria.inria.fr
    RO Romania FI B * roearn.ici.ac.ro
    RU Russian Federation P Ex-USSR
    RW Rwanda
    SA Saudi Arabia B * GulfNet
    SB Solomon Islands
    SC Seychelles
    SD Sudan
    SE Sweden FI B * sunic.sunet.se
    SG Singapore FI B * solomon.technet.sg
    SH St. Helena
    SI Slovenia FI * Ex-Yugos via .yu klepec.yunac.yu
    SJ Svalbard & Jan Mayen Is
    SK Slovak Republic FI * ns.eunet.sk
    SL Sierra Leone
    SM San Marino
    SN Senegal * rain.psg.com
    SO Somalia
    SR Suriname P upr1.upr.clu.edu
    ST St. Tome and Principe
    SU Soviet Union FI B * Still used. ns.eu.net
    SV El Salvador
    SY Syria
    SZ Swaziland
    TC Turks & Caicos Islands
    TD Chad
    TF French Southern Terr.
    TG Togo
    TH Thailand FI * chulkn.chula.ac.th
    TJ Tadjikistan Ex-USSR
    TK Tokelau
    TM Turkmenistan * Ex-USSR in .su domain
    TN Tunisia FI B * alyssa.rsinet.tn
    TO Tonga
    TP East Timor
    TR Turkey FI B * knidos.cc.metu.edu.tr
    TT Trinidad & Tobago P upr1.upr.clu.edu
    TV Tuvalu
    TW Taiwan FI B * moevax.edu.tw
    TZ Tanzania
    UA Ukraine FI * Ex-USSR via .su ns.eu.net
    UG Uganda
    UK United Kingdom FI B * ISO 3166 is GB ns1.cs.ucl.ac.uk
    UM US Minor outlying Isl.
    US United States FI * see note (4) venera.isi.edu
    UY Uruguay B * ns.uu.net
    UZ Uzbekistan Ex-USSR
    VA Vatican City State
    VC St.Vincent & Grenadines P upr1.upr.clu.edu
    VE Venezuela FI * nisc.jvnc.net
    VG Virgin Islands (British)
    VI Virgin Islands (US) *
    VN Vietnam *
    VU Vanuatu
    WF Wallis & Futuna Islands
    WS Samoa
    YE Yemen
    YU Yugoslavia FI B * Bitnet is cut klepec.yunac.yu
    ZA South Africa FI * rain.psg.com
    ZM Zambia
    ZR Zaire
    ZW Zimbabwe * rain.psg.com

    See section Main nameservers for the next top
    level domains (*rs.internic.net*):

    ARPA Old style Arpanet * alias still works ns.nic.ddn.mil
    COM Commercial FI * ns.internic.net
    EDU Educational FI B * ns.internic.net
    GOV Government FI * ns.internic.net
    INT International field FI * used by Nato ns1.cs.ucl.ac.uk
    MIL US Military FI * ns.nic.ddn.mil
    NATO Nato field * soon to be deleted
    NET Network FI * ns.internic.net
    ORG Non-Profit OrganizationFI * ns.internic.net




2007/06/06

python: comments

There are two styles of comments in python

    # single line comment

    " " " (this line MUST be valid indented in the block!)
    this is a multiline comment
    which spawns many lines
    The quick brown fox jumps over the lazy dog
    The quick brown fox jumps over the lazy dog
    The quick brown fox jumps over the lazy dog
    ...
    the next end line may be NOT indented!
    " " "

multiline comments are also used to embed what are called doc strings in a function, i.e.:

    class school:

    """ this class is useful for defining a type of school (1rst. level indented)
    with its strength,affiliation,address etc
    this class has following methods and properties
    affilitaion()
    address()
    """
    def affiliation(board):
    ....
    ...
    ...
    def address(add):
    ...
    ...
    ...

in above piece of code the triple qouted string not only is a comment
but when i declare an object say

    t = school

then,

    t.__doc__

or

    help(school)

will return those comments
-kiran

2007/06/03

the quick brown fox jumps over the lazy dog

wikipedia

    The quick brown fox jumps over the lazy dog 0123456789

    The quick brown fox jumped over the lazy dog's typewriter
    The quick brown fox jumped over the sleeping lazy dog
    The quick red fox jumps over the lazy brown dog

    El veloz murcielago hindu comia feliz cardillo y kiwi
    La ciguena tocaba el saxofon detras del palenque de paja

    TEST 00 FELIX DIAZ VOY A BAJARTE WHISKY PAGAME EN CHEQUE 1234567890

shell: expresiones aritmeticas

Hay dos posibilidades, utilizar el operador aritmetico $(()):


    i=1
    i=$(($i+1))
    echo $i


o bien el comando shell 'expr':


    i=1
    i=`expr $i + 1`
    echo $i


AH

noclobber / shell options / overwrite files


    set -o noclobber
    set -C (es equivalente al anterior)


overwrite: NOT ALLOWED

    % set -C
    % ll > 1
    bash: 1: cannot overwrite existing file
    % set | grep SHELLOPTS
    SHELLOPTS=braceexpand:emacs:hashall:histexpand:history:interactive-comments:moni


overwrite: ALLOWED

    % set +C
    % ll > 1
    %
    % set | grep SHELLOPTS
    SHELLOPTS=braceexpand:emacs:hashall:histexpand:history:interactive-comments:moni

create or set a file to null length

is this form a valid form to create or to set a file to length = 0???


> $FILE


# ---
Joachim Schmitz
Provided the variable $FILE isn't empty: yes
Bye, Jojo

# ---
If $FILE might contain spaces or shell metacharacters it should be
enclosed in double quotes.

Mans Rullgard

Only with bash or with POSIX shells when they are interactive.
But it's always better to quote variables anyway.

--
Stéphane


# ---
Stephane CHAZELAS

Not with every shell (not with bash where you need to quote
$FILE, not with shells like zsh that have a default command when
you don't provide any).


: > "$FILE"


is more correct and more portable and more legible.

":" can be replaced with any command that doesn't output
anything like true, eval... but ":" is the best bet as it's in
every shell and it's builtin in everyshell.

--
Stéphane

2007/06/01

regular expresions / eval / php

revisar, tomado de:

http://www.marotori.com/blog/?cat=10



Archive for the ‘PHP’ Category
Using PHP to highlight links in html
Sunday, March 4th, 2007 by Rob Thomson

Seems to me that there are loads of code samples that show you how to ‘auto highlight’ email addresses and web addresses in a string. Useful, but what happens when the link is already surrounded by an A tag?

I put together this little function (a little dirty but effective) to ‘ignore’ links that are already surrounded by an A tag. This prevents any unexpected double linking of your code.




function findlinks($string){

$string = $string ;

# regular expresion to find matches
$href_regex =”<”; // 1 start of the tag
$href_regex .=”\s*”; // 2 zero or more whitespace
$href_regex .=”a”; // 3 the a of the tag itself
$href_regex .=”\s+”; // 4 one or more whitespace
$href_regex .=”[^>]*”; // 5 zero or more of any character that is _not_ the end of the tag
$href_regex .=”href”; // 6 the href bit of the tag
$href_regex .=”\s*”; // 7 zero or more whitespace
$href_regex .=”=”; // 8 the = of the tag
$href_regex .=”\s*”; // 9 zero or more whitespace
$href_regex .=”[\”‘]?”; // 10 none or one of ” or ‘
$href_regex .=”(”; // 11 opening parenthesis, start of the bit we want to capture
$href_regex .=”[^\”‘ >]+”; // 12 one or more of any character _except_ our closing characters
$href_regex .=”)”; // 13 closing parenthesis, end of the bit we want to capture
$href_regex .=”[\”‘ >]”; // 14 closing chartacters of the bit we want to capture

$regex = “/”; // regex start delimiter
$regex .= $href_regex; //
$regex .= “/”; // regex end delimiter
$regex .= “i”; // Pattern Modifier - makes regex case insensative
$regex .= “s”; // Pattern Modifier - makes a dot metacharater in the pattern
// match all characters, including newlines
$regex .= “U”; // Pattern Modifier - makes the regex ungready

# first find and subst out all text area content
preg_match_all($regex, $string, $regs);
# replace all textarea content with a custom tag
$count = “1″;
if(is_array($regs[”0″])){
foreach($regs[”0″] as $tag){
$string = str_replace($tag,”{link-” . $count . “}”,$string);
$textarea[] = array(”field” => “{link-” . $count . “}”,”data” => $tag);
$count++;
}
}

$string = preg_replace(”/([\w\.]+)(@)([\S\.]+)\b/i”,”$0“,$string);
$string = preg_replace(”/((http(s?):\/\/)|(www\.))([\S\.]+)\b/i”,”$2$4$5“, $string);

# reassemble to handle php code input into text areas
if(is_array($textarea)){
foreach($textarea as $x){
$string = str_replace($x[field],$x[data],$string);
}
}

return trim($string);
}
?>



Anyone got anything better than this?

Posted in PHP | No Comments »
Using EVAL to parse an html file
Sunday, March 4th, 2007 by Rob Thomson

Every now and again I stumble upon a little bit of code that just ‘works’. Anyone who as ever coded in PHP and tried to ‘eval’ and html file is almost certain to have ended up a bit frustrated. It would seem that eval can only process pure PHP, and not a file that has any html tags etc in it.

Never mind! After trawling the net for a while I found this great code snippet that does the trick.



function eval_buffer($string) {
ob_start();
eval("$string[2];");
$return = ob_get_contents();
ob_end_clean();
return $return;
}

function eval_print_buffer($string) {
ob_start();
eval(”print $string[2];”);
$return = ob_get_contents();
ob_end_clean();
return $return;
}

function eval_html($string) {
$string = preg_replace_callback(”/(<\?=)(.*?)\?>/si”,
“eval_print_buffer”,$string);
return preg_replace_callback(”/(<\?php|<\?)(.*?)\?>/si”,
“eval_buffer”,$string);
}

?>


Works perfectly!

2007/05/31

send mail / VBA excel

http://www.rondebruin.nl/sendmail.htm

http://www.paulsadowski.com/WSH/cdo.htm

Keith74


#===============================================================
#===============================================================

maybe that helps:


    Sub NeueMail2Outbox()

    Dim ol, olns, p_out As Outlook.MAPIFolder
    Dim neumail As Outlook.MailItem, empfänger

    Set ol = CreateObject("Outlook.Application")
    Set olns = ol.GetNamespace("MAPI")
    Set p_out = olns.GetDefaultFolder(olFolderOutbox)

    neumail = p_out.Items.Add

    With neumail
    .Recipient.Add "Bernd Meier"
    .Subject = "Einladung"
    .Body = "Einladung zum Gartenfest" _
    & vbCr & "Wann? Am 20. Juni 2000" _
    & vbCr & "Wo? Biergarten Zur Linde, München"
    ' For Each empfänger In neumail.Recipients()
    ' empfänger.Resolve
    ' Next
    ' .Send
    End With


gNeandr

#===============================================================
#===============================================================

http://www.paulsadowski.com/WSH/cdo.htm

that page shows how to use MS CDO

- i enabled its reference, and worked fine with the simple example


    Sub Mail1()

    Set objMessage = CreateObject("CDO.Message")
    objMessage.Subject = "Example CDO Message"
    objMessage.From = "toto@toto.com"
    objMessage.To = "tata@tata.com"
    objMessage.TextBody = "This is some sample message text."

    '==This section provides the configuration information for the remote
    SMTP server.
    '==Normally you will only change the server name or IP.

    objMessage.Configuration.Fields.item _
    ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2

    'Name or IP of Remote SMTP Server
    objMessage.Configuration.Fields.item _
    ("http://schemas.microsoft.com/cdo/configuration/smtpserver") _
    = "smtp.toto.com"

    'Server port (typically 25)
    objMessage.Configuration.Fields.item _
    ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25

    objMessage.Configuration.Fields.Update

    '==End remote SMTP server configuration section==

    objMessage.Send

    End Sub



#===============================================================
#===============================================================


http://www.rondebruin.nl/cdo.htm

Norman Jones

2007/05/30

piping text lines / "Here Documents"

Many ways to do this. Here's two:

    prog << EOF
    line 1
    line 2
    ...
    line N
    EOF


or

    (echo "line 1"
    echo "line 2"
    ...
    echo "line N") | prog


The "<< EOF" syntax creates what is usually called a "here is" document.
The shell takes all of the lines up to (but not including) the line that
begins "EOF" (in column 1), writes all those lines to a temporary file,
and then feeds that file as standard input to "prog", just as in your
original example (except that the shell is doing the work for you). When
"prog" has finished executing, the temporary file is deleted. You can
replace "EOF" by any string that does not appear in the input; the "<<" is
the important part.

Another version of it uses the syntax "<<-EOF". The effect of the "-" is
to allow the terminating EOF to be on a line that has leading white space
on it; it is an instruction to ignore any leading white space in the data
(all of the data, not just the EOF line).

It's usually better to use the facilities provided by the shell rather
than writing out the equivalent code using some other technique. Less code
usually leads to fewer bugs and easier maintenance, because it is
hopefully more readable that way. It's probably a bit more efficient to
use the "<< XXX" method, but not by a lot in this instance (unless you're
doing it very many times).

Steve Thompson

#-----------------------------------------------------
#-----------------------------------------------------


    % (echo "juan"; echo "1"; echo "alba") | sort
    1
    alba
    juan

    % sort << XXXX
    > 5
    > 2
    > 5
    > 1
    > b
    > c
    > XXXX
    1
    2
    5
    5
    b
    c


http://www.tdp.org

"Advanced Bash-Scripting Guide"
And check the chapter about "Here Documents".
Michael Heiming

#-----------------------------------------------------
#-----------------------------------------------------


    {
    echo "line 1"
    echo "line 2"
    ...
    echo "line N"

    } | prog


Or:


    printf "%s\n" "line 1" \
    "line 2" ... \
    "line N" | prog


Chris F.A. Johnson

#-----------------------------------------------------
#-----------------------------------------------------

One person already gave an example that uses the "<< EOF" syntax,
but if you really need to group commands' output together into
a pipe, and you have to commands (and not just interpolated strings),
you can do this:


    {
    echo "line 1"
    echo "line 2"
    echo "line 3"
    } | prog


Personally I like this since it is more flexible. You can chain
them:


    { echo 1; echo 2; } | { read x; read y; echo "$x / $y"; } | bc -l


Or nest them:


    {
    echo 1
    {
    echo 2
    echo 3
    } | sed -e 's/$/x/'
    echo 4
    } | sed -e 's/$/y/'


Also, in some cases, a better solution might be to use a function.

- Logan