汎用機メモっとくか

しごと用の(学習メモ&お気に入り保存)。

わり算02

2023年03月30日 19時16分32秒 | WSH

0割対応は自分でいれてください

試験中

a="7586538575621427759";
lena=a.length;

b='123456789012345';
lenb=b.length;

c=0;
d='';

b01=b.substr(lenb-14,14);
b021="00000000000000" + b.substr(0,lenb-14);
lenb021 = b021.length;
b02= b021.substr(lenb021-14,14);
b05=b02+b01;


posa=0;
a00='';


a00=a00 + a.substr(posa,1);
lena00 = a00.length;
a051 = "0000000000000000000000000000" + a00;
lena051 = a051.length;
a05  = a051.substr(lena051-28,28);


while(posa    lena){
  c=0;
  while(a05 >= b05){
      c++;
      a01=a05.substr(14,14);
      
      if(lena00>14){
         a02=a05.substr(0,14);
      }else{
         a02=0;
      }
      if(a01*1.0     b01*1.0){
       
        a03n1 = 100000000000000 + (a01*1.0);
        a03n2 = (a02*1.0) - 1;       
      }else{
        a03n1 = a01 * 1.0;
        a03n2 = a02 * 1.0;
      }

      a03n1 = a03n1 - (b01 * 1.0);
      a03n2 = a03n2 - (b02 * 1.0);

      if(a03n2 = 0){
        a04 =  "00000000000000" + a03n1;
        lena04 = a04.length;
        a00 = a04.substr(lena04-14,14)
      }else{
        a00 = a03n2 + '';
        a04 = "00000000000000" + a03n1;
        lena04 = a04.length;
        a00 = a00 + a04.substr(lena04 - 14,14);
      }
      lena00 = a00.length;
      a051 = "0000000000000000000000000000" + a00;
      lena051 = a051.length;
      a05  = a051.substr(lena051-28,28);
  }
  posa++;
  a00 = a00 + a.substr(posa,1);
  lena00 = a00.length
  a051 = "0000000000000000000000000000" + a00;
  lena051 = a051.length;
  a05  = a051.substr(lena051-28,28)  


  d = d + '' + c;
}

 

alert(d);


わり算01

2023年03月27日 16時03分10秒 | WSH

0割対応は自分でいれてください

 

被除数は、整数

除数は、14桁整数まで

 

<javascript>

a=76543210987654321;
lena=(a+'').length;
b=87;
lenb=(b+'').length;
c=0;
d='';
posa=0;

a02='';
a02=(a+'').substr(posa,1);


c=0;
a03='';

 

while(posalena){
    c=0;
    if(a02 * 1.0 >= b){
      while(a02 * 1.0 >= b){
         c++;
         a02 = a02 * 1.0 - b;

      }
    }
    
    posa++;
    a02=a02+(a+'').substr(posa,1);
    
    d=d+''+c;
}
alert(d);

 

 

<vbscript>


   dim  data
   dim  data01
   
   dim jyo
   dim jyo_dbl(10)
   dim jyo_stra (10)
 
   
  data = "87654321"
  jyo   =  87

  len_data = Len(data)

 c = 0
 d = 0
 posa = 1
 
 a02 = ""
 a02 = Mid(data,posa,1)

 Do Until (posa > len_data)
    c = 0
    If Cdbl(a02) >= jyo Then
        Do While Cdbl(a02) >= jyo
            c = c + 1
            a02  = Cdbl(a02) - jyo
        Loop
    End If 
    posa = posa + 1
    a02  = Cstr(a02) & Mid(data, posa, 1)

    d = d & c
 Loop

 Msgbox d

 

 

<記事とは無関係>

1..10|&{begin{$a="abc";$c=0}process{$c=$c+$_;echo ($a+$_)}end{echo (" sum=" + $c)}}

 

<awk>

BEGIN{
a=76543210987654321;
lena=length(a);
b=87;
lenb=length(b);

posa=1;

a02="";
a02=substr(a, posa, 1);


c=0;
d="";
 

while(posa*1.0 < lena*1.0){
    c=0;
    if(a02 * 1.0 >= b*1.0){
      while(a02 * 1.0 >= b){
         c++;
         a02 = a02 * 1.0 - b;
         print a02

      }
    }
    
    posa++;
    a02=a02 substr(a, posa, 1);
    print a02
    d= d "" c;
}
print d;
}


