・ VBAのパートタイム利用
・ 文字列の変換
・ 日付文字列から曜日を取得
LispやActiveXの関数にはないけれど、VBAで簡単にできること。
たとえば、文字の変換、乱数の取得、時間の計算など。
これらはVBASTMTコマンドで Lisp から VBA
をパートタイムで利用することによって比較的簡単に実現できます。
値の引渡しには、ユーザー変数 USERS1〜5 を利用します。
初回の実行時に VBAシステムの初期化 に時間がかかるのが難点
次のは、文字列の変換(StrConv)のサンプルです。
(defun Jof_vb_StrConv (str_org ;変換対象文字列; mode ;変換形式(VBAのStrConvに準ずる)整数; ; 1:大文字に変換; ; 2:小文字に変換; ; 3:単語の先頭を大文字に変換; ; 4:半角文字を全角文字に変換; ; 8:全角文字を半角文字に変換; ; 16:ひらがなをカタカナに変換; ; 32:カタカナをひらがなに変換; / usrs5_def usrs4_def str_com str_ret) (setq usrs5_def (getvar "USERS5")) (setq usrs4_def (getvar "USERS4")) (setvar "USERS5" str_org) (setvar "USERS4" (itoa mode)) (setq str_com "ThisDrawing.SetVariable \"USERS5\" , StrConv((ThisDrawing.GetVariable (\"USERS5\")) , (ThisDrawing.GetVariable (\"USERS4\")))") (command "VBASTMT" str_com) (setq str_ret (getvar "USERS5")) (setvar "USERS5" usrs5_def) (setvar "USERS4" usrs4_def) str_ret ) 実行結果 コマンド: (load "Jof_vb_strconv") JOF_VB_STRCONV コマンド: (jof_vb_strconv "あいうエ緒" 16) VBASTMT VBA システムを初期化中... VBASTMT 式: ThisDrawing.SetVariable "USERS5" , StrConv((ThisDrawing.GetVariable ("USERS5")) , (ThisDrawing.GetVariable ("USERS4"))) コマンド: "アイウエ緒" コマンド: (jof_vb_strconv "あいうエ緒" 32) VBASTMT 式: ThisDrawing.SetVariable "USERS5" , StrConv((ThisDrawing.GetVariable ("USERS5")) , (ThisDrawing.GetVariable ("USERS4"))) コマンド: "あいうえ緒" コマンド: 'VLIDE コマンド:
次のは、曜日の取得(WeekdayName)のサンプルです。
(defun Jof_vb_WeekdayName (str_data ;日付文字列; / usrs5_def str_com str_ret) (setq usrs5_def (getvar "USERS5")) (setvar "USERS5" str_data) (setq str_com "ThisDrawing.SetVariable \"USERS5\" , WeekdayName (Weekday (ThisDrawing.GetVariable (\"USERS5\")))") (command "VBASTMT" str_com) (setq str_ret (getvar "USERS5")) (setvar "USERS5" usrs5_def) str_ret )
実行結果 コマンド: (load "Jof_vb_weekdayname") JOF_VB_WEEKDAYNAME コマンド: (jof_vb_weekdayname "2000/01/01") VBASTMT 式: ThisDrawing.SetVariable "USERS5" , WeekdayName (Weekday (ThisDrawing.GetVariable ("USERS5"))) コマンド: "土曜日"