0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

【赤点回避!?】「n進数」を使って赤点を言い訳する!~vbs版~

Posted at

こんにちは。
以下の記事でやっていることをvbsでやったらどうなるかな?と思ったので、需要があるかわかりませんが時間があったので作ってみました。

sample.vbs
On Error Resume Next
'--------------------------------------------------------------
' 悪い点数を少しでも上げようとする悪あがき
'--------------------------------------------------------------
Dim moto ' 元の得点という意
moto = WScript.Arguments(0) ' 何とかしたい得点(10進数)

Int(moto)

' 数字以外の点数がきたらエラー
If Err.Number <> 0 Then
    msgbox "冷やかしはやめてください"
    wscript.quit
End If

' 100以上の点数がきたらエラー
If moto >= 100 Then
    msgbox "100未満の値を入力してください"
    wscript.quit
End If

' どうしようもない
If moto < 2 Then
    msgbox "手の施しようがありません。あきらめてください。"
    wscript.quit
End If

Dim changeVal
Dim radix
' 2進数から9進数まで順々に評価していく。
For radix = 2 To 9 

    changeVal = ChangeValue(moto, radix)
    
    ' 100点以内に収まったらループ終了。
    if changeVal <= 100 Then
        Exit For
    End If
Next

' 結果を表示。
msgbox ato

' 値を指定した基数に変換する。
Function ChangeValue(num, dRadix)

    Dim sho
    Dim Amari 
    Dim cnt
    Dim Ans()
    Dim vv
    vv = num
    cnt = 0

    ' 基数変換。
    Do While True
        Redim Preserve Ans(cnt)
        Ans(cnt) = vv mod dRadix ' 余り
        sho = vv \ dRadix ' 商
        cnt = cnt + 1

        if sho < dRadix Then 
            Redim Preserve Ans(cnt)
            Ans(cnt) = sho
            Exit Do
        End If
        vv = sho
    Loop

    Dim i
    Dim value
    value = 0
    ' 10進数で基数変換後の値を表現。
    For i = 0 To Ubound(ans) step 1
        value = value + ( ans(i) * 10^i)
    Next
    ChangeValue = value
End Function
0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?