CALL "D:\Programs\UWSC\FUNCTIONS.uws" // FUNCTIONS.uwsを置いている絶対パスを指定
CALL関数でFUNCTIONS.uwsにあるすべての関数を利用できます。
このホームページで使われているすべての自作関数です。これをFUNCTIONS.uwsとして一次元で保存・呼び出しすることで重複した関数を定義したりすることなく、プログラムの管理・修正が楽になります。
FUNCTION altClick(IE, alt, num = 1, fullMatchFlg = FALSE)
DIM cnt = 0
IMG_LST = IE.document.Images
IFB num = -1 THEN
FOR n = 0 TO IMG_LST.length - 1
SELECT fullMatchFlg
CASE TRUE
IF IMG_LST.Item(n).Alt = alt THEN cnt = cnt + 1
CASE FALSE
IF POS(alt, IMG_LST.Item(n).Alt) <> 0 THEN cnt = cnt + 1
SELEND
NEXT
RESULT = cnt
ELSE
DIM flg = FALSE
FOR n = 0 TO IMG_LST.length - 1
SELECT fullMatchFlg
CASE TRUE
IFB IMG_LST.Item(n).Alt = alt THEN
cnt = cnt + 1
IFB cnt = num THEN
IMG_LST.Item(n).Click()
flg = TRUE
BREAK
ENDIF
ENDIF
CASE FALSE
IFB POS(alt, IMG_LST.Item(n).Alt) <> 0 THEN
cnt = cnt + 1
IFB cnt = num THEN
IMG_LST.Item(n).Click()
flg = TRUE
BREAK
ENDIF
ENDIF
SELEND
NEXT
RESULT = flg
ENDIF
FEND
FUNCTION ARABIC(str)
DIM arr[][1] = "IV", "IIII", + _
"IX", "VIIII", + _
"XL", "XXXX", + _
"XC", "LXXXX", + _
"CD", "CCCC", + _
"CM", "DCCCC"
DIM Roman[] = "I", "V", "X", "L", "C", "D", "M"
DIM Arbic[] = 1, 5, 10, 50, 100, 500, 1000
FOR n = 0 TO UBound(arr)
num = REPLACE(str, arr[n][0], arr[n][1])
NEXT
DIM res = 0
FOR s = 1 TO LENGTH(num)
FOR ss = UBound(Arbic) TO 0 STEP -1
IFB COPY(str, s, 1) = Roman[ss] THEN
res = res + Arbic[ss]
ENDIF
NEXT
NEXT
IF res <= 0 OR res >= 4000 THEN res = -1
RESULT = res
FEND
PROCEDURE arrayFilter(var array[], callback)
DIM n = 0
DIM tmp[-1]
FOR %val% IN array
IFB EVAL(callback) THEN
RESIZE(tmp, n)
tmp[n] = %val%
n = n + 1
ENDIF
NEXT
RESIZE(array, RESIZE(tmp))
FOR n = 0 TO RESIZE(tmp)
array[n] = tmp[n]
NEXT
FEND
PROCEDURE arrayMap(callback, var array[])
DIM tmp[RESIZE(array)]
DIM n = 0
FOR %val% IN array
tmp[n] = EVAL(callback)
n = n + 1
NEXT
RESIZE(array, RESIZE(tmp))
FOR n = 0 TO RESIZE(tmp)
array[n] = tmp[n]
NEXT
FEND
FUNCTION arrayMerge(var arr[], tmp[])
FOR n = 0 TO UBound(tmp)
arrayPush(arr, tmp[n])
NEXT
RESULT = UBound(arr)
FEND
PROCEDURE arrayPad(Var array[], size, value)
DIM tmp[ABS(size) - (UBound(array) + 2)]
SETCLEAR(tmp, value)
IFB size > 0 THEN
arrayMerge(array, tmp)
ELSE
arrayMerge(tmp, array)
RESIZE(array, UBound(tmp))
SETCLEAR(array, EMPTY)
FOR i = 0 TO UBound(tmp)
array[i] = tmp[i]
NEXT
ENDIF
FEND
FUNCTION arrayPop(Var array[])
DIM n = UBound(array)
DIM res = array[n]
RESIZE(array, n-1)
RESULT = res
FEND
FUNCTION arrayPush(var arr[], str)
DIM res = RESIZE(arr, UBound(arr) + 1)
arr[res] = str
RESULT = res + 1
FEND
FUNCTION arrayShift(Var array[])
DIM res = array[0]
SHIFTARRAY(array, -1)
RESIZE(array, UBound(array) - 1)
RESULT = res
FEND
FUNCTION arraySplice(Var array[], offset, len = NULL)
DIM tmp[-1]
IF len = NULL THEN len = UBound(array)
IF len < 0 THEN len = len + UBound(array)
FOR i = offset - 1 TO len - 1
arrayPush(tmp, array[i])
NEXT
DIM tmp1[-1]
FOR i = 0 TO offset - 1
arrayPush(tmp1, array[i])
NEXT
DIM tmp2[-1]
FOR i = offset + len TO UBound(array)
arrayPush(tmp2, array[i])
NEXT
arrayMerge(tmp1, tmp2)
SETCLEAR(array)
RESIZE(array, UBound(tmp1))
FOR i = 0 TO UBound(tmp1)
array[i] = tmp1[i]
NEXT
RESULT = SLICE(tmp)
FEND
PROCEDURE arrayUnique(var arr[])
HASHTBL array
FOR n = 0 TO UBound(arr)
IF array[arr[n]] = TRUE THEN
arr[n] = EMPTY
ELSE
array[arr[n]] = TRUE
ENDIF
NEXT
FEND
PROCEDURE arrayValues(var arr[])
DIM tmp[-1]
FOR n = 0 TO UBound(arr)
IF arr[n] <> EMPTY THEN arrayPush(tmp, arr[n])
NEXT
RESIZE(arr, UBound(tmp))
FOR n = 0 TO UBound(tmp)
arr[n] = tmp[n]
NEXT
FEND
MODULE Base64
DIM obj, element
PROCEDURE Base64()
obj = CREATEOLEOBJ("Microsoft.XMLDOM")
element = obj.createElement("node")
element.dataType = "bin.base64"
FEND
FUNCTION encodestr(str)
element.nodeTypedValue = ENCODE(str, CODE_BYTEARRAY)
RESULT = element.text
FEND
FUNCTION decodestr(str)
element.text = str
RESULT = DECODE(element.nodeTypedValue, CODE_BYTEARRAY)
FEND
ENDMODULE
FUNCTION binToDec(bin)
dec = 0
FOR n = 1 TO LENGTH(bin)
dec = dec + COPY(bin, n, 1) * POWER(2, LENGTH(bin) - n)
NEXT
RESULT = dec
FEND
FUNCTION binToHex(bin)
HASHTBL bh
bh["0000"] = "0"; bh["0001"] = "1";
bh["0010"] = "2"; bh["0011"] = "3";
bh["0100"] = "4"; bh["0101"] = "5";
bh["0110"] = "6"; bh["0111"] = "7";
bh["1000"] = "8"; bh["1001"] = "9";
bh["1010"] = "a"; bh["1011"] = "b";
bh["1100"] = "c"; bh["1101"] = "d";
bh["1110"] = "e"; bh["1111"] = "f";
len = CEIL(LENGTH(bin) / 4) * 4
bin = REPLACE(FORMAT(bin, len), " ", "0")
hex = ""
FOR n = 1 TO LENGTH(bin) / 4
str = COPY(bin, n * 4 - 3, 4)
hex = hex + bh[str]
NEXT
RESULT = hex
FEND
PROCEDURE bogoSort(Var array[])
DIM num = UBound(array)
REPEAT
DIM flg = FALSE
FisherYates(array)
FOR n = 0 TO num - 1
IF array[n] > array[n+1] THEN
flg = TRUE
BREAK
ENDIF
NEXT
SLEEP(0.001)
UNTIL !flg
FEND
PROCEDURE bubbleSort(Var array[])
REPEAT
DIM flg = FALSE
FOR n = 0 TO UBound(array) - 1
IFB array[n] > array[n+1] THEN
swap(array[n], array[n+1])
flg = TRUE
ENDIF
NEXT
UNTIL !flg
FEND
PROCEDURE BusyWait(Var IE)
SLEEP(0.500)
DIM t = GETTIME()
TRY
REPEAT
DIM tm = GETTIME() - t
FUKIDASI("BusyWait:" + tm)
SLEEP(0.010)
IF tm >= 60 THEN BREAK
UNTIL !IE.Busy AND IE.readyState = 4
EXCEPT
IE = getIEObj(-1)
PRINT IE.document.URL + " のIEオブジェクトを取得しました。"
BusyWait(IE)
ENDTRY
FUKIDASI()
FEND
FUNCTION chuki(JD)
JD = JD - 9/24
DIM t = (JD + 0.5 - 2451545) / 36525
DIM λsun = longitudeSun(t)
DIM λsun0 = 30 * INT(λsun/30)
REPEAT
t = (JD + 0.5 - 2451545) / 36525
λsun = longitudeSun(t)
DIM Δλ = λsun - λsun0
SELECT TRUE
CASE Δλ > 180
Δλ = Δλ - 360
CASE Δλ < -180
Δλ = Δλ + 180
SELEND
DIM Δt = Δλ * 365.2 / 360
JD = JD - Δt
UNTIL Δt <= 1/86400
JD = JD + 9/24
DIM arr[1] = JD, λsun
RESULT = SLICE(arr)
FEND
MODULE Cipher
FUNCTION Caesar.encode(str, num = 3)
DIM res = ""
FOR n = 1 TO LENGTH(str)
DIM s = COPY(str, n, 1)
DIM ofs = ""
DIM normalizedNumber = IIF(num >= 0, num MOD 26, INT(ABS(num / 26) + 1) * 26 + num)
SELECT TRUE
CASE ASC(s) >= ASC("A") AND ASC(s) <= ASC("Z")
ofs = (ASC(s) - ASC("A") + normalizedNumber) MOD 26
res = res + CHR(ofs + ASC("A"))
CASE ASC(s) >= ASC("a") AND ASC(s) <= ASC("z")
ofs = (ASC(s) - ASC("a") + normalizedNumber) MOD 26
res = res + CHR(ofs + ASC("a"))
DEFAULT
res = res + s
SELEND
NEXT
RESULT = res
FEND
FUNCTION Caesar.decode(str, num = 3)
DIM res = ""
FOR n = 1 TO LENGTH(str)
DIM s = COPY(str, n, 1)
DIM ofs = ""
DIM normalizedNumber = IIF(num >= 0, num MOD 26, INT(ABS(num / 26) + 1) * 26 + num)
SELECT TRUE
CASE ASC(s) >= ASC("A") AND ASC(s) <= ASC("Z")
ofs = (ASC(s) - ASC("A") - normalizedNumber + 26) MOD 26
res = res + CHR(ofs + ASC("A"))
CASE ASC(s) >= ASC("a") AND ASC(s) <= ASC("z")
ofs = (ASC(s) - ASC("a") - normalizedNumber + 26) MOD 26
res = res + CHR(ofs + ASC("a"))
DEFAULT
res = res + s
SELEND
NEXT
RESULT = res
FEND
FUNCTION ROT13.encode(str)
RESULT = Cipher.Caesar.encode(str, 13)
FEND
FUNCTION ROT13.decode(str)
RESULT = Cipher.ROT13.encode(str)
FEND
FUNCTION Vigenere.encode(str, key)
str = STRCONV(str, SC_LOWERCASE)
key = STRCONV(key, SC_LOWERCASE)
DIM res = ""
DIM ofs = ""
FOR n = 1 TO LENGTH(str)
DIM s = COPY(str, n, 1)
SELECT TRUE
CASE ASC(s) >= ASC("a") AND ASC(s) <= ASC("z")
DIM num = (n - 1) MOD LENGTH(key) + 1
ofs = ((ASC(s) - ASC("a")) + (ASC(COPY(key, num, 1)) - ASC("a")) + 26) MOD 26
res = res + CHR(ofs + ASC("a"))
DEFAULT
res = res + s
SELEND
NEXT
RESULT = res
FEND
FUNCTION Vigenere.decode(str, key)
str = STRCONV(str, SC_LOWERCASE)
key = STRCONV(key, SC_LOWERCASE)
DIM res = ""
DIM ofs = ""
FOR n = 1 TO LENGTH(str)
DIM s = COPY(str, n, 1)
SELECT TRUE
CASE ASC(s) >= ASC("a") AND ASC(s) <= ASC("z")
DIM num = (n - 1) MOD LENGTH(key) + 1
ofs = ((ASC(s) - ASC("a")) - (ASC(COPY(key, num, 1)) - ASC("a")) + 26) MOD 26
res = res + CHR(ofs + ASC("a"))
DEFAULT
res = res + s
SELEND
NEXT
RESULT = res
FEND
FUNCTION XOR.encode(str, key)
DIM res = ""
FOR n = 1 TO LENGTH(str)
DIM num = (n - 1) MOD LENGTH(key) + 1
DIM a = ASC(COPY(str, n, 1))
DIM b = ASC(COPY(key, num, 1))
res = res + "" + REPLACE(FORMAT(VARTYPE(decToBin(a XOR b), VAR_INTEGER), 8), " ", "0")
NEXT
RESULT = res
FEND
FUNCTION XOR.decode(str, key)
DIM res = ""
FOR n = 1 TO LENGTH(str) / 8
DIM num = (n - 1) MOD LENGTH(key) + 1
DIM a = binToDec(COPY(str, n * 8 - 7, 8))
DIM b = ASC(COPY(key, num, 1))
res = res + CHR(a XOR b)
NEXT
RESULT = res
FEND
ENDMODULE
FUNCTION Collatz(num)
IFB !reTest(num, "\d+") THEN
RESULT = ERR_VALUE
EXIT
ENDIF
DIM array[-1]
arrayPush(array, num)
WHILE num <> 1
num = IIF(num MOD 2 = 0, num / 2, num * 3 + 1)
arrayPush(array, num)
WEND
RESULT = SLICE(array)
FEND
PROCEDURE combSort(Var array[])
DIM num = UBound(array)
DIM h = num
DIM flg = FALSE
WHILE h > 1 OR flg
IF h > 1 THEN h = INT(h / 1.3)
flg = FALSE
FOR n = 0 TO num - h
IFB array[n] > array[n+h] THEN
swap(array[n], array[n+h])
flg = TRUE
ENDIF
NEXT
WEND
FEND
FUNCTION convert(num, before, after)
HASHTBL unit
// 重量
unit["g,sg"] = "num * 6.85217658567918 * POWER(10, -5)"
unit["g,lbm"] = "num * 2.20462262184878 * POWER(10, -3)"
unit["g,u"] = "num * 6.02217 * POWER(10, +23)"
unit["g,ozm"] = "num * 3.52739619495804 * POWER(10, -2)"
unit["sg,g"] = "num * 1.45939029372064 * POWER(10, +4)"
unit["sg,lbm"] = "num * 3.21740485564304 * POWER(10, +1)"
unit["sg,u"] = "num * 8.78869644513561 * POWER(10, +27)"
unit["sg,ozm"] = "num * 5.14784776902887 * POWER(10, +2)"
unit["lbm,g"] = "num * 4.5359237 * POWER(10, +2)"
unit["lbm,sg"] = "num * 3.10809501715673 * POWER(10, -2)"
unit["lbm,u"] = "num * 2.7316103628429 * POWER(10, +26)"
unit["lbm,ozm"] = "num * 1.6 * POWER(10, +1)"
unit["u,g"] = "num * 1.66053100460465 * POWER(10, -24)"
unit["u,sg"] = "num * 1.13782516695463 * POWER(10, -28)"
unit["u,lbm"] = "num * 3.66084421703269 * POWER(10, -27)"
unit["u,ozm"] = "num * 5.8573507472523 * POWER(10, -26)"
unit["ozm,g"] = "num * 2.8349523125 * POWER(10, +1)"
unit["ozm,sg"] = "num * 1.94255938572295 * POWER(10, -3)"
unit["ozm,lbm"] = "num * 6.25 * POWER(10, -2)"
unit["ozm,u"] = "num * 1.70725647677681 * POWER(10, +25)"
// 距離
unit["m,mi"] = "num * 6.21371192237334 * POWER(10, -4)"
unit["m,Nmi"] = "num * 5.39956803455724 * POWER(10, -4)"
unit["m,in"] = "num * 3.93700787401575 * POWER(10, +1)"
unit["m,ft"] = "num * 3.28083989501312 * POWER(10, +0)"
unit["m,yd"] = "num * 1.09361329833771 * POWER(10, +0)"
unit["m,ang"] = "num * 1 * POWER(10, +10)"
unit["m,pica"] = "num * 2.36220472440945 * POWER(10, +2)"
unit["mi,m"] = "num * 1.609344 * POWER(10, +3)"
unit["mi,Nmi"] = "num * 8.68976241900648 * POWER(10, -1)"
unit["mi,in"] = "num * 6.336 * POWER(10, +4)"
unit["mi,ft"] = "num * 5.28 * POWER(10, +3)"
unit["mi,yd"] = "num * 1.76 * POWER(10, +3)"
unit["mi,ang"] = "num * 1.609344 * POWER(10, +13)"
unit["mi,pica"] = "num * 3.8016 * POWER(10, +5)"
unit["Nmi,m"] = "num * 1.852 * POWER(10, +3)"
unit["Nmi,mi"] = "num * 1.15077944802354 * POWER(10, +0)"
unit["Nmi,in"] = "num * 7.29133858267717 * POWER(10, +4)"
unit["Nmi,ft"] = "num * 6.0761154855643 * POWER(10, +3)"
unit["Nmi,yd"] = "num * 2.02537182852143 * POWER(10, +3)"
unit["Nmi,ang"] = "num * 1.852 * POWER(10, +13)"
unit["Nmi,pica"] = "num * 4.3748031496063 * POWER(10, +5)"
unit["in,m"] = "num * 2.54 * POWER(10, -2)"
unit["in,mi"] = "num * 1.57828282828283 * POWER(10, -5)"
unit["in,Nmi"] = "num * 1.37149028077754 * POWER(10, -5)"
unit["in,ft"] = "num * 8.33333333333333 * POWER(10, -2)"
unit["in,yd"] = "num * 2.77777777777778 * POWER(10, -2)"
unit["in,ang"] = "num * 2.54 * POWER(10, +8)"
unit["in,pica"] = "num * 6 * POWER(10, +0)"
unit["ft,m"] = "num * 3.048 * POWER(10, -1)"
unit["ft,mi"] = "num * 1.89393939393939 * POWER(10, -4)"
unit["ft,Nmi"] = "num * 1.64578833693305 * POWER(10, -4)"
unit["ft,in"] = "num * 1.2 * POWER(10, +1)"
unit["ft,yd"] = "num * 3.33333333333333 * POWER(10, -1)"
unit["ft,ang"] = "num * 3.048 * POWER(10, +9)"
unit["ft,pica"] = "num * 7.2 * POWER(10, +1)"
unit["yd,m"] = "num * 9.144 * POWER(10, -1)"
unit["yd,mi"] = "num * 5.68181818181818 * POWER(10, -4)"
unit["yd,Nmi"] = "num * 4.93736501079914 * POWER(10, -4)"
unit["yd,in"] = "num * 3.6 * POWER(10, +1)"
unit["yd,ft"] = "num * 3 * POWER(10, +0)"
unit["yd,ang"] = "num * 9.144 * POWER(10, +9)"
unit["yd,pica"] = "num * 2.16 * POWER(10, +2)"
unit["ang,m"] = "num * 1 * POWER(10, -10)"
unit["ang,mi"] = "num * 6.21371192237334 * POWER(10, -14)"
unit["ang,Nmi"] = "num * 5.39956803455724 * POWER(10, -14)"
unit["ang,in"] = "num * 3.93700787401575 * POWER(10, -9)"
unit["ang,ft"] = "num * 3.28083989501312 * POWER(10, -10)"
unit["ang,yd"] = "num * 1.09361329833771 * POWER(10, -10)"
unit["ang,pica"] = "num * 2.36220472440945 * POWER(10, -8)"
unit["pica,m"] = "num * 4.23333333333333 * POWER(10, -3)"
unit["pica,mi"] = "num * 2.63047138047138 * POWER(10, -6)"
unit["pica,Nmi"] = "num * 2.28581713462923 * POWER(10, -6)"
unit["pica,in"] = "num * 1.66666666666667 * POWER(10, -1)"
unit["pica,ft"] = "num * 1.38888888888889 * POWER(10, -2)"
unit["pica,yd"] = "num * 4.62962962962963 * POWER(10, -3)"
unit["pica,ang"] = "num * 4.23333333333333 * POWER(10, +7)"
// 時間
unit["yr,day"] = "num * 3.6525 * POWER(10, +2)"
unit["yr,hr"] = "num * 8.766 * POWER(10, +3)"
unit["yr,mn"] = "num * 5.2596 * POWER(10, +5)"
unit["yr,sec"] = "num * 3.15576 * POWER(10, +7)"
unit["day,yr"] = "num * 2.7378507871321 * POWER(10, -3)"
unit["day,hr"] = "num * 2.4 * POWER(10, +1)"
unit["day,mn"] = "num * 1.44 * POWER(10, +3)"
unit["day,sec"] = "num * 8.64 * POWER(10, +4)"
unit["hr,yr"] = "num * 1.14077116130504 * POWER(10, -4)"
unit["hr,day"] = "num * 4.16666666666667 * POWER(10, -2)"
unit["hr,mn"] = "num * 6 * POWER(10, +1)"
unit["hr,sec"] = "num * 3.6 * POWER(10, +3)"
unit["mn,yr"] = "num * 1.90128526884174 * POWER(10, -6)"
unit["mn,day"] = "num * 6.94444444444444 * POWER(10, -4)"
unit["mn,hr"] = "num * 1.66666666666667 * POWER(10, -2)"
unit["mn,sec"] = "num * 6 * POWER(10, +1)"
unit["sec,yr"] = "num * 3.16880878140289 * POWER(10, -8)"
unit["sec,day"] = "num * 1.15740740740741 * POWER(10, -5)"
unit["sec,hr"] = "num * 2.77777777777778 * POWER(10, -4)"
unit["sec,mn"] = "num * 1.66666666666667 * POWER(10, -2)"
// 圧力
unit["Pa,atm"] = "num * 9.86923266716013 * POWER(10, -6)"
unit["Pa,mmHg"] = "num * 7.5006168270417 * POWER(10, -3)"
unit["atm,Pa"] = "num * 1.01325 * POWER(10, +5)"
unit["atm,mmHg"] = "num * 7.6 * POWER(10, +2)"
unit["mmHg,Pa"] = "num * 1.33322368421053 * POWER(10, +2)"
unit["mmHg,atm"] = "num * 1.31578947368421 * POWER(10, -3)"
// 物理的な力
unit["N,dyn"] = "num * 1 * POWER(10, +5)"
unit["N,lbf"] = "num * 2.2480894309971 * POWER(10, -1)"
unit["dyn,N"] = "num * 1 * POWER(10, -5)"
unit["dyn,lbf"] = "num * 2.2480894309971 * POWER(10, -6)"
unit["lbf,N"] = "num * 4.4482216152605 * POWER(10, +0)"
unit["lbf,dyn"] = "num * 4.4482216152605 * POWER(10, +5)"
// エネルギー
unit["J,e"] = "num * 1 * POWER(10, +7)"
unit["J,cal"] = "num * 2.38845896627496 * POWER(10, -1)"
unit["J,eV"] = "num * 6.241457 * POWER(10, +18)"
unit["J,HPh"] = "num * 3.72506135998619 * POWER(10, -7)"
unit["J,Wh"] = "num * 2.77777777777778 * POWER(10, -4)"
unit["J,flb"] = "num * 7.37562149277265 * POWER(10, -1)"
unit["J,BTU"] = "num * 9.47817120313317 * POWER(10, -4)"
unit["J,c"] = "num * 2.39005736137667 * POWER(10, -1)"
unit["e,J"] = "num * 1 * POWER(10, -7)"
unit["e,cal"] = "num * 2.38845896627496 * POWER(10, -8)"
unit["e,eV"] = "num * 6.241457 * POWER(10, +11)"
unit["e,HPh"] = "num * 3.72506135998619 * POWER(10, -14)"
unit["e,Wh"] = "num * 2.77777777777778 * POWER(10, -11)"
unit["e,flb"] = "num * 7.37562149277265 * POWER(10, -8)"
unit["e,BTU"] = "num * 9.47817120313317 * POWER(10, -11)"
unit["e,c"] = "num * 2.39005736137667 * POWER(10, -8)"
unit["cal,J"] = "num * 4.1868 * POWER(10, +0)"
unit["cal,e"] = "num * 4.1868 * POWER(10, +7)"
unit["cal,eV"] = "num * 2.61317321676 * POWER(10, +19)"
unit["cal,HPh"] = "num * 1.55960869019902 * POWER(10, -6)"
unit["cal,Wh"] = "num * 1.163 * POWER(10, -3)"
unit["cal,flb"] = "num * 3.08802520659405 * POWER(10, +0)"
unit["cal,BTU"] = "num * 3.9683207193278 * POWER(10, -3)"
unit["cal,c"] = "num * 1.00066921606119 * POWER(10, +0)"
unit["eV,J"] = "num * 1.60219000146921 * POWER(10, -19)"
unit["eV,e"] = "num * 1.60219000146921 * POWER(10, -12)"
unit["eV,cal"] = "num * 3.82676507468522 * POWER(10, -20)"
unit["eV,HPh"] = "num * 5.96825606582916 * POWER(10, -26)"
unit["eV,Wh"] = "num * 4.45052778185891 * POWER(10, -23)"
unit["eV,flb"] = "num * 1.18171470103417 * POWER(10, -19)"
unit["eV,BTU"] = "num * 1.51858311338733 * POWER(10, -22)"
unit["eV,c"] = "num * 3.82932600733558 * POWER(10, -20)"
unit["HPh,J"] = "num * 2.68451953769617 * POWER(10, +6)"
unit["HPh,e"] = "num * 2.68451953769617 * POWER(10, +13)"
unit["HPh,cal"] = "num * 6.41186475995073 * POWER(10, +5)"
unit["HPh,eV"] = "num * 1.67553132601905 * POWER(10, +25)"
unit["HPh,Wh"] = "num * 7.4569987158227 * POWER(10, +2)"
unit["HPh,flb"] = "num * 1.98 * POWER(10, +6)"
unit["HPh,BTU"] = "num * 2.54443357764402 * POWER(10, +3)"
unit["HPh,c"] = "num * 6.41615568283024 * POWER(10, +5)"
unit["Wh,J"] = "num * 3.6 * POWER(10, +3)"
unit["Wh,e"] = "num * 3.6 * POWER(10, +10)"
unit["Wh,cal"] = "num * 8.59845227858985 * POWER(10, +2)"
unit["Wh,eV"] = "num * 2.24692452 * POWER(10, +22)"
unit["Wh,HPh"] = "num * 1.34102208959503 * POWER(10, -3)"
unit["Wh,flb"] = "num * 2.65522373739816 * POWER(10, +3)"
unit["Wh,BTU"] = "num * 3.41214163312794 * POWER(10, +0)"
unit["Wh,c"] = "num * 8.60420650095602 * POWER(10, +2)"
unit["flb,J"] = "num * 1.3558179483314 * POWER(10, +0)"
unit["flb,e"] = "num * 1.3558179483314 * POWER(10, +7)"
unit["flb,cal"] = "num * 3.23831553532865 * POWER(10, -1)"
unit["flb,eV"] = "num * 8.46227942433866 * POWER(10, +18)"
unit["flb,HPh"] = "num * 5.05050505050505 * POWER(10, -7)"
unit["flb,Wh"] = "num * 3.76616096758722 * POWER(10, -4)"
unit["flb,BTU"] = "num * 1.28506746345658 * POWER(10, -3)"
unit["flb,c"] = "num * 3.24048266809608 * POWER(10, -1)"
unit["BTU,J"] = "num * 1.05505585262 * POWER(10, +3)"
unit["BTU,e"] = "num * 1.05505585262 * POWER(10, +10)"
unit["BTU,cal"] = "num * 2.51995761111111 * POWER(10, +2)"
unit["BTU,eV"] = "num * 6.58508573672607 * POWER(10, +21)"
unit["BTU,HPh"] = "num * 3.93014778922204 * POWER(10, -4)"
unit["BTU,Wh"] = "num * 2.93071070172222 * POWER(10, -1)"
unit["BTU,flb"] = "num * 7.78169262265965 * POWER(10, +2)"
unit["BTU,c"] = "num * 2.52164400721797 * POWER(10, +2)"
unit["c,J"] = "num * 4.184 * POWER(10, +0)"
unit["c,e"] = "num * 4.184 * POWER(10, +7)"
unit["c,cal"] = "num * 9.99331231489443 * POWER(10, -1)"
unit["c,eV"] = "num * 2.6114256088 * POWER(10, +19)"
unit["c,HPh"] = "num * 1.55856567301822 * POWER(10, -6)"
unit["c,Wh"] = "num * 1.16222222222222 * POWER(10, -3)"
unit["c,flb"] = "num * 3.08596003257608 * POWER(10, +0)"
unit["c,BTU"] = "num * 3.96566683139092 * POWER(10, -3)"
// 仕事率
unit["HP,W"] = "num * 7.4569987158227 * POWER(10, +2)"
unit["W,HP"] = "num * 1.34102208959503 * POWER(10, -3)"
// 磁力
unit["T,ga"] = "num * 1 * POWER(10, +4)"
unit["ga,T"] = "num * 1 * POWER(10, -4)"
// 温度
unit["C,F"] = "num * (9/5) + 32"
unit["C,K"] = "num + 273.15"
unit["F,C"] = "(num - 32) * (9/5)"
unit["F,K"] = "(num - 32) * (5/9) + 273.15"
unit["K,C"] = "num - 23373.15"
unit["K,F"] = "(num - 273.15) * (9/5) + 32"
// 体積(容積)
unit["tsp,tbs"] = "num * 3.33333333333333 * POWER(10, -1)"
unit["tsp,oz"] = "num * 1.66666666666667 * POWER(10, -1)"
unit["tsp,cup"] = "num * 2.08333333333333 * POWER(10, -2)"
unit["tsp,us_pt"] = "num * 1.04166666666667 * POWER(10, -2)"
unit["tsp,uk_pt"] = "num * 8.67368942321863 * POWER(10, -3)"
unit["tsp,qt"] = "num * 5.20833333333333 * POWER(10, -3)"
unit["tsp,gal"] = "num * 1.30208333333333 * POWER(10, -3)"
unit["tbs,tsp"] = "num * 3 * POWER(10, +0)"
unit["tbs,oz"] = "num * 5 * POWER(10, -1)"
unit["tbs,cup"] = "num * 6.25 * POWER(10, -2)"
unit["tbs,us_pt"] = "num * 3.125 * POWER(10, -2)"
unit["tbs,uk_pt"] = "num * 2.60210682696559 * POWER(10, -2)"
unit["tbs,qt"] = "num * 1.5625 * POWER(10, -2)"
unit["tbs,gal"] = "num * 3.90625 * POWER(10, -3)"
unit["oz,tsp"] = "num * 6 * POWER(10, +0)"
unit["oz,tbs"] = "num * 2 * POWER(10, +0)"
unit["oz,cup"] = "num * 1.25 * POWER(10, -1)"
unit["oz,us_pt"] = "num * 6.25 * POWER(10, -2)"
unit["oz,uk_pt"] = "num * 5.20421365393118 * POWER(10, -2)"
unit["oz,qt"] = "num * 3.125 * POWER(10, -2)"
unit["oz,gal"] = "num * 7.8125 * POWER(10, -3)"
unit["cup,tsp"] = "num * 4.8 * POWER(10, +1)"
unit["cup,tbs"] = "num * 1.6 * POWER(10, +1)"
unit["cup,oz"] = "num * 8 * POWER(10, +0)"
unit["cup,us_pt"] = "num * 5 * POWER(10, -1)"
unit["cup,uk_pt"] = "num * 4.16337092314494 * POWER(10, -1)"
unit["cup,qt"] = "num * 2.5 * POWER(10, -1)"
unit["cup,gal"] = "num * 6.25 * POWER(10, -2)"
unit["us_pt,tsp"] = "num * 9.6 * POWER(10, +1)"
unit["us_pt,tbs"] = "num * 3.2 * POWER(10, +1)"
unit["us_pt,oz"] = "num * 1.6 * POWER(10, +1)"
unit["us_pt,cup"] = "num * 2 * POWER(10, +0)"
unit["us_pt,uk_pt"] = "num * 8.32674184628989 * POWER(10, -1)"
unit["us_pt,qt"] = "num * 5 * POWER(10, -1)"
unit["us_pt,gal"] = "num * 1.25 * POWER(10, -1)"
unit["uk_pt,tsp"] = "num * 1.15291192848466 * POWER(10, +2)"
unit["uk_pt,tbs"] = "num * 3.84303976161554 * POWER(10, +1)"
unit["uk_pt,oz"] = "num * 1.92151988080777 * POWER(10, +1)"
unit["uk_pt,cup"] = "num * 2.40189985100971 * POWER(10, +0)"
unit["uk_pt,us_pt"] = "num * 1.20094992550486 * POWER(10, +0)"
unit["uk_pt,qt"] = "num * 6.00474962752428 * POWER(10, -1)"
unit["uk_pt,gal"] = "num * 1.50118740688107 * POWER(10, -1)"
unit["qt,tsp"] = "num * 1.92 * POWER(10, +2)"
unit["qt,tbs"] = "num * 6.4 * POWER(10, +1)"
unit["qt,oz"] = "num * 3.2 * POWER(10, +1)"
unit["qt,cup"] = "num * 4 * POWER(10, +0)"
unit["qt,us_pt"] = "num * 2 * POWER(10, +0)"
unit["qt,uk_pt"] = "num * 1.66534836925798 * POWER(10, +0)"
unit["qt,gal"] = "num * 2.5 * POWER(10, -1)"
unit["gal,tsp"] = "num * 7.68 * POWER(10, +2)"
unit["gal,tbs"] = "num * 2.56 * POWER(10, +2)"
unit["gal,oz"] = "num * 1.28 * POWER(10, +2)"
unit["gal,cup"] = "num * 1.6 * POWER(10, +1)"
unit["gal,us_pt"] = "num * 8 * POWER(10, +0)"
unit["gal,uk_pt"] = "num * 6.66139347703191 * POWER(10, +0)"
unit["gal,qt"] = "num * 4 * POWER(10, +0)"
RESULT = EVAL(unit[before + "," + after])
FEND
FUNCTION dateAdd(interval, num, date)
DIM year, month, day, d
GETTIME(0, date)
SELECT interval
CASE "yyyy"
d = (G_TIME_YY + num) + "/" + G_TIME_MM2 + "/" + G_TIME_DD2
CASE "m"
IFB num > 0 THEN
year = G_TIME_YY + INT((G_TIME_MM + num) / 12)
month = REPLACE(FORMAT(((G_TIME_MM + num) MOD 12), 2), " ", "0")
ELSE
year = G_TIME_YY + CEIL((G_TIME_MM + num) / 12 - 1)
month = REPLACE(FORMAT(G_TIME_MM - (ABS(num) MOD 12), 2), " ", "0")
ENDIF
IF month = "00" THEN month = 12
day = G_TIME_DD2
d = "" + year + month + day
IFB !isDate(d) THEN
d = year + "/" + month + "/" + "01"
d = getEndOfMonth(d)
ELSE
d = year + "/" + month + "/" + day
ENDIF
CASE "d"
GETTIME(num, date)
d = G_TIME_YY4 + "/" + G_TIME_MM2 + "/" + G_TIME_DD2
CASE "ww"
GETTIME(num * 7, date)
d = G_TIME_YY4 + "/" + G_TIME_MM2 + "/" + G_TIME_DD2
CASE "h"
GETTIME(num / 24, date)
d = G_TIME_YY4 + "/" + G_TIME_MM2 + "/" + G_TIME_DD2 + " " + G_TIME_HH2 + ":" + G_TIME_NN2 + ":" + G_TIME_SS2
CASE "n"
GETTIME(num / 1440, date)
d = G_TIME_YY4 + "/" + G_TIME_MM2 + "/" + G_TIME_DD2 + " " + G_TIME_HH2 + ":" + G_TIME_NN2 + ":" + G_TIME_SS2
CASE "s"
GETTIME(num / 86400, date)
d = G_TIME_YY4 + "/" + G_TIME_MM2 + "/" + G_TIME_DD2 + " " + G_TIME_HH2 + ":" + G_TIME_NN2 + ":" + G_TIME_SS2
SELEND
RESULT = d
FEND
FUNCTION dateDiff(interval, date1, date2)
DIM y1, y2, m1, m2, d1, d2, d
SELECT interval
CASE "yyyy"
GETTIME(0, date1)
y1 = G_TIME_YY
GETTIME(0, date2)
y2 = G_TIME_YY
d = y2 - y1
CASE "m"
GETTIME(0, date1)
y1 = G_TIME_YY
m1 = G_TIME_MM
GETTIME(0, date2)
y2 = G_TIME_YY
m2 = G_TIME_MM
d = (y2 - y1) * 12 + m2 - m1
CASE "d"
d1 = GETTIME(0, date1)
d2 = GETTIME(0, date2)
d = (d2 - d1) / 86400
SELEND
RESULT = d
FEND
FUNCTION dateString(date)
GETTIME(0, date)
DIM y = G_TIME_YY
DIM m = G_TIME_MM
DIM d = G_TIME_DD
DIM dt = ""
SELECT TRUE
CASE GETTIME(0, date) >= GETTIME(0, "2019/05/01")
dt = "令和" + IIF(y - 2018 = 1, "元", y - 2018) + "年"
CASE GETTIME(0, date) >= GETTIME(0, "1989/01/18")
dt = "平成" + IIF(y - 1988 = 1, "元", y -1988) + "年"
CASE GETTIME(0, date) >= GETTIME(0, "1926/12/25")
dt = "昭和" + IIF(y - 1925 = 1, "元", y -1925) + "年"
CASE GETTIME(0, date) >= GETTIME(0, "1912/07/30")
dt = "大正" + IIF(y - 1911 = 1, "元", y - 1911) + "年"
CASE GETTIME(0, date) >= GETTIME(0, "1868/01/25")
dt = "明治" + IIF(y - 1867 = 1, "元", y - 1867) + "年"
SELEND
RESULT = dt + m + "月" + d + "日"
FEND
FUNCTION dateValue(str)
HASHTBL Pattern
Pattern["year"] = "(190[0-9]|19[1-9][0-9]|[2-9][0-9]{3})"
Pattern["month"] = "(1[0-2]|0?[1-9])"
Pattern["day"] = "([1-2][0-9]|3[0-1]|0?[1-9])"
SELECT TRUE
CASE reTest(str, Pattern["year"] + "/" + Pattern["month"] + "/" + Pattern["day"])
Matches = reExecute(str, Pattern["year"] + "/" + Pattern["month"] + "/" + Pattern["day"])
WITH Matches.Item(0)
date = .SubMatches(0) + "/" + text(VAL(.SubMatches(1)), "00") + "/" + text(VAL(.SubMatches(2)), "00")
ENDWITH
CASE reTest(str, Pattern["year"] + "年" + Pattern["month"] + "月" + Pattern["day"] + "日")
Matches = reExecute(str, Pattern["year"] + "年" + Pattern["month"] + "月" + Pattern["day"] + "日")
WITH Matches.Item(0)
date = .SubMatches(0) + "/" + text(VAL(.SubMatches(1)), "00") + "/" + text(VAL(.SubMatches(2)), "00")
ENDWITH
CASE reTest(str, Pattern["month"] + "/" + Pattern["day"])
Matches = reExecute(str, Pattern["month"] + "/" + Pattern["day"])
GETTIME()
WITH Matches.Item(0)
date = G_TIME_YY4 + "/" + text(VAL(.SubMatches(0)), "00") + "/" + text(VAL(.SubMatches(1)), "00")
ENDWITH
CASE reTest(str, Pattern["month"] + "月" + Pattern["day"] + "日")
Matches = reExecute(str, Pattern["month"] + "月" + Pattern["day"] + "日")
GETTIME()
WITH Matches.Item(0)
date = G_TIME_YY4 + "/" + text(VAL(.SubMatches(0)), "00") + "/" + text(VAL(.SubMatches(1)), "00")
ENDWITH
CASE reTest(str, "^(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)-" + Pattern["day"] + "$")
Matches = reExecute(str, "^(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)-" + Pattern["day"] + "$")
SELECT Matches.Item(0).SubMatches(0)
CASE "Jan"; m = "01"
CASE "Feb"; m = "02"
CASE "Mar"; m = "03"
CASE "Apr"; m = "04"
CASE "May"; m = "05"
CASE "Jun"; m = "06"
CASE "Jul"; m = "07"
CASE "Aug"; m = "08"
CASE "Sep"; m = "09"
CASE "Oct"; m = "10"
CASE "Nov"; m = "11"
CASE "Dec"; m = "12"
SELEND
GETTIME()
date = G_TIME_YY4 + m + Matches.Item(0).SubMatches(1)
SELEND
RESULT = uwscToSerial(GETTIME(0, date))
FEND
FUNCTION decToBin(dec)
bin = ""
REPEAT
bin = (dec MOD 2) + bin
dec = INT(dec/2)
UNTIL dec = 0
RESULT = bin
FEND
FUNCTION decToHex(dec)
RESULT = FORMAT(VAL(dec), 0, -1)
FEND
FUNCTION degToRad(deg)
DIM pi = 3.14159265358979
RESULT = deg * pi / 180
FEND
FUNCTION digitSum(num)
DIM res = 0
IFB VARTYPE(ABS(num, VAR_DWORD)) = num THEN // 正の整数ならば
FOR n = 1 TO LENGTH(num)
res = res + VAL(COPY(num, n, 1))
NEXT
ELSE
res = ERR_VALUE
ENDIF
RESULT = res
FEND
FUNCTION divisors(num)
DIM arr[-1]
FOR n = 1 TO num / 2
IF num MOD n = 0 THEN arrayPush(arr, n)
NEXT
arrayPush(arr, num)
RESULT = SLICE(arr)
FEND
FUNCTION DownloadFile(URL, folderspec = "", filename = "")
DIM Shell = CREATEOLEOBJ("Shell.Application")
DIM FSO = CREATEOLEOBJ("Scripting.FileSystemObject")
// フォルダ名
IFB folderspec = "" THEN
// 指定がなければダウンロードフォルダ
folderspec = Shell.NameSpace("shell:Downloads").Self.Path
ELSE
// 指定したフォルダが存在しなければ
IFB !FSO.FolderExists(folderspec) THEN
PRINT "「" + folderspec + "」は存在しないフォルダです。"
folderspec = Shell.NameSpace("shell:Downloads").Self.Path
ENDIF
ENDIF
// ファイル名
IFB filename = "" THEN
// 指定がなければURLのファイル名をそのまま使う
DIM Matches = reExecute(URL, ".+/(.+?)([\?#;].*)?$")
filename = Matches.Item(0).SubMatches(0)
ENDIF
// フォルダ名とフォイル名を繋げてパスを生成
DIM path = FSO.BuildPath(folderspec, filename)
// 重複しないパスを生成
path = uniqueFilename(path)
// ダウンロードするコマンド
DIM cmd = "bitsadmin.exe /TRANSFER htmlget <#DBL>" + URL + "<#DBL> <#DBL>" + path + "<#DBL>"
// コマンドを実行
DIM res = TRIM(DOSCMD(cmd))
PRINT res
DIM flg = FALSE
// 成功時 : Transfer complete.
// 失敗時 : Unable to complete transfer.
IF POS("Transfer complete.", res) THEN flg = TRUE
RESULT = flg
FEND
FUNCTION Endian(str)
DIM len = LENGTH(str)
IFB !isEven(len) THEN
str = "0" + str
len = len + 1
ENDIF
DIM res = ""
FOR n = 1 TO len STEP 2
res = COPY(str, n, 2) + res
NEXT
RESULT = res
FEND
FUNCTION ExcelBoot(path = "")
DIM Excel = CREATEOLEOBJ("Excel.Application")
Excel.Visible = TRUE
IFB path = "" THEN
Excel.Workbooks.Add
ELSE
DIM FSO = CREATEOLEOBJ("Scripting.FileSystemObject")
IFB FSO.GetParentFolderName(path) = "" THEN
path = GET_CUR_DIR + "\" + path
ENDIF
Excel.Workbooks.Open(path)
ENDIF
RESULT = Excel
FEND
MODULE ExcelFunction
CONST Excel = CREATEOLEOBJ("Excel.Application")
FUNCTION ASC(str)
RESULT = Excel.Evaluate("ASC(" + str + ")")
FEND
FUNCTION BAHTTEXT(num)
RESULT = Excel.Evaluate("BAHTTEXT(" + num + ")")
FEND
FUNCTION CHAR(num)
RESULT = Excel.Evaluate("CHAR(" + num + ")")
FEND
FUNCTION CLEAN(str)
RESULT = Excel.Evaluate("CLEAN(" + str + ")")
FEND
FUNCTION CODE(str)
RESULT = Excel.Evaluate("CODE(" + str + ")")
FEND
FUNCTION DATEVALUE(str)
RESULT = Excel.Evaluate("DATEVALUE(<#DBL>" + str + "<#DBL>)")
FEND
FUNCTION YEN(num, digit = "")
RESULT = Excel.Evaluate("YEN(" + num + ", " + digit + ")")
FEND
FUNCTION EXACT(str1, str2)
RESULT = Excel.Evaluate("EXACT(" + str1 + ", " + str2 + ")")
FEND
FUNCTION FIND(str)
RESULT = Excel.Evaluate("FIND(" + str + ")")
FEND
FUNCTION FINDB(str)
RESULT = Excel.Evaluate("FINDB(" + str + ")")
FEND
FUNCTION FIXED(str, digit = "", separator = "")
RESULT = Excel.Evaluate("FIXED(" + str + ", " + digit + ", " + separator + ")")
FEND
FUNCTION LEFT(str, num = "")
RESULT = Excel.Evaluate("LEFT(<#DBL>" + str + "<#DBL>, " + num + ")")
FEND
FUNCTION LEFTB(str, byte = "")
RESULT = Excel.Evaluate("LEFTB(" + str + ", " + byte + ")")
FEND
FUNCTION LEN(str)
RESULT = Excel.Evaluate("LEN(<#DBL>" + str + ")")
FEND
FUNCTION LENB(str)
RESULT = Excel.Evaluate("LENB(" + str + ")")
FEND
FUNCTION LOWER(str)
RESULT = Excel.Evaluate("LOWER(" + str + ")")
FEND
FUNCTION MID(str, start, num)
RESULT = Excel.Evaluate("MID(" + str + ", " + start + ", " + num + ")")
FEND
FUNCTION MIDB(str, start, num)
RESULT = Excel.Evaluate("MIDB(" + str + ", " + start + ", " + num + ")")
FEND
FUNCTION PROPER(str)
RESULT = Excel.Evaluate("PROPER(" + str + ")")
FEND
FUNCTION REPLACE(str, start, length, replace)
RESULT = Excel.Evaluate("REPLACE(" + str + ", " + start + ", " + length + ", " + replace + ")")
FEND
FUNCTION REPLACEB(str, start, byte, replace)
RESULT = Excel.Evaluate("REPLACEB(" + str + ", " + start + ", " + byte + ", " + replace + ")")
FEND
FUNCTION REPT(str, num)
RESULT = Excel.Evaluate("REPT(" + str + ", " + num + ")")
FEND
FUNCTION RIGHT(str, num = "")
RESULT = Excel.Evaluate("RIGHT(<#DBL>" + str + "<#DBL>, " + num + ")")
FEND
FUNCTION RIGHTB(str, byte = "")
RESULT = Excel.Evaluate("RIGHTB(" + str + ", " + byte + ")")
FEND
FUNCTION SEARCH(str, target, start = "")
RESULT = Excel.Evaluate("SEARCH(" + str + ", " + target + ", " + start + ")")
FEND
FUNCTION SEARCHB(str, target, start = "")
RESULT = Excel.Evaluate("SEARCHB(" + str + ", " + target + ", " + start + ")")
FEND
FUNCTION SUBSTITUTE(str1, str2, str3, target = "")
RESULT = Excel.Evaluate("SUBSTITUTE(" + str1 + ", " + str2 + ", " + str3 + ", " + target + ")")
FEND
FUNCTION T(num)
RESULT = Excel.Evaluate("T(" + num + ")")
FEND
FUNCTION TEXT(num, format)
RESULT = Excel.Evaluate("TEXT(" + num + ", <#DBL>" + format + "<#DBL>)")
FEND
FUNCTION TRIM(str)
RESULT = Excel.Evaluate("TRIM(" + str + ")")
FEND
FUNCTION UPPER(str)
RESULT = Excel.Evaluate("UPPER(" + str + ")")
FEND
FUNCTION VALUE(str)
RESULT = Excel.Evaluate("VALUE(" + str + ")")
FEND
ENDMODULE
FUNCTION fact(n)
IF n <> ABS(INT(n)) THEN EXIT
IFB n = 0 OR n = 1 THEN
RESULT = 1
ELSE
RESULT = n * fact(n - 1)
ENDIF
FEND
FUNCTION factDouble(n)
IF n <> ABS(INT(n)) THEN EXIT
IFB n = 0 THEN
RESULT = 1
EXIT
ENDIF
IFB n <= 2 THEN
RESULT = n
ELSE
RESULT = n * factDouble(n - 2)
ENDIF
FEND
FUNCTION Fibonacci(n)
IFB RESIZE(Fibonacci) >= n THEN
IFB Fibonacci[n] <> EMPTY THEN
RESULT = Fibonacci[n]
EXIT
ENDIF
ENDIF
SELECT n
CASE 0
IFB RESIZE(Fibonacci) < n THEN
RESIZE(Fibonacci, n)
Fibonacci[0] = 0
ENDIF
RESULT = 0
EXIT
CASE 1
IFB RESIZE(Fibonacci) < n THEN
RESIZE(Fibonacci, n)
Fibonacci[1] = 1
ENDIF
RESULT = 1
EXIT
DEFAULT
IFB RESIZE(Fibonacci) < n THEN
RESIZE(Fibonacci, n)
Fibonacci[n] = Fibonacci(n - 1) + Fibonacci(n - 2)
ENDIF
SELEND
RESULT = Fibonacci[n-1] + Fibonacci[n-2]
FEND
PROCEDURE FisherYates(var arr[])
FOR n = UBound(arr) TO 0 STEP -1
DIM num = RANDOM(n+1)
DIM tmp = arr[n]
arr[n] = arr[num]
arr[num] = tmp
NEXT
FEND
PROCEDURE forceQuit()
EXITEXIT
FEND
FUNCTION GCD(arr[])
DIM c = LENGTH(arr)
DIM rem = arr[c-1] MOD arr[c-2]
IFB rem = 0 THEN
IFB LENGTH(arr) = 2 THEN
RESULT = arr[c-2]
EXIT
ENDIF
RESIZE(arr, c-2)
RESULT = GCD(arr)
EXIT
ENDIF
arr[c-1] = arr[c-2]
arr[c-2] = rem
RESULT = GCD(arr)
FEND
FUNCTION getBitmap(path)
DIM arr[3] // 戻り値
DIM Stream = CREATEOLEOBJ("ADODB.Stream")
Stream.Open()
Stream.Type = 1 // adTypeBinary
Stream.LoadFromFile(path)
DIM tmp = Stream.Read(30)
Stream.Close()
// BM(0~1)
DIM fmt = ""
FOR n = 0 TO 1
fmt = fmt + decToHex(tmp[n])
NEXT
IFB fmt <> "424D" THEN
RESULT = ERR_VALUE
EXIT
ENDIF
// サイズ(2~5)
DIM size = ""
FOR n = 2 TO 5
size = size + REPLACE(FORMAT(VAL(decToHex(tmp[n])), 2), " ", "0")
NEXT
arr[0] = hexToDec(Endian(size))
// 幅(18~21)
DIM width = ""
FOR n = 18 TO 21
width = width + REPLACE(FORMAT(VAL(decToHex(tmp[n])), 2), " ", "0")
NEXT
arr[1] = hexToDec(Endian(width))
// 高さ(22~25)
DIM height = ""
FOR n = 22 TO 25
height = height + REPLACE(FORMAT(VAL(decToHex(tmp[n])), 2), " ", "0")
NEXT
arr[2] = hexToDec(Endian(height))
// ビットの深さ(28~29)
DIM bit = ""
FOR n = 28 TO 29
bit = bit + REPLACE(FORMAT(VAL(decToHex(tmp[n])), 2), " ", "0")
NEXT
arr[3] = hexToDec(Endian(bit))
RESULT = SLICE(arr)
FEND
FUNCTION getBitNumber()
SELECT KINDOFOS(TRUE)
CASE TRUE
RESULT = "64bit"
CASE FALSE
RESULT = "32bit"
SELEND
FEND
FUNCTION getDay(date)
GETTIME(0, date)
RESULT = G_TIME_DD2
FEND
FUNCTION getEndOfMonth(date, m = 0)
GETTIME(0, date)
IFB m >= 0 THEN
year = G_TIME_YY + INT((G_TIME_MM + m + 1) / 12)
month = REPLACE(FORMAT(((G_TIME_MM + m + 1) MOD 12), 2), " ", "0")
ELSE
year = G_TIME_YY + CEIL((G_TIME_MM + m + 1) / 12 - 1)
month = REPLACE(FORMAT(G_TIME_MM - (ABS(m + 1) MOD 12), 2), " ", "0")
IF EVAL(month) < 0 THEN month = REPLACE(FORMAT(12 + EVAL(month), 2), " ", "0")
ENDIF
IF month = "00" THEN month = "12"
day = "01"
d = "" + year + month + day
GETTIME(-1, d)
RESULT = G_TIME_YY4 + "/" + G_TIME_MM2 + "/" + G_TIME_DD2
FEND
FUNCTION getHour(date)
GETTIME(0, date)
RESULT = G_TIME_HH2
FEND
FUNCTION getIEObj(str, flg = FALSE)
DIM Shell = CREATEOLEOBJ("Shell.Application")
SELECT CHKNUM(str)
CASE TRUE
DIM cnt = 0
SELECT TRUE
CASE str > 0
FOR n = 0 TO Shell.Windows.Count - 1
TRY
IFB Shell.Windows.Item(n).Name = "Internet Explorer" THEN
cnt = cnt + 1
IFB str = cnt THEN
RESULT = Shell.Windows.Item(n)
EXIT
ENDIF
ENDIF
EXCEPT
ENDTRY
NEXT
CASE str < 0
FOR n = Shell.Windows.Count - 1 TO 0 STEP -1
TRY
IFB Shell.Windows.Item(n).Name = "Internet Explorer" THEN
cnt = cnt + 1
IFB ABS(str) = cnt THEN
RESULT = Shell.Windows.Item(n)
EXIT
ENDIF
ENDIF
EXCEPT
ENDTRY
NEXT
CASE str = 0
FOR n = 0 TO Shell.Windows.Count - 1
TRY
IF Shell.Windows.Item(n).Name = "Internet Explorer" THEN cnt = cnt + 1
EXCEPT
ENDTRY
NEXT
RESULT = cnt
EXIT
SELEND
CASE FALSE
DIM t = GETTIME()
REPEAT
FOR n = 0 TO Shell.Windows.Count - 1
TRY
DIM targetObj = Shell.Windows.Item(n)
IFB targetObj.Name = "Internet Explorer" THEN
SELECT flg
CASE TRUE
IFB targetObj.document.title = str OR targetObj.LocationURL = str THEN
RESULT = Shell.Windows.Item(n)
EXIT
ENDIF
CASE FALSE
IFB POS(str, targetObj.document.title) OR POS(str, targetObj.LocationURL) THEN
RESULT = Shell.Windows.Item(n)
EXIT
ENDIF
SELEND
ENDIF
EXCEPT
ENDTRY
NEXT
UNTIL GETTIME() - t >= 5
SELEND
RESULT = ERR_VALUE
FEND
FUNCTION getKyureki(year, month, day)
DIM tm = YMDToJD(year, month, day, 0, 0, 0)
DIM chu[-1] // n*2︰ユリウス日、n*2+1︰Δλsun0、n=0,1,2
DIM tmp
tmp = nishiNibun(tm)
FOR n = 0 TO UBound(tmp)
arrayPush(chu, tmp[n])
NEXT
// 中気の計算 3回 chu[n]︰n+1回目
FOR n = 0 TO 2
tmp = chuki(chu[n*2] + 32)
FOR n = 0 TO UBound(tmp)
arrayPush(chu, tmp[n])
NEXT
NEXT
DIM saku[5]
saku[0] = saku(chu[0])
// 朔の計算
FOR n = 1 TO 4
saku[n] = saku(saku[n-1] + 30)
IFB ABS(INT(saku[n-1]) - INT(saku[n])) <= 26 THEN
saku[n] = saku(saku[n-1] + 35)
ENDIF
NEXT
// 朔の修正
SELECT TRUE
CASE saku[1] <= INT(chu[0*2+0])
SHIFTARRAY(saku, -1)
saku[4] = saku(saku[3] + 35)
CASE saku[0] > INT(chu[0*2+0])
SHIFTARRAY(saku, 1)
saku[0] = saku(saku[0] - 27)
SELEND
DIM kyureki[3] // 0︰年、1︰閏月、2︰月、3︰日
// 閏月検索
DIM flg = FALSE
IF INT(saku[4]) <= INT(chu[3*2+0]) THEN flg = TRUE
DIM m[4][2]
m[0][0] = INT(chu[0*2+1]/30) + 2
IF m[0][1] > 12 THEN m[0][0] = m[0][0] - 12
m[0][2] = INT(saku[0*0+0])
m[0][1] = ""
FOR n = 1 TO 4
IFB flg = TRUE AND n <> 1 THEN
IFB INT(chu[(n-1)*2+0]) <= INT(saku[n-1]) OR INT(chu[(n-1)*2+0]) >= INT(saku[n]) THEN
m[n-1][0] = m[n-2][0]
m[n-1][1] = "閏"
m[n-1][2] = INT(saku[n-1])
flg = FALSE
ENDIF
ENDIF
m[n][0] = m[n-1][0] + 1
IF m[n][0] > 12 THEN m[n][0] = m[n][0] - 12
m[n][2] = INT(saku[n])
m[n][1] = ""
NEXT
DIM state = 0
FOR n = 0 TO 4
IFB INT(tm) < INT(m[n][2]) THEN
state = 1
BREAK
ELSEIF INT(tm) = INT(m[n][2]) THEN
state = 2
BREAK
ENDIF
NEXT
IF state = 0 OR state = 1 THEN n = n - 1
DIM kyureki[3]
kyureki[1] = m[n][1]
kyureki[2] = m[n][0]
kyureki[3] = INT(tm) - INT(m[n][2]) + 1
d = JDToYMD(tm)
kyureki[0] = d[0]
IF kyureki[2] > 9 AND kyureki[2] > d[1] THEN kyureki[0] = kyureki[0] - 1
RESULT = SLICE(kyureki)
FEND
FUNCTION getMakerName()
RESULT = TRIM(REPLACE(DOSCMD("wmic csproduct get Vendor"), "Vendor", ""))
FEND
FUNCTION getMinute(date)
GETTIME(0, date)
RESULT = G_TIME_NN2
FEND
FUNCTION getModelName()
RESULT = TRIM(REPLACE(DOSCMD("wmic csproduct get Name"), "Name", ""))
FEND
FUNCTION getMonth(date)
GETTIME(0, date)
RESULT = G_TIME_MM2
FEND
FUNCTION getMUSCUR(n)
HASHTBL cur
cur[CUR_APPSTARTING] = "砂時計付き矢印カーソル"
cur[CUR_ARROW] = "標準矢印カーソル"
cur[CUR_CROSS] = "十字カーソル"
cur[CUR_HAND] = "ハンドカーソル"
cur[CUR_HELP] = "クエスチョンマーク付き矢印カーソル"
cur[CUR_IBEAM] = "アイビーム(縦線)カーソル"
cur[CUR_NO] = "禁止カーソル"
cur[CUR_SIZEALL] = "4方向矢印カーソル"
cur[CUR_SIZENESW] = "斜め左下がりの両方向矢印カーソル"
cur[CUR_SIZENS] = "上下両方向矢印カーソル"
cur[CUR_SIZENWSE] = "斜め右下がりの両方向矢印カーソル"
cur[CUR_SIZEWE] = "左右両方向矢印カーソル"
cur[CUR_UPARROW] = "垂直の矢印カーソル"
cur[CUR_WAIT] = "砂時計カーソル"
RESULT = cur[n]
FEND
FUNCTION getNthWeekday(n, w, date = EMPTY)
GETTIME(0, date)
d = 1 - G_TIME_DD
GETTIME(d, date)
w = w - G_TIME_WW
d = d + w + ((w < 0) + n - 1) * 7
GETTIME(d, date)
RESULT = G_TIME_YY4 + "/" + G_TIME_MM2 + "/" + G_TIME_DD2
FEND
FUNCTION getOSType()
HASHTBL os
os["10"] = "NT3.5"; os["11"] = "NT4";
os["12"] = "Win2000"; os["13"] = "WinXP";
os["14"] = "Server2003"; os["20"] = "Vista";
os["21"] = "Server2008"; os["22"] = "Windows 7";
os["23"] = "Windows 8"; os["24"] = "Server2012";
os["25"] = "Windows 8.1"; os["30"] = "Windows 10";
os["31"] = "Server2016";
RESULT = os[KINDOFOS()]
FEND
FUNCTION getRokuyo(year, month, day)
DIM arr[6] = "大安", "赤口", "先勝", "友引", "先負", "仏滅""
DIM d = getKyureki(year, month, day)
DIM n = (d[2] + d[3]) MOD 6
RESULT = arr[n]
FEND
FUNCTION getSecond(date)
GETTIME(0, date)
RESULT = G_TIME_SS2
FEND
FUNCTION getSerialNumber()
RESULT = TRIM(REPLACE(DOSCMD("wmic csproduct get IdentifyingNumber"), "IdentifyingNumber", ""))
FEND
FUNCTION getSerialTime(uwscTime)
RESULT = (GETTIME(0, uwscTime) - GETTIME(0, "1899/12/30 00:00:00")) / 86400
FEND
PROCEDURE getSubFolders(var array[], folderspec)
DIM FSO = CREATEOLEOBJ("Scripting.FileSystemObject")
DIM Folder = FSO.GetFolder(folderspec)
DIM Folders = Folder.SubFolders
FOR Folder IN Folders
arrayPush(array, Folder.Path)
getSubFolders(array, Folder.Path)
NEXT
FEND
PROCEDURE getTableData(table, Var arr[][])
rowMax = table.rows.length - 1
colMax = 0
FOR row = 0 TO table.rows.length - 1
IFB table.rows(row).cells.length - 1 > colMax THEN
colMax = table.rows(row).cells.length - 1
ENDIF
NEXT
DIM arr[rowMax][colMax]
FOR row = 0 TO table.rows.length - 1
FOR col = 0 TO table.rows(row).cells.length - 1
n = 0
WHILE arr[row][col + n] <> ""
n = n + 1
WEND
arr[row][col + n] = table.rows(row).cells(col).innerText
// rowSpan(行結合)とcolSpan(列結合)の両方があれば
IFB table.rows(row).cells(col).rowSpan > 1 AND table.rows(row).cells(col).colSpan > 1 THEN
rmax = table.rows(row).cells(col).rowSpan - 1
cmax = table.rows(row).cells(col).colSpan - 1
FOR r = 1 TO rmax
FOR c = 1 TO cmax
arr[row + r][col + c] = "←"
NEXT
NEXT
ENDIF
// rowSpan(行結合)があれば結合セルに「↑」を代入
IFB table.rows(row).cells(col).rowSpan > 1 THEN
n = table.rows(row).cells(col).rowSpan - 1
WHILE n
arr[row + n][col] = "↑"
n = n - 1
WEND
ENDIF
// colSpan(列結合)があれば結合セルに「←」を代入
IFB table.rows(row).cells(col).colSpan > 1 THEN
n = table.rows(row).cells(col).colSpan - 1
WHILE n
arr[row][col + n] = "←"
n = n - 1
WEND
ENDIF
NEXT
NEXT
FEND
FUNCTION getUNIXTime(date)
RESULT = (GETTIME(0, date) - GETTIME(0, "1970/01/01 09:00:00"))
FEND
FUNCTION getVARTYPE(n)
HASHTBL type
type[VAR_EMPTY] = "Empty"
type[VAR_NULL] = "Null"
type[VAR_SMALLINT] = "2バイト整数"
type[VAR_INTEGER] = "4バイト整数"
type[VAR_SINGLE] = "単精度浮動小数点値"
type[VAR_DOUBLE] = "倍精度浮動小数点値"
type[VAR_CURRENCY] = "通貨型"
type[VAR_DATE] = "日付型"
type[VAR_DISPATCH] = "オブジェクト"
type[VAR_ERROR] = "エラー値"
type[VAR_BOOLEAN] = "ブール型"
type[VAR_VARIANT] = "バリアント"
type[VAR_UNKNOWN] = "未定義のオブジェクト"
type[VAR_SBYTE] = "1バイト整数"
type[VAR_BYTE] = "1バイト整数"
type[VAR_WORD] = "2バイト整数"
type[VAR_DWORD] = "4バイト整数"
type[VAR_INT64] = "8バイト整数"
type[VAR_ASTR] = "ANSI文字列"
type[VAR_USTR] = "UNICODE文字列"
type[VAR_ARRAY] = "配列"
RESULT = type[n]
FEND
FUNCTION getWeekday(date)
GETTIME(0, date)
RESULT = G_TIME_WW
FEND
FUNCTION getWeekdayName(num, format = "aaa")
DIM re = CREATEOLEOBJ("VBScript.RegExp")
DIM aaa[] = "日", "月", "火", "水", "木", "金", "土";
DIM aaaa[] = "日曜日", "月曜日", "火曜日", "水曜日", "木曜日", "金曜日", "土曜日";
DIM ddd[] = "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat";
DIM dddd[] = "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday";
match = reExecute(format, "(a|d)+")
type = match.Item(0).Value
RESULT = reReplace(format, EVAL(type + "[" + num + "]"), type)
FEND
FUNCTION getWiFiInterface(n)
DIM arr[] = "名前", "説明", "GUID", "物理アドレス", "状態", "SSID", "BSSID", "ネットワークの種類", "無線の種類", "認証", "暗号", "接続モード", "チャネル", "受信速度", "送信速度", "シグナル", "プロファイル", "ホストされたネットワークの状態"
str = DOSCMD("netsh wlan show interface")
match = reExecute(str, arr[n] + ".*?:\s(.*?)\r\n")
RESULT = match.Item(0).SubMatches.Item(0)
FEND
FUNCTION getWiFiPass(SSID)
str = DOSCMD("netsh wlan show profiles name=" + SSID + " key=clear")
match = reExecute(str, "主要なコンテンツ.*?\r\n")
RESULT = TRIM(COPY(match.Item(0).Value, POS(":", match.Item(0).Value)+1))
FEND
FUNCTION getWiFiProfiles()
cmd = "netsh wlan show profiles"
str = DOSCMD(cmd)
matches = reExecute(str, ".*?:\s(.*?)\r\n")
num = matches.Count - 1
DIM res[num]
FOR n = 0 TO num
res[n] = matches.Item(n).SubMatches(0)
NEXT
RESULT = SLICE(res)
FEND
FUNCTION getYear(date)
GETTIME(0, date)
RESULT = G_TIME_YY4
FEND
PROCEDURE gnomeSort(Var array[])
DIM n = 1
DIM num = UBound(array)
WHILE n < num + 1
IFB array[n-1] <= array[n] THEN
n = n + 1
ELSE
swap(array[n], array[n-1])
n = n - 1
IF n = 0 THEN n = n + 1
ENDIF
WEND
FEND
PROCEDURE hashInvert(Var hash[])
HASHTBL tmp
DIM cnt = LENGTH(hash)
FOR n = 0 TO cnt - 1
tmp[hash[n, HASH_VAL]] = hash[n, HASH_KEY]
NEXT
hash = HASH_REMOVEALL
FOR n = 0 TO cnt - 1
hash[tmp[n, HASH_KEY]] = tmp[n, HASH_VAL]
NEXT
FEND
PROCEDURE hashValueSort(Var hash[])
HASHTBL tmp = HASH_SORT
DIM cnt = LENGTH(hash)
hashInvert(hash)
FOR n = 0 TO cnt - 1
tmp[hash[n, HASH_KEY]] = hash[n, HASH_VAL]
NEXT
hash = HASH_REMOVEALL
FOR n = 0 TO cnt - 1
hash[tmp[n, HASH_VAL]] = tmp[n, HASH_KEY]
NEXT
FEND
PROCEDURE heapSort(Var array[])
DIM i = 0
DIM u = UBound(array)
WHILE i < u
upHeap(array, i)
i = i + 1
WEND
WHILE i > 0
swap(array[0], array[i])
downHeap(array, i)
i = i - 1
WEND
FEND
PROCEDURE upHeap(Var array[], n)
WHILE n > 0
DIM parent = (n - 1) / 2
IFB array[parent] < array[n] THEN
swap(array[parent], array[n])
ELSE
BREAK
ENDIF
n = parent
WEND
FEND
PROCEDURE downHeap(Var array[], n)
DIM m = 0
DIM tmp = 0
WHILE TRUE
DIM LtChild = (m + 1) * 2 - 1
DIM RtChild = (m + 1) * 2
IF LtChild >= n THEN BREAK
IF array[LtChild] > array[tmp] THEN tmp = LtChild
IF RtChild < n AND array[RtChild] > array[tmp] THEN tmp = RtChild
IF tmp = m THEN BREAK
swap(array[tmp], array[m])
m = tmp
WEND
FEND
FUNCTION hexToBin(hex)
HASHTBL hb
hb["0"] = "0000"; hb["1"] = "0001";
hb["2"] = "0010"; hb["3"] = "0011";
hb["4"] = "0100"; hb["5"] = "0101";
hb["6"] = "0110"; hb["7"] = "0111";
hb["8"] = "1000"; hb["9"] = "1001";
hb["a"] = "1010"; hb["b"] = "1011";
hb["c"] = "1100"; hb["d"] = "1101";
hb["e"] = "1110"; hb["f"] = "1111";
bin = ""
FOR n = 1 TO LENGTH(hex)
bin = bin + hb[COPY(hex, n, 1)]
NEXT
RESULT = bin
FEND
FUNCTION hexToDec(hex)
dec = 0
hex = STRCONV(hex, SC_LOWERCASE)
FOR n = 1 TO LENGTH(hex)
str = COPY(hex, n, 1)
IFB CHKNUM(str) THEN
num = str
ELSE
num = ASC(str) - 87
ENDIF
dec = dec + (num * POWER(16, LENGTH(hex) - n))
NEXT
RESULT = dec
FEND
FUNCTION Hour(serial)
RESULT = REPLACE(FORMAT(INT(serial * 24), 2), " ", "0")
FEND
FUNCTION IEBoot(InPrivate = FALSE)
DIM IE
SELECT InPrivate
CASE TRUE
DOSCMD("start iexplore -private")
GETID("InPrivate - Internet Explorer - [InPrivate]", "IEFrame", -1)
IE = GETACTIVEOLEOBJ("InternetExplorer.Application","InPrivate - Internet Explorer - [InPrivate]")
CASE FALSE
TRY
IE = CREATEOLEOBJ("InternetExplorer.Application")
IE.Visible = TRUE
EXCEPT
EXEC("C:\Program Files\Internet Explorer\iexplore.exe")
GETID("Internet Explorer", "IEFrame", -1)
TRY
IE = GETACTIVEOLEOBJ("InternetExplorer.Application")
EXCEPT
IE = getIEObj(-1)
ENDTRY
ENDTRY
SELEND
RESULT = IE
FEND
FUNCTION IENoticeBar()
REPEAT
ID = GETID("Internet Explorer", "IEFrame")
DirectUIHWND = GETCTLHND(ID, "DirectUIHWND", 2)
IF DirectUIHWND <> 0 THEN GETCTLHND(ID, "DirectUIHWND", 1)
UNTIL DirectUIHWND <> 0
REPEAT
popupHandle = HNDTOID(DirectUIHWND)
UNTIL popupHandle <> 0
REPEAT
SLEEP(0.50)
DirectUIHWND = GETCTLHND(ID, "DirectUIHWND", 2)
IF DirectUIHWND <= 0 THEN DirectUIHWND = GETCTLHND(ID, "DirectUIHWND", 1)
popupHandle = HNDTOID(DirectUIHWND)
NotificationBar = CLKITEM(popupHandle, "保存", CLK_ACC)
UNTIL NotificationBar <> 0
REPEAT
SLEEP(0.50)
UNTIL POS("のダウンロードが完了しました。", GETSTR(popupHandle, 1, STR_ACC_STATIC))
str = GETSTR(popupHandle, 1, STR_ACC_STATIC)
CLKITEM(popupHandle, "閉じる", CLK_ACC)
RESULT = COPY(str, 1, POS(" のダウンロードが完了しました。", str) - 1)
FEND
FUNCTION IIF(expr, truepart, falsepart)
IFB EVAL(expr) THEN
RESULT = truepart
ELSE
RESULT = falsepart
ENDIF
FEND
FUNCTION inArray( needle, haystack[], strict = FALSE)
DIM res = FALSE
FOR item IN haystack
IFB needle = item THEN
res = TRUE
BREAK
ENDIF
NEXT
RESULT = res
FEND
PROCEDURE insertionSort(Var array[])
FOR i = 1 TO UBound(array)
j = i
WHILE j > 0
IF array[j-1] > array[j] THEN swap(array[j-1], array[j])
j = j - 1
WEND
NEXT
FEND
// WiFiに接続しているかどうか
FUNCTION isConnectedWiFi()
HASHTBL LAN
str = SPLIT(DOSCMD("netsh wlan show interface"), "<#CR>")
FOR n = 0 TO UBound(str)
IFB POS(":", str[n]) THEN
arr = SPLIT(str[n], ":")
LAN[TRIM(arr[0])] = TRIM(arr[1])
ENDIF
NEXT
res = FALSE
// SSIDが取得できたらWiFiに接続されていると判断
IF LENGTH(LAN["SSID"]) <> 0 THEN res = TRUE
RESULT = res
FEND
FUNCTION isDate(date)
DIM Pattern = "^(?!([02468][1235679]|[13579][01345789])000229)(([0-9]{4}(01|03|05|07|08|10|12)(0[1-9]|[12][0-9]|3[01]))|([0-9]{4}(04|06|09|11)(0[1-9]|[12][0-9]|30))|([0-9]{4}02(0[1-9]|1[0-9]|2[0-8]))|([0-9]{2}([02468][048]|[13579][26])0229))$"
DIM Match = reExecute(date, Pattern)
RESULT = IIF(Match.Count <> 0, TRUE, FALSE)
FEND
FUNCTION isEven(n)
IFB n <> VARTYPE(n, VAR_INTEGER) THEN
RESULT = ERR_VALUE
EXIT
ENDIF
RESULT = IIF(n MOD 2 = 0, TRUE, FALSE)
FEND
FUNCTION isFile(path)
RESULT = TRIM(DOSCMD("IF EXIST " + path + " (echo TRUE) ELSE echo FALSE"))
FEND
FUNCTION isOdd(n)
IFB n <> VARTYPE(n, VAR_INTEGER) THEN
RESULT = ERR_VALUE
EXIT
ENDIF
RESULT = IIF(n MOD 2 <> 0, TRUE, FALSE)
FEND
FUNCTION isPrime(num)
SELECT TRUE
CASE num < 2
RESULT = FALSE
EXIT
CASE num = 2
RESULT = TRUE
EXIT
CASE num MOD 2 = 0
RESULT = FALSE
EXIT
SELEND
FOR n = 3 TO SQRT(num) STEP 2
IFB num MOD n = 0 THEN
RESULT = FALSE
EXIT
ENDIF
NEXT
RESULT = TRUE
FEND
FUNCTION JDToYMD(JD)
DIM x0 = INT(JD + 68570)
DIM x1 = INT(x0 / 36524.25)
DIM x2 = x0 - INT(36524.25 * x1 + 0.75)
DIM x3 = INT((x2 + 1) / 365.2425)
DIM x4 = x2 - INT(365.25 * x3) + 31
DIM x5 = INT(INT(x4) / 30.59)
DIM x6 = INT(INT(x5) / 11)
DIM t2 = x4 - INT(30.59 * x5)
DIM t1 = x5 - 12 * x6 + 2
DIM t0 = 100 * (x1 - 49) + x3 + x6
IFB t1 = 2 AND t2 > 28 THEN
SELECT TRUE
CASE t0 MOD 100 = 0 AND t0 MOD 400 = 0
t2 = 29
CASE t0 MOD 4 = 0
t2 = 29
DEFAULT
t2 = 28
SELEND
ENDIF
DIM tm = 86400 * (JD - INT(JD))
DIM t3 = INT(tm / 3600)
DIM t4 = INT((tm - 3600 * t3) / 60)
DIM t5 = INT(tm - 3600 * t3 - 60 * t4)
DIM t[] = t0, t1, t2, t3, t4, t5
RESULT = SLICE(t)
FEND
FUNCTION JISToSJIS(JIS)
DIM arr[1]
DIM res[1]
arr[0] = hexToDec(COPY(JIS, 1, 2))
arr[1] = hexToDec(COPY(JIS, 3, 2))
// 上位8bit
arr[0] = arr[0] - $21
// 上位7bit
res[0] = binToDec(COPY(decToBin(arr[0]), 1, LENGTH(decToBin(arr[0])) - 1))
res[0] = decToHex(res[0] + IIF(res[0] <= $1E, $81, $C1))
// 下位8bit
SELECT COPY(hexToBin(arr[0]), LENGTH(hexToBin(arr[0])))
CASE "0"
res[1] = arr[1] + $1F
IFB res[1] >= $7F THEN
res[1] = decToHex(res[1] + 1)
ELSE
res[1] = decToHex(res[1])
ENDIF
CASE "1"
res[1] = decToHex(arr[1] + $7E)
SELEND
RESULT = JOIN(res, "")
FEND
FUNCTION Kaprekar(num)
IFB !reTest(num, "\d+") THEN
RESULT = ERR_VALUE
EXIT
ENDIF
DIM res[-1]
DIM cnt = 0
arrayPush(res, num)
WHILE TRUE
DIM array[-1]
FOR n = 1 TO LENGTH(res[cnt])
arrayPush(array, COPY(res[cnt], n, 1))
NEXT
QSORT(array, 1) // 降順
mx = VAL(JOIN(array, ""))
QSORT(array, 0) // 昇順
mn = VAL(JOIN(array, ""))
arrayPush(res, mx - mn)
cnt = cnt + 1
IF res[cnt-1] = res[cnt] THEN BREAK
WEND
RESIZE(res, UBound(res)-1)
RESULT = SLICE(res)
FEND
FUNCTION LBound(arr[])
RESULT = UBound(arr) - LENGTH(arr) + 1
FEND
FUNCTION LCM(arr[])
DIM c = LENGTH(arr)
DIM arr2[] = arr[c-1], arr[c-2]
DIM rem = arr[c-1] * arr[c-2] / GCD(arr2)
IFB c = 2 THEN
RESULT = rem
EXIT
ENDIF
arr[c-2] = rem
RESIZE(arr, c-2)
RESULT = LCM(arr)
FEND
FUNCTION Left(str, len)
RESULT = COPY(str, 1, len)
FEND
FUNCTION longitudeMoon(JC)
DIM A[63] = 0.0003, 0.0003, 0.0003, 0.0003, 0.0003, 0.0003, 0.0003, 0.0004, 0.0004, 0.0005, 0.0005, 0.0005, 0.0006, 0.0006, 0.0007, 0.0007, 0.0007, 0.0007, 0.0008, 0.0009, 0.0011, 0.0012, 0.0016, 0.0018, 0.0021, 0.0021, 0.0021, 0.0022, 0.0023, 0.0024, 0.0026, 0.0027, 0.0028, 0.0037, 0.0038, 0.004, 0.004, 0.004, 0.005, 0.0052, 0.0068, 0.0079, 0.0085, 0.01, 0.0107, 0.011, 0.0125, 0.0154, 0.0304, 0.0347, 0.0409, 0.0458, 0.0533, 0.0571, 0.0588, 0.1144, 0.1851, 0.2136, 0.6583, 1.274, 6.2888, 481267.8809 * JC, 218.3162
DIM k[63] = 2322131, 4067, 549197, 1808933, 349472, 381404, 958465, 12006, 39871, 509131, 1745069, 1908795, 2258267, 111869, 27864, 485333, 405201, 790672, 1403732, 858602, 1920802, 1267871, 1856938, 401329, 341337, 71998, 990397, 818536, 922466, 99863, 1379739, 918399, 1934, 541062, 1781068, 133, 1844932, 1331734, 481266, 31932, 926533, 449334, 826671, 1431597, 1303870, 489205, 1443603, 75870, 513197.9, 445267.1, 441199.8, 854535.2, 1367733.1, 377336.3, 63863.5, 966404, 35999, 954397.7, 890534.2, 413335.3, 477198.9, 0, 0
DIM θ0[63] = 191, 70, 220, 58, 337, 354, 340, 187, 223, 242, 24, 90, 156, 38, 127, 186, 50, 114, 98, 129, 186, 249, 152, 274, 16, 85, 357, 151, 163, 122, 17, 182, 145, 259, 21, 29, 56, 283, 205, 107, 323, 188, 111, 315, 246, 142, 52, 41, 222.5, 27.9, 47.4, 148.2, 280.7, 13.2, 124.2, 276.5, 87.53, 179.93, 145.7, 10.74, 44.963, 0, 0
DIM λmoon[63]
FOR n = 0 TO 60
DIM ang = normalizeAngle(k[n] * JC + θ0[n])
λmoon[n] = A[n] * COS(degToRad(ang))
NEXT
λmoon[61] = normalizeAngle(A[61])
λmoon[62] = normalizeAngle(A[62])
RESULT = normalizeAngle(CALCARRAY(λmoon, CALC_ADD))
FEND
FUNCTION longitudeSun(JC)
DIM A[18] = 0.0004, 0.0004, 0.0005, 0.0005, 0.0006, 0.0007, 0.0007, 0.0007, 0.0013, 0.0015, 0.0018, 0.0018, 0.0020, 0.0200, -0.0048*JC, 1.9147, 36000.7695*JC, 280.4659
DIM k[18] = 31557.0, 29930.0, 2281.0, 155.0, 33718.0, 9038.0, 3035.0, 65929.0, 22519.0, 45038.0, 445267.0, 19.0, 32964.0, 71998.1, 35999.05, 35999.05, 0, 0
DIM θ0[18] = 161.0, 48.0, 221.0, 118.0, 316.0, 64.0, 110.0, 45.0, 352.0, 254.0, 208.0, 159.0, 158.0, 265.1, 267.52, 267.52, 0, 0
DIM λsun[18]
FOR n = 0 TO 15
DIM ang = normalizeAngle(k[n] * JC + θ0[n])
λsun[n] = A[n] * COS(degToRad(ang))
NEXT
λsun[16] = normalizeAngle(A[16])
λsun[17] = normalizeAngle(A[17])
RESULT = normalizeAngle(CALCARRAY(λsun, CALC_ADD))
FEND
FUNCTION Lucas(n)
SELECT n
CASE 0
RESULT = 2
EXIT
CASE 1
RESULT = 1
EXIT
SELEND
RESULT = Lucas(n - 1) + Lucas(n - 2)
FEND
PROCEDURE mergeSort(Var array[], Lt = 0, Rt = 0)
IF Rt = 0 THEN Rt = UBound(array)
IFB Rt - Lt <= 1 THEN
IFB array[Lt] >= array[Rt] THEN
swap(array[Lt], array[Rt])
ENDIF
EXIT
ENDIF
DIM mid = INT((Lt + Rt) / 2)
mergeSort(array, Lt, mid)
mergeSort(array, mid + 1, Rt)
merge(array, Lt, mid + 1, Rt)
FEND
PROCEDURE merge(Var array[], Lt, mid, Rt)
DIM tmp1 = SLICE(array, Lt, mid - 1)
DIM tmp2 = SLICE(array, mid, Rt)
DIM tmp[-1]
WHILE tmp1[0] <> EMPTY OR tmp2[0] <> EMPTY
IFB (tmp1[0] < tmp2[0] AND tmp1[0] <> EMPTY) OR tmp2[0] = EMPTY THEN
arrayPush(tmp, tmp1[0])
SHIFTARRAY(tmp1, -1)
ELSE
arrayPush(tmp, tmp2[0])
SHIFTARRAY(tmp2, -1)
ENDIF
WEND
FOR n = Lt TO Rt
array[n] = tmp[n-Lt]
NEXT
FEND
FUNCTION Minute(serial)
RESULT = REPLACE(FORMAT(INT(serial * 1440) MOD 60, 2), " ", "0")
FEND
MODULE MORSE
HASHTBL code
PROCEDURE MORSE()
code["A"] = "・-"
code["B"] = "-・・・"
code["C"] = "-・-・"
code["D"] = "-・・"
code["E"] = "・"
code["F"] = "・・-・"
code["G"] = "--・"
code["H"] = "・・・・"
code["I"] = "・・"
code["J"] = "・---"
code["K"] = "-・-"
code["L"] = "・-・・"
code["M"] = "--"
code["N"] = "-・"
code["O"] = "---"
code["P"] = "・--・"
code["Q"] = "--・-"
code["R"] = "・-・"
code["S"] = "・・・"
code["T"] = "-"
code["U"] = "・・-"
code["V"] = "・・・-"
code["W"] = "・--"
code["X"] = "-・・-"
code["Y"] = "-・--"
code["Z"] = "--・・"
code["1"] = "・----"
code["2"] = "・・---"
code["3"] = "・・・--"
code["4"] = "・・・・-"
code["5"] = "・・・・・"
code["6"] = "-・・・・"
code["7"] = "--・・・"
code["8"] = "---・・"
code["9"] = "----・"
code["0"] = "-----"
code["."] = "・-・-・-"
code[","] = "--・・--"
code["?"] = "・・--・・"
code["--"] = "-・・・-"
code["-"] = "-・・・・-"
code["/"] = "-・・-・"
code["@"] = "・--・-・"
FOR n = 0 TO LENGTH(code)
code[code[n, HASH_VAL]] = code[n, HASH_KEY]
NEXT
FEND
FUNCTION encode(str)
DIM res = ""
FOR n = 1 TO LENGTH(str)
res = res + code[COPY(str, n, 1)] + " "
NEXT
RESULT = TRIM(res)
FEND
FUNCTION decode(str)
DIM res = ""
DIM arr = SPLIT(str, " ")
FOR n = 0 TO UBound(arr)
res = res + code[arr[n]]
NEXT
RESULT = res
FEND
ENDMODULE
FUNCTION nishiNibun(JD)
// ユリウス日を力学時に変換
DIM TD = JD - 9/24
DIM n = 1
REPEAT
// 力学時をユリウス世紀に変換
DIM JC = (TD + 0.5 - 2451545) / 36525
DIM λsun = longitudeSun(JC)
IF n = 1 THEN DIM λsun0 = INT(λsun / 90) * 90
DIM Δλ = λsun - λsun0
SELECT TRUE
CASE Δλ > 180
Δλ = Δλ - 360
CASE Δλ < -180
Δλ = Δλ + 180
SELEND
DIM Δt = Δλ * (365.2/360)
TD = TD - Δt
n = n + 1
UNTIL ABS(Δt) <= 1/86400
DIM arr[1]
arr[0] = TD + 9/24
arr[1] = λsun0
RESULT = SLICE(arr)
FEND
FUNCTION normalizeAngle(deg)
SELECT TRUE
CASE deg >= 360
deg = deg - INT(deg / 360) * 360
CASE deg < 0
deg = deg + INT(ABS(deg / 360) + 1) * 360
SELEND
RESULT = deg
FEND
FUNCTION now()
GETTIME()
RESULT = G_TIME_YY4 + "/" + G_TIME_MM2 + "/" + G_TIME_DD2 + " " + G_TIME_HH2 + ":" + G_TIME_NN2
FEND
PROCEDURE oddEvenSort(Var array[])
REPEAT
DIM flg = FALSE
FOR i = 0 TO UBound(array) STEP 2
IFB array[i] > array[i+1] THEN
swap(array[i], array[i+1])
flg = TRUE
ENDIF
NEXT
FOR i = 1 TO UBound(array) - 1 STEP 2
IFB array[i] > array[i+1] THEN
swap(array[i], array[i+1])
flg = TRUE
ENDIF
NEXT
UNTIL !flg
FEND
FUNCTION PathCleanupSpec(filename)
DIM filenameErrChar[12] = "\", "/", ":", "*", "?", "<#DBL>", "<#CR>", "<#TAB>", "<", ">", "|", "[", "]"
FOR item IN filenameErrChar
filename = REPLACE(filename, item, "")
NEXT
RESULT = filename
FEND
FUNCTION primeFactorization(num)
DIM arr[-1]
// 偶数なら2で割り続ける
WHILE num MOD 2 = 0
arrayPush(arr, 2)
num = num / 2
WEND
FOR n = 3 TO num
WHILE num MOD n = 0
arrayPush(arr, n)
num = num / n
WEND
NEXT
RESULT = SLICE(arr)
FEND
PROCEDURE quickSort(Var array[], Lt, Rt)
DIM LtHold = Lt
DIM RtHold = Rt
DIM pivot = array[Lt]
WHILE Lt < Rt
WHILE array[Rt] >= pivot AND Lt < Rt
Rt = Rt - 1
WEND
IFB Lt <> Rt THEN
array[Lt] = array[Rt]
Lt = Lt + 1
ENDIF
WHILE array[Lt] <= pivot AND Lt < Rt
Lt = Lt + 1
WEND
IFB Lt <> Rt THEN
array[Rt] = array[Lt]
Rt = Rt - 1
ENDIF
WEND
array[Lt] = pivot
pivot = Lt
Lt = LtHold
Rt = RtHold
IF Lt < pivot THEN quickSort(array, Lt, pivot - 1)
IF Rt > pivot THEN quickSort(array, pivot + 1, Rt)
FEND
MODULE QuotedPrintable
FUNCTION encode(str)
DIM res = ""
FOR n = 1 TO LENGTH(str)
DIM s = COPY(str, n, 1)
DIM Matches = reExecute(JISToSJIS(decToHex(ExcelFunction.CODE("<#DBL>" + s + "<#DBL>"))), "([0-9A-F]{2})([0-9A-F]{2})")
FOR m = 0 TO Matches.Count - 1
res = res + "=" + Matches.Item(m).SubMatches(0) + "=" + Matches.Item(m).SubMatches(1)
NEXT
NEXT
RESULT = res
FEND
FUNCTION decode(str)
DIM res = ""
DIM Matches = reExecute(str, "=([0-9A-F]{2})+")
DIM n = 0
WHILE n <= Matches.Count - 1
SELECT TRUE
CASE hexToDec(Matches.Item(n).SubMatches(0)) >= $81
res = res + ExcelFunction.CHAR(hexToDec(SJISToJIS(Matches.Item(n).SubMatches(0) + Matches.Item(n+1).SubMatches(0))))
n = n + 2
DEFAULT
res = res + ExcelFunction.CHAR(hexToDec(Matches.Item(n).SubMatches(0)))
n = n + 1
SELEND
WEND
RESULT = res
FEND
ENDMODULE
FUNCTION radToDeg(rad)
DIM pi = 3.14159265358979
RESULT = rad * 180 / pi
FEND
FUNCTION reExecute(str, Pattern, IgnoreCase = TRUE, Global = TRUE)
DIM re = CREATEOLEOBJ("VBScript.RegExp")
re.Pattern = Pattern
re.IgnoreCase = IgnoreCase
re.Global = Global
RESULT = re.Execute(str)
FEND
FUNCTION REPT(str, num)
DIM res
IFB ABS(INT(num)) <> num THEN
RESULT = ERR_VALUE
EXIT
ENDIF
FOR n = 1 TO num
res = res + str
NEXT
RESULT = res
FEND
FUNCTION reReplace(str1, str2, Pattern, IgnoreCase = TRUE, Global = TRUE)
DIM re = CREATEOLEOBJ("VBScript.RegExp")
re.Pattern = Pattern
re.IgnoreCase = IgnoreCase
re.Global = Global
RESULT = re.Replace(str1, str2)
FEND
FUNCTION reTest(str, Pattern, IgnoreCase = TRUE, Global = TRUE)
DIM re = CREATEOLEOBJ("VBScript.RegExp")
re.Pattern = Pattern
re.IgnoreCase = IgnoreCase
re.Global = Global
RESULT = re.Test(str)
FEND
FUNCTION Right(str, len)
RESULT = COPY(str, LENGTH(str) - len + 1)
FEND
FUNCTION ROMAN(num)
DIM arr[][1] = 1, "I", + _
2, "II", + _
3, "III", + _
4, "IV", + _
5, "V", + _
6, "VI", + _
7, "VII", + _
8, "VIII", + _
9, "IX", + _
10, "X", + _
40, "XL", + _
50, "L", + _
90, "XC", + _
100, "C", + _
400, "CD", + _
500, "D", + _
900, "CM", + _
1000, "M"
DIM res = ""
n = UBound(arr)
REPEAT
SELECT TRUE
CASE num / arr[n][0] >= 1
res = res + arr[n][1]
num = num - arr[n][0]
DEFAULT
n = n - 1
SELEND
UNTIL num = 0
RESULT = res
FEND
FUNCTION saku(JD)
DIM lc = 1 // loop counter
DIM JD1 = INT(JD)
DIM JD2 = JD - JD1
JD2 = JD2 - 9/24
DIM Δt1 = 0
DIM Δt2 = 1
WHILE ABS(Δt1+Δt2) > 1/86400
DIM JC = (JD2 + 0.5) / 36525
JC = JC + (JD1 - 2451545) / 36525
DIM λsun = longitudeSun(JC)
DIM λmoon = longitudeMoon(JC)
DIM Δλ = λmoon - λsun
SELECT TRUE
CASE lc = 1 AND Δλ < 0
Δλ = normalizeAngle(Δλ)
CASE λsun >= 0 AND λsun <= 20 AND λmoon >= 300
Δλ = normalizeAngle(Δλ)
Δλ = 360 - Δλ
CASE ABS(Δλ) > 40
Δλ = normalizeAngle(Δλ)
SELEND
Δt1 = INT(Δλ * 29.530589 / 360)
Δt2 = Δλ * 29.530589 / 360
Δt2 = Δt2 - Δt1
JD1 = JD1 - Δt1
JD2 = JD2 - Δt2
IFB JD2 < 0 THEN
JD2 = JD2 + 1
JD1 = JD1 - 1
ENDIF
IFB lc = 15 AND ABS(Δt1+Δt2) > 1/86400 THEN
JD1 = INT(JD - 26)
JD2 = 0
ELSEIF lc > 30 AND ABS(Δt1+Δt2) > 1/86400
JD1 = JD
JD2 = 0
ENDIF
lc = lc + 1
WEND
RESULT = JD1 + JD2 + 9/24
FEND
FUNCTION Second(serial)
RESULT = REPLACE(FORMAT(INT(serial * 86400) MOD 60, 2), " ", "0")
FEND
PROCEDURE selectionSort(Var array[])
FOR n = 0 TO UBound(array)
DIM mini = n
FOR m = n + 1 TO UBound(array)
IFB array[m] < array[mini] THEN
mini = m
ENDIF
NEXT
swap(array[n], array[mini])
NEXT
FEND
FUNCTION serialToUNIX(serialTime)
RESULT = serialTime - 2209194000
FEND
FUNCTION serialToUwsc(serialDate)
RESULT = GETTIME(serialDate, "18991230000000")
FEND
PROCEDURE shakerSort(Var array[])
DIM topIndex = 0
DIM bottomIndex = UBound(array) - 1
WHILE TRUE
DIM lastSwapIndex = topIndex
FOR n = topIndex TO bottomIndex
IFB array[n] > array[n+1] THEN
swap(array[n], array[n+1])
lastSwapIndex = n
ENDIF
NEXT
bottomIndex = lastSwapIndex
IF topIndex = bottomIndex THEN BREAK
FOR n = bottomIndex TO topIndex + 1 STEP -1
IFB array[n] < array[n-1] THEN
swap(array[n], array[n-1])
lastSwapIndex = n
ENDIF
NEXT
topIndex = lastSwapIndex
IF topIndex = bottomIndex THEN BREAK
WEND
FEND
PROCEDURE shearSort(Var array[])
DIM num = UBound(array)
DIM rows = INT(SQRT(num))
DIM cols = (num + 1) / rows
FOR loop = 1 TO rows
// 行をグループ
FOR row = 1 TO rows
IFB row MOD 2 <> 0 THEN
// 奇数行目
REPEAT
DIM flg = FALSE
FOR col = 1 TO cols - 1
ofsRow = row - 1
ofsCol = col - 1
n = ofsRow * cols + ofsCol
IFB array[n] > array[n+1] THEN
swap(array[n], array[n+1])
flg = TRUE
ENDIF
NEXT
UNTIL !flg
ELSE
// 偶数行目
REPEAT
flg = FALSE
FOR col = 1 TO cols - 1
ofsRow = row - 1
ofsCol = col - 1
n = ofsRow * cols + ofsCol
IFB array[n] < array[n+1] THEN
swap(array[n], array[n+1])
flg = TRUE
ENDIF
NEXT
UNTIL !flg
ENDIF
NEXT
PRINT
// 列をグループ
FOR col = 1 TO cols
REPEAT
flg = FALSE
FOR row = 1 TO rows - 1
ofsRow = row - 1
ofsCol = col - 1
n = ofsRow * cols + ofsCol
IFB array[n] > array[n+cols] THEN
swap(array[n], array[n+cols])
flg = TRUE
ENDIF
NEXT
UNTIL !flg
NEXT
NEXT
FOR row = 1 TO rows
REPEAT
flg = FALSE
FOR col = 1 TO cols - 1
ofsRow = row - 1
ofsCol = col - 1
n = ofsRow * cols + ofsCol
IFB array[n] > array[n+1] THEN
swap(array[n], array[n+1])
flg = TRUE
ENDIF
NEXT
UNTIL !flg
NEXT
FEND
PROCEDURE shellSort(Var array[])
DIM i, j, inc, temp
inc = 4
WHILE INT(inc) > 0
FOR i = 0 TO UBound(array)
j = i
temp = array[i]
WHILE j >= inc AND array[zcut(j-inc)] > temp
array[j] = array[j-inc]
j = j - inc
WEND
array[j] = temp
NEXT
IFB inc / 2 <> 0 THEN
inc = inc / 2
ELSEIF inc = 1 THEN
inc = 0
ELSE
inc = 1
ENDIF
WEND
FEND
PROCEDURE showSubFolders(path)
DIM FSO = CREATEOLEOBJ("Scripting.FileSystemObject")
DIM Folder = FSO.GetFolder(path).SubFolders
FOR n = 0 TO GETOLEITEM(Folder) - 1
PRINT ALL_OLE_ITEM[n].Path
showSubFolders(ALL_OLE_ITEM[n].Path)
NEXT
FEND
FUNCTION SIGN(num)
SELECT TRUE
CASE !CHKNUM(num)
RESULT = ERR_VALUE
CASE num > 0
RESULT = 1
CASE num = 0
RESULT = 0
CASE num < 0
RESULT = -1
SELEND
FEND
FUNCTION SJISToJIS(SJIS)
DIM arr[1]
DIM res[1]
arr[0] = hexToDec(COPY(SJIS, 1, 2))
arr[1] = hexToDec(COPY(SJIS, 3, 2))
IFB arr[0] <= $9F THEN
arr[0] = arr[0] - $71
ELSE
arr[0] = arr[0] - $B1
ENDIF
arr[0] = arr[0] * 2 + 1
IF arr[1] >= $7F THEN arr[1] = arr[1] - 1
IFB arr[1] >= $9E THEN
arr[1] = arr[1] - $7D
arr[0] = arr[0] + 1
ELSE
arr[1] = arr[1] - $1F
ENDIF
res[0] = COPY("0" + decToHex(arr[0]), LENGTH("0" + decToHex(arr[0])) - 1)
res[1] = COPY("0" + decToHex(arr[1]), LENGTH("0" + decToHex(arr[1])) - 1)
RESULT = JOIN(res, "")
FEND
FUNCTION strRepeat(inputs, multiplier)
DIM res = ""
FOR n = 1 TO multiplier
res = res + inputs
NEXT
RESULT = res
FEND
FUNCTION strReplace(search, replace, subject)
SELECT VARTYPE(subject) AND $2000
CASE $2000
// 配列
FOR n = 0 TO UBound(subject)
subject[n] = REPLACE(subject[n], search, replace)
NEXT
RESULT = SLICE(subject)
DEFAULT
// 配列以外
RESULT = REPLACE(subject, search, replace)
SELEND
FEND
PROCEDURE swap(Var a, Var b)
DIM tmp = a
a = b
b = tmp
FEND
FUNCTION text(serial, format)
HASHTBL startDate
startDate["明治"] = "1868/01/25"
startDate["大正"] = "1912/07/30"
startDate["昭和"] = "1926/12/25"
startDate["平成"] = "1989/01/08"
startDate["令和"] = "2019/05/01"
DIM baseDate = "1899/12/30"
SELECT TRUE
CASE reTest(format, "\[h+\]")
Matches = reExecute(format, "\[(h+)\]")
RESULT = text(Hour(serial), strRepeat("0", LENGTH(Matches.Item(0).SubMatches(0))))
CASE reTest(format, "^h+$")
Matches = reExecute(format, "^(h+)$")
RESULT = text(Hour(serial) MOD 24, strRepeat("0", LENGTH(Matches.Item(0).SubMatches(0))))
CASE reTest(format, "\[m+\]")
Matches = reExecute(format, "\[(m+)\]")
RESULT = text(serial * 1440, strRepeat("0", LENGTH(Matches.Item(0).SubMatches(0))))
CASE format = "m"
GETTIME(serial, baseDate)
RESULT = text(G_TIME_MM, "0")
CASE format = "mm"
GETTIME(serial, baseDate)
RESULT = G_TIME_MM2
CASE format = "n"
GETTIME(serial, baseDate)
RESULT = G_TIME_NN
CASE format = "nn"
GETTIME(serial, baseDate)
RESULT = G_TIME_NN2
CASE format = "s"
GETTIME(serial, baseDate)
RESULT = text(G_TIME_SS, "0")
CASE format = "ss"
GETTIME(serial, baseDate)
RESULT = G_TIME_SS2
CASE format = "yyyy"
GETTIME(serial, baseDate)
RESULT = G_TIME_YY4
CASE format = "yy"
GETTIME(serial, baseDate)
RESULT = COPY(G_TIME_YY4, 3, 2)
CASE format = "e"
SELECT TRUE
CASE dateDiff("d", startDate["令和"], text(serial, "yyyy/mm/dd")) >= 0
RESULT = text(serial, "yyyy") - 2018
CASE dateDiff("d", startDate["平成"], text(serial, "yyyy/mm/dd")) >= 0
RESULT = text(serial, "yyyy") - 1988
CASE dateDiff("d", startDate["昭和"], text(serial, "yyyy/mm/dd")) >= 0
RESULT = text(serial, "yyyy") - 1925
CASE dateDiff("d", startDate["大正"], text(serial, "yyyy/mm/dd")) >= 0
RESULT = text(serial, "yyyy") - 1911
CASE dateDiff("d", startDate["明治"], text(serial, "yyyy/mm/dd")) >= 0
RESULT = text(serial, "yyyy") - 1867
SELEND
CASE format = "ee"
SELECT TRUE
CASE dateDiff("d", startDate["令和"], text(serial, "yyyy/mm/dd")) >= 0
RESULT = text(text(serial, "yyyy") - 2018, "00")
CASE dateDiff("d", startDate["平成"], text(serial, "yyyy/mm/dd")) >= 0
RESULT = text(text(serial, "yyyy") - 1988, "00")
CASE dateDiff("d", startDate["昭和"], text(serial, "yyyy/mm/dd")) >= 0
RESULT = text(text(serial, "yyyy") - 1925, "00")
CASE dateDiff("d", startDate["大正"], text(serial, "yyyy/mm/dd")) >= 0
RESULT = text(text(serial, "yyyy") - 1911, "00")
CASE dateDiff("d", startDate["明治"], text(serial, "yyyy/mm/dd")) >= 0
RESULT = text(text(serial, "yyyy") - 1867, "00")
SELEND
CASE format = "g"
SELECT TRUE
CASE dateDiff("d", startDate["令和"], text(serial, "yyyy/mm/dd")) >= 0; RESULT = "R"
CASE dateDiff("d", startDate["平成"], text(serial, "yyyy/mm/dd")) >= 0; RESULT = "H"
CASE dateDiff("d", startDate["昭和"], text(serial, "yyyy/mm/dd")) >= 0; RESULT = "S"
CASE dateDiff("d", startDate["大正"], text(serial, "yyyy/mm/dd")) >= 0; RESULT = "T"
CASE dateDiff("d", startDate["明治"], text(serial, "yyyy/mm/dd")) >= 0; RESULT = "M"
SELEND
CASE format = "gg"
RESULT = COPY(text(serial, "ggg"), 1, 1)
CASE format = "ggg"
SELECT TRUE
CASE dateDiff("d", startDate["令和"], text(serial, "yyyy/mm/dd")) >= 0; RESULT = "令和"
CASE dateDiff("d", startDate["平成"], text(serial, "yyyy/mm/dd")) >= 0; RESULT = "平成"
CASE dateDiff("d", startDate["昭和"], text(serial, "yyyy/mm/dd")) >= 0; RESULT = "昭和"
CASE dateDiff("d", startDate["大正"], text(serial, "yyyy/mm/dd")) >= 0; RESULT = "大正"
CASE dateDiff("d", startDate["明治"], text(serial, "yyyy/mm/dd")) >= 0; RESULT = "明治"
SELEND
CASE format = "mmmmm"
RESULT = COPY(text(serial, "mmmm"), 1, 1)
CASE format = "mmmm"
SELECT text(serial, "m")
CASE 1; RESULT = "January"
CASE 2; RESULT = "February"
CASE 3; RESULT = "March"
CASE 4; RESULT = "April"
CASE 5; RESULT = "May"
CASE 6; RESULT = "June"
CASE 7; RESULT = "July"
CASE 8; RESULT = "August"
CASE 9; RESULT = "September"
CASE 10; RESULT = "October"
CASE 11; RESULT = "November"
CASE 12; RESULT = "December"
SELEND
CASE format = "mmm"
RESULT = COPY(text(serial, "mmmm"), 1, 3)
CASE format = "dd"
GETTIME(serial, baseDate)
RESULT = text(G_TIME_DD2, "00")
CASE format = "d"
GETTIME(serial, baseDate)
RESULT = text(G_TIME_DD, "0")
CASE format = "aaaa"
GETTIME(serial, baseDate)
RESULT = getWeekdayName(G_TIME_WW, "aaaa")
CASE format = "aaa"
GETTIME(serial, baseDate)
RESULT = getWeekdayName(G_TIME_WW, "aaa")
CASE format = "dddd"
GETTIME(serial, baseDate)
RESULT = getWeekdayName(G_TIME_WW, "dddd")
CASE format = "ddd"
GETTIME(serial, baseDate)
RESULT = getWeekdayName(G_TIME_WW, "ddd")
CASE reTest(format, "(0+\.?0+)?%")
Matches = reExecute(format, "(0+\.?0+)?%")
RESULT = text(serial * 100, Matches.Item(0).SubMatches(0)) + "%"
CASE reTest(format, "^\[DBNum\d{1,4}\](.*?)$")
Matches = reExecute(format, "^\[DBNum(\d{1,4})\](.*?)$")
SELECT Matches.Item(0).SubMatches(0)
CASE 1
CASE 2
CASE 3
RESULT = STRCONV(text(serial, Matches.Item(0).SubMatches(1)), SC_FULLWIDTH)
CASE 4
SELEND
CASE reTest(format, "^(.*?)(AM\/PM|am\/pm|A\/P|a\/p)(.*?)$")
Matches = reExecute(format, "^(.*?)(AM\/PM|am\/pm|A\/P|a\/p)(.*?)$")
res = ""
WITH Matches.Item(0)
res = text(serial, .SubMatches(0)) + .SubMatches(1) + text(serial, .SubMatches(2))
ENDWITH
RESULT = res
CASE reTest(format, "([^ymdagehns]{0,})?(([ymdagehns])\3{0,})([^ymdagehns]+)?")
Matches = reExecute(format, "([^ymdagehns]{0,})?(([ymdagehns])\3{0,})([^ymdagehns]+)?")
FOR n = 0 TO Matches.Count - 1
IF n = 0 THEN res = Matches.Item(n).SubMatches(0)
NEXT
FOR n = 0 TO Matches.Count - 1
WITH Matches.Item(n)
res = res + text(serial, .SubMatches(1)) + .SubMatches(3)
ENDWITH
NEXT
RESULT = res
CASE reTest(format, "(0+)\.?(0+)?") AND UBound(SPLIT(format, ".")) <= 1
Matches = reExecute(format, "(0+)\.?(0+)?")
len1 = LENGTH(Matches.Item(0).SubMatches(0))
len2 = LENGTH(Matches.Item(0).SubMatches(1))
DIM arr[] = LENGTH(INT(serial)), len1
IFB POS(".", format) THEN
RESULT = REPLACE(FORMAT(serial, CALCARRAY(arr, CALC_MAX) + len2 + 1, len2), " ", "0")
ELSE
RESULT = REPLACE(FORMAT(serial, CALCARRAY(arr, CALC_MAX)), " ", "0")
ENDIF
SELEND
FEND
FUNCTION timeValue(str)
HASHTBL Pattern
Pattern["hour"] = "(1[0-9]|2[0-4]|0?[0-9])"
Pattern["minute"] = "([1-5][0-9]|60|0?[0-9])"
pattern["second"] = "([1-5][0-9]|60|0?[0-9])"
SELECT TRUE
CASE reTest(str, Pattern["hour"] + ":" + Pattern["minute"] + ":" + pattern["second"] + " (AM|PM)")
Matches = reExecute(str, Pattern["hour"] + ":" + Pattern["minute"] + ":" + pattern["second"] + " (AM|PM)")
WITH Matches.Item(0)
SELECT .SubMatches(3)
CASE "AM"
time = (.SubMatches(0) / 24) + (.SubMatches(1) / 1440) + (.SubMatches(2) / 86400)
CASE "PM"
time = ((.SubMatches(0) + 12) / 24) + (.SubMatches(1) / 1440) + (.SubMatches(2) / 86400)
SELEND
ENDWITH
CASE reTest(str, Pattern["hour"] + ":" + Pattern["minute"] + ":" + pattern["second"])
Matches = reExecute(str, Pattern["hour"] + ":" + Pattern["minute"] + ":" + pattern["second"])
WITH Matches.Item(0)
time = (.SubMatches(0) / 24) + (.SubMatches(1) / 1440) + (.SubMatches(2) / 86400)
ENDWITH
SELEND
RESULT = time
FEND
FUNCTION today()
GETTIME()
RESULT = G_TIME_YY4 + "/" + G_TIME_MM2 + "/" + G_TIME_DD2
FEND
PROCEDURE tweet(msg)
IE = CREATEOLEOBJ("InternetExplorer.Application")
IE.Visible = TRUE
IE.Navigate("https://twitter.com")
BusyWait(IE)
TRY
obj = IE.document.getElementsByClassName("name")
username = obj.Item(0).innerText
EXCEPT
IE.Navigate("https://twitter.com/login?lang=ja")
BusyWait(IE)
IESETDATA(IE, "電話番号/メールアドレス/ユーザー名", "session[username_or_email]", EMPTYPARAM, 2)
IESETDATA(IE, "パスワード", "session[password]", EMPTYPARAM, 2)
IE.document.forms[2].submit()
BusyWait(IE)
ENDTRY
text = ENCODE(ENCODE(msg, CODE_UTF8), CODE_URL)
IE.Navigate("https://twitter.com/intent/tweet?text=" + text)
BusyWait(IE)
TRY
IE.document.forms[1].submit()
EXCEPT
ENDTRY
BusyWait(IE)
IFB IE.document.title = "ツイートが投稿されました" THEN
PRINT "ツイート完了"
ELSE
PRINT "ツイート失敗"
ENDIF
IE.Quit
FEND
FUNCTION UBound(array[])
RESULT = RESIZE(array)
FEND
FUNCTION uniqueFilename(path)
DIM FSO = CREATEOLEOBJ("Scripting.FileSystemObject")
IFB FSO.FileExists(path) THEN
DIM fol = FSO.GetParentFolderName(path)
DIM filename = FSO.GetBaseName(path)
DIM extension = FSO.GetExtensionName(path)
DIM i = 2
WHILE FSO.FileExists(FSO.BuildPath(fol, filename + " (" + i + ")." + extension))
i = i + 1
WEND
RESULT = FSO.BuildPath(fol, filename + " (" + i + ")." + extension)
ELSE
RESULT = path
ENDIF
FEND
FUNCTION UNIXToSerial(unixTime)
RESULT = (unixTime + 2209194000) / 86400
FEND
FUNCTION UNIXToUwsc(unixTime)
//秒から日に単位変換
unixDate = unixTime / 86400
RESULT = GETTIME(unixDate , "1970/01/01 09:00:00")
FEND
FUNCTION uwscToSerial(uwscTime)
uwscDate = uwscTime / 86400
RESULT = 36526 + uwscDate
FEND
FUNCTION uwscToUNIX(uwscTime)
uwscDate = uwscTime / 86400
RESULT = (GETTIME(uwscDate) - GETTIME(uwscDate, "1970/01/01 09:00:00"))
FEND
MODULE WordFunction
FUNCTION rand(paragraph, num)
DIM sentences[] = "[挿入] タブのギャラリーには、文書全体の体裁に合わせて調整するためのアイテムが含まれています。", + _
"これらのギャラリーを使用して、表、ヘッダー、フッター、リスト、表紙や、その他の文書パーツを挿入できます。", + _
"図、グラフ、図表を作成すると、文書の現在の体裁に合わせて調整されます。", + _
"文書で選択した文字列の書式は、[ホーム] タブのクイック スタイル ギャラリーで体裁を選択することで簡単に変更できます。", + _
"[ホーム] タブの他のボタンやオプションを使用して、文字列に書式を直接設定することもできます。", + _
"ほとんどのボタンやオプションで、現在のテーマの体裁を使用するか、直接指定する書式を使用するかを選択できます。", + _
"文書全体の体裁を変更するには、[ページ レイアウト] タブで新しいテーマを選択します。", + _
"クイック スタイル ギャラリーに登録されている体裁を変更するには、現在のクイック スタイル セットを変更するコマンドを使用します。", + _
"テーマ ギャラリーとクイック スタイル ギャラリーにはリセット コマンドが用意されており、文書の体裁を現在のテンプレートの元の体裁にいつでも戻すことができます。"
DIM res = ""
FOR n = 0 TO paragraph * num - 1
res = res + sentences[n MOD (UBound(sentences) + 1)]
IF (n + 1) MOD num = 0 THEN res = res + "<#CR>"
NEXT
RESULT = TRIM(res)
FEND
FUNCTION rand.old(num)
DIM sentence = "Word 2003 は、画期的な日本語入力・編集環境を実現した日本語ワープロです。"
DIM res = ""
FOR n = 1 TO num
res = res + sentence + sentence + sentence + "<#CR>"
NEXT
RESULT = TRIM(res)
FEND
FUNCTION lorem(paragraph, num)
DIM sentences[] = "Lorem ipsum dolor sit amet, consectetuer adipiscing elit.", + _
"Maecenas porttitor congue massa.", + _
"Fusce posuere, magna sed pulvinar ultricies, purus lectus malesuada libero, sit amet commodo magna eros quis urna.", + _
"Nunc viverra imperdiet enim.", + _
"Fusce est.", + _
"Vivamus a tellus.", + _
"Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas.", + _
"Proin pharetra nonummy pede.", + _
"Mauris et orci.", + _
"Aenean nec lorem.", + _
"In porttitor.", + _
"Donec laoreet nonummy augue.", + _
"Suspendisse dui purus, scelerisque at, vulputate vitae, pretium mattis, nunc.", + _
"Mauris eget neque at sem venenatis eleifend.", + _
"Ut nonummy.", + _
"Fusce aliquet pede non pede.", + _
"Suspendisse dapibus lorem pellentesque magna.", + _
"Integer nulla.", + _
"Donec blandit feugiat ligula.", + _
"Donec hendrerit, felis et imperdiet euismod, purus ipsum pretium metus, in lacinia nulla nisl eget sapien.", + _
"Donec ut est in lectus consequat consequat.", + _
"Etiam eget dui.", + _
"Aliquam erat volutpat.", + _
"Sed at lorem in nunc porta tristique.", + _
"Proin nec augue.", + _
"Quisque aliquam tempor magna.", + _
"Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas.", + _
"Nunc ac magna.", + _
"Maecenas odio dolor, vulputate vel, auctor ac, accumsan id, felis.", + _
"Pellentesque cursus sagittis felis.", + _
"Pellentesque porttitor, velit lacinia egestas auctor, diam eros tempus arcu, nec vulputate augue magna vel risus.", + _
"Cras non magna vel ante adipiscing rhoncus.", + _
"Vivamus a mi.", + _
"Morbi neque.", + _
"Aliquam erat volutpat.", + _
"Integer ultrices lobortis eros.", + _
"Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas.", + _
"Proin semper, ante vitae sollicitudin posuere, metus quam iaculis nibh, vitae scelerisque nunc massa eget pede.", + _
"Sed velit urna, interdum vel, ultricies vel, faucibus at, quam.", + _
"Donec elit est, consectetuer eget, consequat quis, tempus quis, wisi.", + _
"In in nunc.", + _
"Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos hymenaeos.", + _
"Donec ullamcorper fringilla eros.", + _
"Fusce in sapien eu purus dapibus commodo.", + _
"Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus.", + _
"Cras faucibus condimentum odio.", + _
"Sed ac ligula.", + _
"Aliquam at eros.", + _
"Etiam at ligula et tellus ullamcorper ultrices.", + _
"In fermentum, lorem non cursus porttitor, diam urna accumsan lacus, sed interdum wisi nibh nec nisl.", + _
"Ut tincidunt volutpat urna.", + _
"Mauris eleifend nulla eget mauris.", + _
"Sed cursus quam id felis.", + _
"Curabitur posuere quam vel nibh.", + _
"Cras dapibus dapibus nisl.", + _
"Vestibulum quis dolor a felis congue vehicula.", + _
"Maecenas pede purus, tristique ac, tempus eget, egestas quis, mauris.", + _
"Curabitur non eros.", + _
"Nullam hendrerit bibendum justo.", + _
"Fusce iaculis, est quis lacinia pretium, pede metus molestie lacus, at gravida wisi ante at libero.", + _
"Quisque ornare placerat risus.", + _
"Ut molestie magna at mi.", + _
"Integer aliquet mauris et nibh.", + _
"Ut mattis ligula posuere velit.", + _
"Nunc sagittis.", + _
"Curabitur varius fringilla nisl.", + _
"Duis pretium mi euismod erat.", + _
"Maecenas id augue.", + _
"Nam vulputate.", + _
"Duis a quam non neque lobortis malesuada.", + _
"Praesent euismod.", + _
"Donec nulla augue, venenatis scelerisque, dapibus a, consequat at, leo.", + _
"Pellentesque libero lectus, tristique ac, consectetuer sit amet, imperdiet ut, justo.", + _
"Sed aliquam odio vitae tortor.", + _
"Proin hendrerit tempus arcu.", + _
"In hac habitasse platea dictumst.", + _
"Suspendisse potenti.", + _
"Vivamus vitae massa adipiscing est lacinia sodales.", + _
"Donec metus massa, mollis vel, tempus placerat, vestibulum condimentum, ligula.", + _
"Nunc lacus metus, posuere eget, lacinia eu, varius quis, libero.", + _
"Aliquam nonummy adipiscing augue."
DIM res = ""
FOR n = 0 TO paragraph * num - 1
res = res + sentences[n MOD (UBound(sentences) + 1)]
IF (n + 1) MOD num = 0 THEN res = res + "<#CR>"
NEXT
RESULT = TRIM(res)
FEND
ENDMODULE
FUNCTION xlCODE(str)
DIM Excel = CREATEOLEOBJ("Excel.Application")
RESULT = Excel.Evaluate("CODE(<#DBL>" + str + "<#DBL>)")
FEND
FUNCTION xlTEXT(num, format)
DIM Excel = CREATEOLEOBJ("Excel.Application")
RESULT = Excel.Evaluate("TEXT(<#DBL>" + num + "<#DBL>, <#DBL>" + format + "<#DBL>)")
FEND
FUNCTION YMDToJD(year, month, day, hour = 0, minute = 0, second = 0)
IFB month < 3 THEN
year = year - 1
month = month + 12
ENDIF
DIM JD = INT(year * 365.25)
JD = JD + INT(year / 400)
JD = JD - INT(year / 100)
JD = JD + INT((month - 2) * 30.59)
JD = JD + 1721088
JD = JD + day
DIM t = second / 3600
t = t + minute / 60
t = t + hour
t = t / 24
JD = JD + t
RESULT = JD
FEND
この記事は役に立ちましたか?