VBAオブジェクトを自動生成しイベントを付与する。

2019.01.12

Logging

VBAオブジェクトを自動生成しイベントを付与する。
サンプルコードです。
ダウンロードはこちら
https://zip358.com/tool/sample.zip

Dim chg_class(0 To 5) As chg
Public Sub objset()
Dim obj_ctl As Control
Dim i As Integer
For i = LBound(chg_class) To UBound(chg_class)
    Set obj_ctl = UserForm1.Controls.Add("Forms.TextBox.1", "Box" & i)
    obj_ctl.Top = 10 + 20 * i
    obj_ctl.Width = 200
    obj_ctl.Height = 20
    obj_ctl.Text = "ここを変更してみて、またはダブルクリック(" & i & "番)"
    Set chg_class(i) = New chg
    chg_class(i).set_evn obj_ctl, i
    Set obj_ctl = Nothing
Next i
End Sub
Private WithEvents TextB As MSForms.TextBox
Private index_no As Integer
Public Sub set_evn(hoge_obj As MSForms.TextBox, hoge As Integer)
    Set TextB = hoge_obj
    index_no = hoge
End Sub
Private Sub TextB_Change()
    MsgBox TextB.Text 'UserForm1("Box" & index_no)
End Sub
Private Sub TextB_DblClick(ByVal Cancel As MSForms.ReturnBoolean)
    MsgBox TextB.Text 'UserForm1("Box" & index_no)
End Sub
Private Sub TextBox1_Change()
MsgBox TextBox1
End Sub
Private Sub CommandButton1_Click()
End Sub
Private Sub UserForm_Click()
End Sub

タグ

0, , 10, 20, 200, 358, 5, Add, amp, as, Box, chg, class, com, Control, Controls, ctl, Dim, For, Forms, Height, Integer, LBound, obj, objset, public, sample, set, Sub, Text, TextBox, To, tool, TOP, UBound, UserForm, VBA, Width, zip, イベント, オブジェクト, コード, ここ, こちら, サンプル, ダウンロード, 付与, 変更, 自動生成,

さくらレンタルサーバーとかで制限以上のクロンタブ(crontab)を使う方法。

2018.11.08

Logging

さくらレンタルサーバーとかで制限以上のクロンタブ(crontab)を使う方法
10年ぐらいまえのコードを見直して改善したコードが下記になります。
10年前はクラスを使わない方法で構築したのだけど、今回はクラスの概念を
使って構築。ここ何年かで自分のコーディングの技術は上がっているかといえば
そうでもないですが、昔よりかは技術の幅は広がっていると思いたいw
※qiita日付は数年前にUPしたのですけど、コード自体は10年前のコードです。

追記:2022/10/08 修正:詳しくはコチラ
https://qiita.com/question909/items/8f1df9b62ab4fba76243

<?php
//5分刻みに対して有効な無限クローン 処理が負荷の場合どうなるかは知りません。
date_default_timezone_set('Asia/Tokyo');
class cron{

    public function d_m($obj)
    {
            if($obj->m==="*")return true;
            if(preg_match("/,/",$obj->m))return $this->comma($obj->m,date("m"));
            if((int)$obj->m === (int)date("m"))return true;

            return false;
    }

    public function d_d($obj)
    {
            if($obj->d==="*")return true;
            if(preg_match("/,/",$obj->d))return $this->comma($obj->d,date("d"));
            if((int)$obj->d === (int)date("d"))return true;

            return false;
    }

    public function d_H($obj)
    {
            if(preg_match("/\*\/[0-9]{1,2}/",$obj->H)){
                $H = explode("/",$obj->H);
                if((int)$H[1]>0 && ((int)date("H") % (int)$H[1])===0)return true;
            }else{
                if($obj->H==="*")return true;
                if(preg_match("/,/",$obj->H))return $this->comma($obj->H,date("H"));
                if((int)$obj->H === (int)date("H"))return true;

            }
            return false;
    }

    public function d_i($obj)
    {
            if(preg_match("/\*\/[0-9]{1,2}/",$obj->i)){
                $i = explode("/",$obj->i);
                if((int)$i[1]>0 && ((int)date("i") % (int)$i[1])===0)return true;
            }else{
                if($obj->i==="*")return true;
                if(preg_match("/,/",$obj->i))return $this->comma($obj->i,date("i"));
                if((int)$obj->i === (int)date("i"))return true;

            }
            return false;
    }

    //曜日 0=日曜日 6=土曜日
    public function d_w($obj)
    {
            if((int)$obj->w[date("w")]===1)return true;
            return false;
    }

    public  function comma($c="",$t=""){
        if($c==="")return false;
        if($t==="")return false;
        $flg = false;
        foreach(explode(",",$c) as $cc){
            if((int)$cc===(int)$t)$flg = true;
        }
        return $flg;
    }


