G3028_マクロの実験①

2025417

9:44

G3028_pc_goma_note_macro_experiment_1

 

Version:0.9 StartHTML:00000000 EndHTML:00000000 StartFragment:00000000 EndFragment:00000000 G3028-プロジェクト

 

マクロの内容

 

 

プロジェクト一覧に「マクロ」を追加し、上の方に配置します

 

 

 

 

マクロはプロジェクト毎に分類が欲しいので3階層管理を作ります

 

 

 

メインタイトルの登録までは、改造なしで処理できます

 

 

 

サブタイトル一覧(パス)を追加します

 

 

 

サブタイトル一覧(パス)の入力画面を追加します

 

 

 

 

サブタイトルデータ(入力)を追加します

 

 

 

マクロの実験入力です

 

 

この一部だけ実行してみます

 

 

 

 

マクロ処理のコード

 

 

 

 

 

追記

2025.04.20 SAN (01:38) goma0099 -3804408-

 

文字数判定、整列など

 

 

定義の事例

 

 

実行結果

 

 

ここまでのコード例

 

 

// マクロ実行

private void Form5_macro_run()

{

string proj_title = Form1.Proj_title;

string main_title = Form1.Main_title;

string sub_title = Form1.Sub_title;

 

string[][] tbl = new string[8][];

string fil_path = Form1.Prm_dat_get("データルートフォルダ") + @"\" + proj_title + @"\"

+ proj_title + "_" + main_title + "_" + sub_title + ".txt";

 

int fld_max;

int lin;

int lin_sta, lin_end,dat_max;

string tmp_dat = "";

//string ans_dat = "";

int num_dat = 0;

int x, y;

bool end_flg = false;

 

if (System.IO.File.Exists(fil_path) == false) return;

 

tbl[0] = Form1.Com_txt_tbl_red2(fil_path, 0, "", out fld_max);

if (fld_max == 0) return;

 

tbl[1] = Form1.Com_txt_tbl_red2(fil_path, 1, "", out fld_max);

tbl[2] = Form1.Com_txt_tbl_red2(fil_path, 2, "", out fld_max);

tbl[3] = Form1.Com_txt_tbl_red2(fil_path, 3, "", out fld_max);

tbl[4] = Form1.Com_txt_tbl_red2(fil_path, 4, "", out fld_max);

tbl[5] = Form1.Com_txt_tbl_red2(fil_path, 5, "", out fld_max);

tbl[6] = Form1.Com_txt_tbl_red2(fil_path, 6, "", out fld_max);

tbl[7] = Form1.Com_txt_tbl_red2(fil_path, 7, "", out fld_max);

 

lin = 0;

dat_max = 0;

while(true)

{

lin_sta = lin_end = 0;

switch (tbl[0][lin].Trim())

{

case "リストボックス配置":

Form6_lst_box(tbl[1][lin], tbl[2][lin], tbl[3][lin], tbl[4][lin], tbl[5][lin]);

break;

case "ファイル一覧":

Form6_fil_lst(tbl[1][lin], tbl[2][lin], tbl[3][lin]);

break;

case "データ件数":

dat_max = Form6_loop_max_get(tbl[1][lin], tbl[2][lin]);

//Form1.msg2("dat_max", dat_max.ToString(), "111");

break;

case "[":

case "{":

case "(":

lin_sta = lin + 1;

lin_end = 0;

for (int i = lin + 1; i < fld_max; i++)

{

switch (tbl[0][i])

{

case "]":

case "}":

case ")":

lin_end = i - 1;

break;

}

if (lin_end != 0) break;

}

if (lin_end == 0)

{

Form1.msg("ループの終端がありません 中止します");

return;

}

break;

case "整列コピー":

Form6_sort_copy(tbl[1][lin], tbl[2][lin], tbl[3][lin]);

break;

}

 

if (0 < lin_sta && 0 < lin_end)

{

//Form1.msg2("sta_end", lin_sta.ToString(), lin_end.ToString());

//Form1.msg2("dat_max", dat_max.ToString(), "333");

// ループ実行

for (x=0;x<dat_max;x++)

{

for (y = lin_sta; y <= lin_end; y++)

{

end_flg = false;

switch (tbl[0][y].Trim())

{

case "文字列取得":

tmp_dat = Form6_string_get(x, tbl[1][y], tbl[2][y]);

//Form1.msg2("文字列取得",tmp_dat, "");

break;

case "文字列分離":

tmp_dat = Form6_string_cut(tmp_dat, tbl[1][y], tbl[2][y]);

//Form1.msg2("文字列分離", tmp_dat, "");

break;

case "文字数取得":

num_dat = tmp_dat.Length;

//Form1.msg2("文字数取得", num_dat.ToString(), "");

break;

case "数値範囲外パス":

//Form1.msg2("数値範囲外パス", num_dat.ToString(), "");

if (Form6_num_min_max_chk(num_dat, tbl[1][y], tbl[2][y]) == false) end_flg = true;

break;

case "代入":

Form6_dat_upd(tmp_dat, tbl[1][y], tbl[2][y]);

break;

}

if (end_flg == true) break;

}

 

}

lin = lin_end;

}

 

lin++;

if (fld_max <= lin) break;

}

 

}