LibreOfficeマクロ雑記

2021年12月05日 09時23分59秒 | OOoCalcBasic

Libre Office version 5.4.1.2 で下記をトライ。

Main01 は動く
Main02 は put  で
 Basicランタイムエラー
 デバイスI/O エラー
になる。

最新version で試す必要あり。

REM  *****  BASI          C  *****

Type putInt

         tstInt( 2999 ) As  Integer
End Type

Sub Main01
    Dim fileName As String
    
    Dim fileNO    As Integer
    
    Dim tstInt(2)  As  Integer
    tstInt(0)   =    0
    tstInt(1)   =    255
    tstInt(2)   =    -1
    fileName = "C:\Users\user\desktop\libre01.dat"
    fileNO    =  FreeFile()
    
    Open  fileName For Random As fileNO
    Put  #fileNO,   , tstInt(0)
    Put  #fileNO,   , tstInt(1)
    Put  #fileNO,   , tstInt(2)
    Close fileNO
    Msgbox "owari"

End Sub

 

REM  *****  BASIC  *****

Sub Main02
    Dim fileName As String
    Dim fileNO    As Integer
    Dim  ix      As  Long
    Dim  iy     As  Long
    Dim  testInt(4)  As  New putInt    

    For   ix =  0  To  4
        For  iy  =  0  To  2999
            testInt( ix ).tstInt( iy )   =  Int(   Rnd()  *  65536 )   - 32768
        Next
    Next
    
    fileName = "C:\Users\user\desktop\libre100M.bin"
    fileNO    =  FreeFile()
    
    Open  fileName For Random As fileNO
    
    Dim   iz   As  Long
    Dim   px  As  Long
 
    
    For   iz   =   1  To   100
        px   =   Int(  Rnd()  *  5 )   
        Put  #fileNO,   ,  testInt(  px  )
    Next
    Msgbox "owari"

    Close fileNO
End Sub

<20211208STA> Libre Office version 5.4.1.2 でなんとか動かす


Sub Main02_00
    Dim fileName As String
    Dim fileNO    As Integer
    Dim  ix      As  Long
    Dim  iy     As  Long
    Dim  testInt                   As   Integer    
    ' 32768 >   30000  =  ( 14999 + 1 ) * 2
    Dim  putInt00(    14999)  As   Integer
    Dim  putInt01(    14999)  As   Integer
    Dim  putInt02(    14999)  As   Integer
    Dim  putInt03(    14999)  As   Integer
    Dim  putInt04(    14999)  As   Integer    
    
    Dim  Max                       As   Integer
    Max  = 14999
    For   ix =  0  To  4
        For  iy  =  0  To  Max
            testInt  =  Int(   Rnd()  *  65536 )   - 32768
            Select   Case  ix
                Case  0    
                    'PUT  MAX  32768BYTE 
                    putInt00(  iy  )  =  testInt
                Case  1
                    putInt01(  iy  )  =  testInt 
                Case  2
                    putInt02(  iy  )  =  testInt
                Case  3 
                    putInt03(  iy  )  =  testInt
                Case  4 
                    putInt04(  iy  )   =  testInt
            End  Select    
        Next
    Next
    
    fileName = "C:\User\user\desktop\libre02_00_100M.bin"
    fileNO    =  FreeFile  
    Open  fileName For  Binary   As   fileNO
    
    Dim   iz   As  Long
    Dim   px  As  Long
 
    Msgbox "書きます"
    For   iz   =   1  To   1000
           px   =   Int(  Rnd()  *  5 )
           Select   Case  px
                Case  0    
                    Put  #fileNO,   , putInt00
                Case  1
                    Put  #fileNO,   , putInt01
                Case  2
                    Put  #fileNO,   , putInt02
                Case  3 
                    Put  #fileNO,   , putInt03
                Case  4 
                    Put  #fileNO,   , putInt04
            End  Select
    Next
    
    
     Close fileNO
     Msgbox "owari"