    public function d_command($obj){
        if($obj->command){
            exec($obj->command . " > /dev/null &");
        }
        return true;
    }

}
if ($argv[1]) {
   $filename = $argv[1];
    if(is_file($filename)){
        $jsn = json_decode(file_get_contents($filename));
        $cron = new cron();
        try {
            foreach($jsn as $obj){
                if($cron->d_m($obj)){
                    if($cron->d_d($obj)){
                        if($cron->d_H($obj)){
                            if($cron->d_i($obj)){
                                if($cron->d_w($obj)){
                                    $cron->d_command($obj);//波動拳{{{{
                                }
                            }
                        }
                    }
                }
            }
        } catch (\Throwable $th) {
            print $th->getMessage();
        }
    }
}

タグ

08, 10, 2022, 39, 5, Asia, class, cron, crontab, date, default, function, if, lt, obj, php, public, qiita, set, timezone, Tokyo, UP, , クラス, クローン, クロン, コーディング, コード, ここ, コチラ, サーバー, さくら, タブ, まえ, レンタル, 下記, 今回, 何年か, 修正, 処理, 分刻み, 制限, 場合, , 技術, 改善, , 方法, 日付, , 有効, 概念, 構築, 無限, 自体, 自分, 負荷, 追記,

Gmail未読一括既読、最終形態みたいなものです。

2018.07.15

Logging


Gmail未読一括既読、最終形態みたいなものです。
どうぞ、お使いください。
前回のプログラムをトリガー呼び出すと下記のエラーが表示されますが
今回のコードを実行してもプログラムエラーは表示されません。
よって未読メールから既読メールになります。

[object Object] を (class) に変換できません。

前回のコードはこちらです。
見比べてみると違いがわかると思います、
ちなみにエラーで落ちていた所は、3行目になります。

function gmailbat () {
  gm = GmailApp.search("is:unread");
  if(gm.length){
    gm.forEach(function(m,i,a){
      if(m.isUnread()){
        m.markRead();
      }
    });
  }
  if(gm.length){
      return gmailbat();
  }
  return true;
}

タグ

class, function, function gmailbat, gm, gm.forEach, gm.length, GmailApp.search, Gmail未読一括既読, if, is, m.isUnread, m.markRead, object Object, quot, return gmailbat, return true, unread&quot, エラー, トリガー, 既読メール,

