スクリプト言語の HSP については、公式ホームページの「HSPTV!」をどうぞ。
このページは「単位文字列について」シリーズの1つです。
ここには、HSPで5桁のバイト/秒文字列を作成するサンプルを紹介します。(戻る)
小技集のサンプル
管理上このサンプルは sample235(5桁バイト/秒の文字列を作成).hsp のソースです。
//------------------------------------------------------------------------------ // 5桁バイト/秒の文字列を作成 by 科学太郎 //============================================================================== // 新規作成日:2018-08-09 (木) 12:40:00 // 最終更新日:2018-08-09 (木) 12:48:00 //------------------------------------------------------------------------------ //-------------------------------------- // 記号定数 //-------------------------------------- #define MSG_SPACE " " //-------------------------------------- // メイン部 //-------------------------------------- *Init ;バイト/秒 sdim ByteUnits,9 ByteUnits(0)=" Bps","KBps","MBps","GBps","TBps","PBps","EBps","ZBps","YBps" *Main screen 0,640,480,SCREEN_NORMAL|SCREEN_FIXEDSIZE syscolor 15:boxf:color:title "5桁バイト/秒の文字列を作成 by 科学太郎" ;固定5桁 s="" a=1.0 repeat 90 s+=MakeByteUnit5A(a)+"\n" a*=2.0 loop ;可変5桁 t="" a=1.0 repeat 90 t+=MakeByteUnit5B(a)+"\n" a*=2.0 loop ;文字 font MSGOTHIC,14 x=ginfo_winX/2 y=ginfo_winY-20 color $00,$00,$00:boxf color $FF,$FF,$00:pos 0,3:mes "《固定5桁のバイト/秒》" color $FF,$FF,$00:pos x,3:mes "《可変5桁のバイト/秒》" ;結果 font MSGOTHIC,12:objmode 2 pos 0,20:mesbox s,x,y,5,0 pos x,20:mesbox t,x,y,5,0 stop //-------------------------------------- // 5桁バイト/秒の文字列を作成 //-------------------------------------- #defcfunc MakeByteUnit5A double _size_,\ local nPos,\ local dbSize dbSize=(_size_) if(dbSize<1024.0){ return strf("%5.f",dbSize)+MSG_SPACE+ByteUnits(nPos) } while(dbSize>=1024.0) dbSize/=1024.0:nPos++ wend if(dbSize>=1000.0){ dbSize/=1024.0:nPos++ } return strf("%5.1f",dbSize)+MSG_SPACE+ByteUnits(nPos) //-------------------------------------- // 5桁バイト/秒の文字列を作成 //-------------------------------------- #defcfunc MakeByteUnit5B double _size_,\ local nPos,\ local dbSize,\ local szSize dbSize=(_size_) if(dbSize<1024.0){ return strf("%5.f",dbSize)+MSG_SPACE+ByteUnits(nPos) } while(dbSize>=1024.0) dbSize/=1024.0:nPos++ wend if(dbSize>=1000.0){ dbSize/=1024.0:nPos++ } ;補正 szSize=strf("%f",dbSize) :poke szSize,5 if(peek(szSize,4)=='.') :poke szSize,4 return strf("%5s",szSize)+MSG_SPACE+ByteUnits(nPos) //------------------------------------------------------------------------------ // End of sample235(5桁バイト/秒の文字列を作成).hsp //------------------------------------------------------------------------------
スクリーン・ショット
実行結果
固定5桁 | 可変5桁 |
---|---|
1 Bps 2 Bps 4 Bps 8 Bps 16 Bps 32 Bps 64 Bps 128 Bps 256 Bps 512 Bps 1.0 KBps 2.0 KBps 4.0 KBps 8.0 KBps 16.0 KBps 32.0 KBps 64.0 KBps 128.0 KBps 256.0 KBps 512.0 KBps 1.0 MBps 2.0 MBps 4.0 MBps 8.0 MBps 16.0 MBps 32.0 MBps 64.0 MBps 128.0 MBps 256.0 MBps 512.0 MBps 1.0 GBps 2.0 GBps 4.0 GBps 8.0 GBps 16.0 GBps 32.0 GBps 64.0 GBps 128.0 GBps 256.0 GBps 512.0 GBps 1.0 TBps 2.0 TBps 4.0 TBps 8.0 TBps 16.0 TBps 32.0 TBps 64.0 TBps 128.0 TBps 256.0 TBps 512.0 TBps 1.0 PBps 2.0 PBps 4.0 PBps 8.0 PBps 16.0 PBps 32.0 PBps 64.0 PBps 128.0 PBps 256.0 PBps 512.0 PBps 1.0 EBps 2.0 EBps 4.0 EBps 8.0 EBps 16.0 EBps 32.0 EBps 64.0 EBps 128.0 EBps 256.0 EBps 512.0 EBps 1.0 ZBps 2.0 ZBps 4.0 ZBps 8.0 ZBps 16.0 ZBps 32.0 ZBps 64.0 ZBps 128.0 ZBps 256.0 ZBps 512.0 ZBps 1.0 YBps 2.0 YBps 4.0 YBps 8.0 YBps 16.0 YBps 32.0 YBps 64.0 YBps 128.0 YBps 256.0 YBps 512.0 YBps |
1 Bps 2 Bps 4 Bps 8 Bps 16 Bps 32 Bps 64 Bps 128 Bps 256 Bps 512 Bps 1.000 KBps 2.000 KBps 4.000 KBps 8.000 KBps 16.00 KBps 32.00 KBps 64.00 KBps 128.0 KBps 256.0 KBps 512.0 KBps 1.000 MBps 2.000 MBps 4.000 MBps 8.000 MBps 16.00 MBps 32.00 MBps 64.00 MBps 128.0 MBps 256.0 MBps 512.0 MBps 1.000 GBps 2.000 GBps 4.000 GBps 8.000 GBps 16.00 GBps 32.00 GBps 64.00 GBps 128.0 GBps 256.0 GBps 512.0 GBps 1.000 TBps 2.000 TBps 4.000 TBps 8.000 TBps 16.00 TBps 32.00 TBps 64.00 TBps 128.0 TBps 256.0 TBps 512.0 TBps 1.000 PBps 2.000 PBps 4.000 PBps 8.000 PBps 16.00 PBps 32.00 PBps 64.00 PBps 128.0 PBps 256.0 PBps 512.0 PBps 1.000 EBps 2.000 EBps 4.000 EBps 8.000 EBps 16.00 EBps 32.00 EBps 64.00 EBps 128.0 EBps 256.0 EBps 512.0 EBps 1.000 ZBps 2.000 ZBps 4.000 ZBps 8.000 ZBps 16.00 ZBps 32.00 ZBps 64.00 ZBps 128.0 ZBps 256.0 ZBps 512.0 ZBps 1.000 YBps 2.000 YBps 4.000 YBps 8.000 YBps 16.00 YBps 32.00 YBps 64.00 YBps 128.0 YBps 256.0 YBps 512.0 YBps |
- 固定5桁のバイト/秒文字列は、小数点位置が固定してるため有効桁数が変化します。
- 可変5桁のバイト/秒文字列は、小数点位置が可変するため有効桁数は常に4桁を表示します。
- ネット・モニターのソフトなどでは、可変5桁のバイト/秒文字列を使います。
関連記事
- 5桁バイト単位文字列のサンプル
- 5桁バイト/秒文字列のサンプル
- 5桁ビット/秒文字列のサンプル
- 5桁Mバイト/秒文字列のサンプル
※コメント投稿者のブログIDはブログ作成者のみに通知されます