End Sub

<20211208END>

Excel2013 構造体64kbの壁あり

Type putInt

         tstInt(29999) As Integer
End Type


 

Rem  *****  BASIC  *****

Sub abcdeMain02()
    Dim fileName As String
    Dim fileNO    As Integer
    Dim ix       As Long
    Dim iy      As Long
    Dim testInt(4)   As putInt

    For ix = 0 To 4
        For iy = 0 To 29999
            testInt(ix).tstInt(iy) = Int(Rnd() * 65536) - 32768
        Next
    Next
    
    fileName = "C:\Users\user\desktop\libre100M.bin"
    fileNO = FreeFile()
    
    Open fileName For Binary As fileNO
    
    Dim iz     As Long
    Dim px    As Long
 
    
    For iz = 1 To 100
        px = Int(Rnd() * 5)
        Put #fileNO, , testInt(px)
    Next
    
    Close fileNO
    
    MsgBox "owari"

End Sub

 

 


JScript でInputBoxを使う2

2020年07月19日 22時48分59秒 | WSH

JScript でInputBoxを使う2

”Windows Script Programming”様より
バッチファイルからMsgBox()を使う。
http://scripting.cocolog-nifty.com/blog/2009/06/msgbox-c3bc.html

使えるかどうかは、別にして、inputboxを実行してみる
MSHTA.EXE vbscript:Execute("Set oFS=CreateObject(""Scripting.FileSystemObject""):Set oTxt=oFS.CreateTextFile(""C:\Users\usr\Desktop\temp.inputbox.tmp""):oTxt.WriteLine(InputBox(""aaa"",""bbb"",""ccc"")):oTxt.Close:close")

動くので次。
<test02.js>
//test02.js

var oWshShell = new ActiveXObject("WScript.Shell");
var myParm = new String;

myParm   =  "MSHTA.EXE vbscript:Execute(" +
             "\"Set oFS=CreateObject(\"\"Scripting.FileSystemObject\"\"):" +
             "Set oTxt=oFS.CreateTextFile(\"\"C:\\Users\\usr\\Desktop\\temp.inputbox.tmp\"\"):" +
             "oTxt.WriteLine(InputBox(\"\"aaa\"\",\"\"bbb\"\",\"\"ccc\"\")):" +
             "oTxt.Close:close\"" +
             ")";
 
  res01 = "wait";
  res01 =  oWshShell.Run(myParm , 1,true);

  
    //res01 = 0;
    while(res01 == "wait"){
      WScript.Sleep(1000);
    }
    var pFS  = new ActiveXObject("Scripting.FileSystemObject");
    var pTxt = pFS.OpenTextFile("C:\\Users\\usr\\Desktop\\temp.inputbox.tmp");
    myText   = pTxt.ReadAll();

    WScript.Echo(myText);
    pTxt.Close();

 


JScript でInputBoxを使う(Excel有りの環境下にて)

2019年11月23日 08時44分52秒 | WSH

<sample01.js>
var oExcel = new ActiveXObject("Excel.Application");
var target_file = oExcel.GetOpenFilename("読み込み (*.*),*");
var a01 = oExcel.InputBox("prompt","Title","Default");
oExcel.Quit();
delete oExcel;
WScript.Echo(target_file);
WScript.Echo(a01);

 


その他のやり方1
<sample02.bat>.BATにして動かす
@if(0)==(0) ECHO OFF
C:\Windows\SysWOW64\WScript.exe //NoLogo //E:JScript "%~f0" %1
GOTO :EOF
@end
var nVBS = new ActiveXObject("ScriptControl");
    nVBS.Language = "VBScript";
    nVBS.AddCode("Function func_msgbox(a01) " + "\n" +
                 " func_msgbox = MsgBox(a01)" + "\n" +
                 "End Function " + "\n" +
        "Function func_inputbox(prompt,title,default) " + "\n" +
        " func_inputbox = inputBox(prompt,title,default)" + "\n" +
        "End Function");
var oVBS = nVBS.CodeObject;
WScript.Echo(oVBS.func_msgbox("aaaaa"));
WScript.Echo(oVBS.func_inputbox("Prompt","Title","Default"));