2
2

More than 5 years have passed since last update.

HSPでgetter・setterを使わないでモジュール変数にアクセスする

Posted at

納得C言語 [第14回]構造体 - ほぷしぃの例題1を移植。
直接モジュール変数に触るにはgosubで飛ばさせてラベルをコールバックで読ませれば良い。
それでVBのWith的用法が可能となるはず。

#runtime "hsp3cl"

//構造体の型宣言
#module OLD no,name,s_year,s_class
    #modinit int _no,str _name,int _s_year,str _s_class
        no=_no            //番号
        name=_name        //名前
        s_year=_s_year    //年
        s_class=_s_class  //クラス
    return

    #modfunc withEnd var fn
        gosub fn
    return
#global

mes "学籍番号\t 名前\t学年\tクラス"

//構造体の初期化
dimtype _old,5,15
newmod _old,OLD, 1,"上杉謙信"    ,3,"A"
newmod _old,OLD, 2,"武田信玄"    ,3,"A"
newmod _old,OLD, 3,"豊臣秀吉"    ,3,"A"
newmod _old,OLD, 4,"明智光秀"    ,3,"A"
newmod _old,OLD, 5,"織田信長"    ,3,"A"
newmod _old,OLD, 6,"徳川家康"    ,3,"A"
newmod _old,OLD, 7,"聖徳太子"    ,3,"A"
newmod _old,OLD, 8,"マッカーサー",3,"A"
newmod _old,OLD, 9,"ザビエル"    ,3,"A"
newmod _old,OLD,10,"北条政子"    ,3,"A"
newmod _old,OLD,11,"沖田総司"    ,3,"A"
newmod _old,OLD,12,"永倉新八"    ,3,"A"
newmod _old,OLD,13,"斉藤一"      ,3,"A"
newmod _old,OLD,14,"松原忠治"    ,3,"A"
newmod _old,OLD,15,"武田観柳斎"  ,3,"A"

foreach _old
    if 0 {*_with
        //結果の出力
        mes strf("%7d%15s%5d%10s", no@OLD, name@OLD, s_year@OLD, s_class@OLD)
    return}
    with=*_with
    withEnd _old(cnt),with
loop
2
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2