// 整列コピー

private void Form6_sort_copy(

string prm_dat_type,

string prm_sou_no,

string prm_des_no)

{

int sou_no, des_no;

 

List<string> list = new List<string>();

 

if (int.TryParse(prm_sou_no, out sou_no) == false) sou_no = 0;

if (int.TryParse(prm_des_no, out des_no) == false) des_no = 0;

 

switch(prm_dat_type.Trim())

{

case "リストボックス":

Form1.msg2("sou / des",sou_no.ToString(), des_no.ToString());

int lst_max = Form1.Lst_tbl[sou_no].Items.Count;

for(int i = 0;i<lst_max;i++) list.Add(Form1.Lst_tbl[sou_no].Items[i].ToString());

list.Sort();

for (int i = 0; i < lst_max; i++) Form1.Lst_tbl[des_no].Items.Add(list[i]);

 

break;

}

 

 

}

 

// 結果代入

private void Form6_dat_upd(string prm_dat, string prm_type, string prm_lst_no)

{

int lst_no;

 

switch (prm_type.Trim())

{

case "リストボックス":

if (int.TryParse(prm_lst_no, out lst_no) == false) lst_no = 0;

Form1.Lst_tbl[lst_no].Items.Add(prm_dat);

break;

}

 

}

 

// 数値範囲検査

private bool Form6_num_min_max_chk(int prm_num_dat, string prm_min, string prm_max)

{

int chk_min, chk_max;

bool ans_flg = false;

 

if (int.TryParse(prm_min, out chk_min) == false) chk_min = 0;

if (int.TryParse(prm_max, out chk_max) == false) chk_max = 0;

 

if (chk_min <= prm_num_dat && prm_num_dat <= chk_max) ans_flg = true;

 

return ans_flg;

}

 

// 文字列分離

private string Form6_string_cut(string prm_tmp_dat, string prm_cut_type, string prm_get_no)

{

char[] cha_tbl = prm_cut_type.ToCharArray();

string[] cut_tbl = prm_tmp_dat.Split(cha_tbl[0]);

int get_no;

 

if (int.TryParse(prm_get_no, out get_no) == false) get_no = 0;

 

if (cut_tbl.Length <= get_no) return "";    // オーバーフロー

 

return cut_tbl[get_no];

}

// ループ件数取得

private int Form6_loop_max_get(string prm_type, string prm_dat)

{

int loop_max = 0;

int lst_no;

switch (prm_type.Trim())

{

case "リストボックス":

if (int.TryParse(prm_dat, out lst_no) == false) lst_no = 0;

loop_max = Form1.Lst_tbl[lst_no].Items.Count;

break;

}

 

return loop_max;

}

// 文字列取得

private string Form6_string_get(int prm_loop_no,string prm_type,string prm_dat)

{

string tmp_dat = "";

int lst_no;

switch (prm_type.Trim())

{

case "リストボックス":

if (int.TryParse(prm_dat, out lst_no) == false) lst_no = 0;

tmp_dat = Form1.Lst_tbl[lst_no].Items[prm_loop_no].ToString();

break;

}

 

 

return tmp_dat;

}

 

// リストボックス配置

private void Form6_lst_box(

string prm_lst_no,

string prm_x,

string prm_y,

string prm_width,

string prm_height)

{

int lst_no, x, y, width, height;

 

if (int.TryParse(prm_lst_no, out lst_no) == false) lst_no = 0;

if (int.TryParse(prm_x, out x) == false) x = 0;

if (int.TryParse(prm_y, out y) == false) y = 0;

if (int.TryParse(prm_width, out width) == false) width = 0;

if (int.TryParse(prm_height, out height) == false) height = 0;

 

// リストボックスの配置

Form1.Lst_tbl[lst_no] = new ListBox();

this.Controls.Add(Form1.Lst_tbl[lst_no]);

 

Form1.Lst_tbl[lst_no].Location = new Point(x, y);

Form1.Lst_tbl[lst_no].Size = new Size(width, height);

 

}

// ファイル一覧作成

private void Form6_fil_lst(

string prm_folder,

string prm_type,

string prm_lst_no)

{

int lst_no,lst_max;

 

if (int.TryParse(prm_lst_no, out lst_no) == false) lst_no = 0;

 

string[] fil_lst = System.IO.Directory.GetFiles(prm_folder, "*.*", System.IO.SearchOption.TopDirectoryOnly);

lst_max = fil_lst.Length;

 

switch (prm_type.Trim())

{

case "リストボックス":

for (int i = 0; i < lst_max; i++)

{

Form1.Lst_tbl[lst_no].Items.Add(Path.GetFileName(fil_lst[i]));

}

break;

}

 

}

}

}

 

この記事は続きますが、時間を要するためここで停止しておきます