昨日の続き、cronPHP(´Д`)、一つのジョブから複数のPHPファイルを実行させる方法。

2015.06.25

Logging

<?php
//5分刻みに対して有効な無限クローン 処理が負荷の場合どうなるかは知りません。
date_default_timezone_set('Asia/Tokyo');
class cron{

    public function d_m($obj)
    {
            if($obj->m==="*")return true;
            if(preg_match("/,/",$obj->m))return $this->comma($obj->m,date("m"));
            if((int)$obj->m === (int)date("m"))return true;

            return false;
    }

    public function d_d($obj)
    {
            if($obj->d==="*")return true;
            if(preg_match("/,/",$obj->d))return $this->comma($obj->d,date("d"));
            if((int)$obj->d === (int)date("d"))return true;

            return false;
    }

    public function d_H($obj)
    {
            if(preg_match("/\*\/[0-9]{1,2}/",$obj->H)){
                $H = explode("/",$obj->H);
                if((int)$H[1]>0 && ((int)date("H") % (int)$H[1])===0)return true;
            }else{
                if($obj->H==="*")return true;
                if(preg_match("/,/",$obj->H))return $this->comma($obj->H,date("H"));
                if((int)$obj->H === (int)date("H"))return true;

            }
            return false;
    }

    public function d_i($obj)
    {
            if(preg_match("/\*\/[0-9]{1,2}/",$obj->i)){
                $i = explode("/",$obj->i);
                if((int)$i[1]>0 && ((int)date("i") % (int)$i[1])===0)return true;
            }else{
                if($obj->i==="*")return true;
                if(preg_match("/,/",$obj->i))return $this->comma($obj->i,date("i"));
                if((int)$obj->i === (int)date("i"))return true;

            }
            return false;
    }

    //曜日 0=日曜日 6=土曜日
    public function d_w($obj)
    {
            if((int)$obj->w[date("w")]===1)return true;
            return false;
    }

    public  function comma($c="",$t=""){
        if($c==="")return false;
        if($t==="")return false;
        $flg = false;
        foreach(explode(",",$c) as $cc){
            if((int)$cc===(int)$t)$flg = true;
        }
        return $flg;
    }


    public function d_command($obj){
        if($obj->command){
            exec($obj->command . " > /dev/null &");
        }
        return true;
    }

}
if ($argv[1]) {
   $filename = $argv[1];
    if(is_file($filename)){
        $jsn = json_decode(file_get_contents($filename));
        $cron = new cron();
        try {
            foreach($jsn as $obj){
                if($cron->d_m($obj)){
                    if($cron->d_d($obj)){
                        if($cron->d_H($obj)){
                            if($cron->d_i($obj)){
                                if($cron->d_w($obj)){
                                    $cron->d_command($obj);//波動拳{{{{
                                }
                            }
                        }
                    }
                }
            }
        } catch (\Throwable $th) {
            print $th->getMessage();
        }
    }
}

 
この頃、ネタがないので手抜き投稿です。気づいた人どのぐらいいるのだろうか?
Qittaに公開しました。https://qiita.com/question909/items/8f1df9b62ab4fba76243

タグ

39, 5, Asia, class, comma, cron, cronphp, date, default, function, gt, if, int, lt, match, obj, php, preg, public, quot, retu, return, set, this, timezone, Tokyo, true, クローン, ジョブ, ファイル, 一つ, 処理, 分刻み, 場合, 実行, 方法, 昨日, 有効, 無限, 複数, 負荷,

cronPHPを作ってみた朝の続き。

2015.06.24

Logging


 
cronPHPを作ってみた朝の続き・・・たぶん、コレだけで十分かと思います(稼働させてないのでどう動くかは不明?)。仕事帰って作りました。この頃、もっと勉強しないとなと思うこの頃です。いまの自分に足りないのは間違いなく技術力です、あとタイピングとか・・・かなり遅いので生産性がかなり低いです。英語を打つのに遅すぎる・・・・。日本語はまぁまぁ早いのですけど。キーを覚えているというよりは何となく覚えているので・・・・なぜ、タイピングできるのか自分でも不思議なのです。
 

追記2022/09/06:詳しくは、こちらを参照くださいませ

<?php
//5分刻みに対して有効な無限クローン 処理が負荷の場合どうなるかは知りません。
date_default_timezone_set('Asia/Tokyo');
class cron{

    public function d_m($obj)
    {
            if($obj->m==="*")return true;
            if(preg_match("/,/",$obj->m))return $this->comma($obj->m,date("m"));
            if((int)$obj->m === (int)date("m"))return true;

            return false;
    }

    public function d_d($obj)
    {
            if($obj->d==="*")return true;
            if(preg_match("/,/",$obj->d))return $this->comma($obj->d,date("d"));
            if((int)$obj->d === (int)date("d"))return true;

            return false;
    }

    public function d_H($obj)
    {
            if(preg_match("/\*\/[0-9]{1,2}/",$obj->H)){
                $H = explode("/",$obj->H);
                if((int)$H[1]>0 && ((int)date("H") % (int)$H[1])===0)return true;
            }else{
                if($obj->H==="*")return true;
                if(preg_match("/,/",$obj->H))return $this->comma($obj->H,date("H"));
                if((int)$obj->H === (int)date("H"))return true;

            }
            return false;
    }

    public function d_i($obj)
    {
            if(preg_match("/\*\/[0-9]{1,2}/",$obj->i)){
                $i = explode("/",$obj->i);
                if((int)$i[1]>0 && ((int)date("i") % (int)$i[1])===0)return true;
            }else{
                if($obj->i==="*")return true;
                if(preg_match("/,/",$obj->i))return $this->comma($obj->i,date("i"));
                if((int)$obj->i === (int)date("i"))return true;

            }
            return false;
    }

    //曜日 0=日曜日 6=土曜日
    public function d_w($obj)
    {
            if((int)$obj->w[date("w")]===1)return true;
            return false;
    }

    public  function comma($c="",$t=""){
        if($c==="")return false;
        if($t==="")return false;
        $flg = false;
        foreach(explode(",",$c) as $cc){
            if((int)$cc===(int)$t)$flg = true;
        }
        return $flg;
    }


    public function d_command($obj){
        if($obj->command){
            exec($obj->command . " > /dev/null &");
        }
        return true;
    }

}
if ($argv[1]) {
   $filename = $argv[1];
    if(is_file($filename)){
        $jsn = json_decode(file_get_contents($filename));
        $cron = new cron();
        try {
            foreach($jsn as $obj){
                if($cron->d_m($obj)){
                    if($cron->d_d($obj)){
                        if($cron->d_H($obj)){
                            if($cron->d_i($obj)){
                                if($cron->d_w($obj)){
                                    $cron->d_command($obj);//波動拳{{{{
                                }
                            }
                        }
                    }
                }
            }
        } catch (\Throwable $th) {
            print $th->getMessage();
        }
    }
}

タグ

06, 09, 2022, 39, 5, Asia, class, cron, cronphp, date, default, function, lt, nbsp, obj, php, public, set, timezone, Tokyo, いま, かなり, キー, クローン, こちら, コレ, ダイビング, 不思議, 不明, 仕事, 処理, 分刻み, 勉強, 参照, 場合, 技術力, 日本語, 有効, , 無限, 生産性, 稼働, 自分, 英語, 負荷, 追記, ,