【HSP3.4】選択した履歴を保持する

もすちゃん@deratege

2015年07月11日 16:18

コンボボックス(ドロップダウンリスト)で選択した履歴をリストの先頭に表示させる。
INIファイルの処理はここのini module ver2モジュールを使用

#include "inim2.hsp"
INIInit "sample1.ini"
hismax=5 //保持する履歴の最大値

// 文字列リストの定義
list="東京\n大阪\n名古屋\n浜松\n静岡\n福井\n三重\n津\n岡崎"

// iniに保存した履歴の取得
if INIGet("sample1","history"){his1=refstr}else{his1=""}
strrep his1,"|","\n"
notesel his1:hislg=notemax:noteunsel //履歴の行数(hislg)を取得

// 表示用文字列の生成
list1=his1+"-----\n"+list

//コンボボックスの設置
combox cb,100,list1
oid=stat //オブジェクトIDを取得

//リストボックスの設置
listbox lb,100,list1
lid=stat //オブジェクトIDを取得

button "変更",*henko
stop

*henko
if cb = -1 :stop //未選択の場合は処理中止
if cb = hislg :stop //区切り文字の場合も処理中止
notesel list1:noteget tx,cb:noteunsel //選択文字列を抽出
notesel his1
repeat hislg
noteget tx1,cnt
if tx1=tx :notedel cnt:break //履歴と一致したらその行を削除
loop
noteadd tx,0 //履歴の先頭に追加
if notemax=6 : notedel 5 //行数が5を超えたら削る
hislg=notemax //履歴の長さをセットする
noteunsel
his2=his1
strrep his2,"\n","|"
INISet "sample1","history",his2
cb=-1 //未選択の状態にする
// 表示用文字列の再生成
list1=his1+"-----\n"+list

objprm oid,list1
objprm lid,list1

stop
関連記事