目次

在庫管理

 spreadsheetは、小規模なデータベース機能をもっています。

 データベース機能を利用して、手持ちの
 電子回路で使う部品の在庫管理をして
 みました。

 どんな電子部品をストックしているのかと
 調べてみると、次のようになってます。

 TTLゲートIC



 74HCシリーズIC



 CMOS_IC



 OPアンプ



 他に抵抗、キャパシタ、インダクタetcがあります。

 シート1枚に、1種の部品を割り当てて管理。



 74HCシリーズICの場合、次のように手持ちのICを
 分類して、個数を入力していきます。

 型番、機能、特記事項をA列、B列、C列に記入し
 D列に在庫量を入れます。

 入手店舗と単価も必要ならば、別の列に
 記入しておけば、個人が活用できる最高
 のデータベースになるでしょう。

 半期、年間で、どれだけのICを使ったのか
 それは、どのICであったのか等の統計資料
 を作成することも可能。

 入庫、出庫のいずれかがあれば
 在庫量を再度計算するマクロを
 作成します。

 基本は、D列の値は、E列とF列の差分を
 求めて代入するだけでよいはず。

Dim objS As Object

Dim i  As Byte

Dim xtmp As Byte
Dim tmpa As Byte
Dim tmpb As Byte

' set object pointer
objS = ThisComponent.CurrentController.ActiveSheet

' vertical scan
For i = 1 to 19
  ' set pointer
  ptr  = objS.getCellByPosition(3,i)
  ptrA = objS.getCellByPosition(4,i)
  ptrB = objS.getCellByPosition(5,i)
  ' get value
  tmpa = ptrA.Value
  tmpb = ptrB.Value
  ' calculate 
  xtmp = tmpa - tmpb
  ' store
  ptr.Value = xtmp
Next i

 この操作を、全シートにわたって処理すればよいので
 シート番号をスキャンするようにループを組みます。

Sub ReCalc()
  Dim i As Byte
  Dim j As Byte

  Dim xtmp As Byte
  Dim tmpa As Byte
  Dim tmpb As Byte

  ' sheet scan
  For j = 0 to 5
    ' vertical scan
    For i = 1 to 19
      ' set pointer
      ptr  = ThisComponent.Sheets(j).getCellByPosition(3,i)
      ptrA = ThisComponent.Sheets(j).getCellByPosition(4,i)
      ptrB = ThisComponent.Sheets(j).getCellByPosition(5,i)
      ' get value
      tmpa = ptrA.Value
      tmpb = ptrB.Value
      ' calculate 
      xtmp = tmpa - tmpb
      ' store
      ptr.Value = xtmp
    Next i
  Next j
End Sub

 spreadsheetは、自動計算するのが基本なので
 次の式を、シートのC列に入れることでも可能。

C列 =D2-E2

 ひとつのシートで扱う項目が増えるたびに
 copy & paste する方が面倒と考え、マクロ
 にしています。

 シートごとに、処理する行の数が異なるので
 I列に処理する行数を格納して対応する仕様
 に変更。

 I2に、行数が含まれているとすれば、次の
 マクロで対応可能。

Sub ReCalc()
  Dim i As Byte
  Dim j As Byte
  Dim last As Byte

  Dim xtmp As Byte
  Dim tmpa As Byte
  Dim tmpb As Byte

  ' sheet scan
  For j = 0 to 5
    ' get counter
    last = ThisComponent.Sheets(j).getCellByPosition(8,1).Value
    ' vertical scan
    For i = 1 to last
      ' default
      xtmp = 0
      ' set pointer
      ptr  = ThisComponent.Sheets(j).getCellByPosition(3,i)
      ptrA = ThisComponent.Sheets(j).getCellByPosition(4,i)
      ptrB = ThisComponent.Sheets(j).getCellByPosition(5,i)
      ' get value
      tmpa = ptrA.Value
      tmpb = ptrB.Value
      ' judge
      If tmpa >= tmpb Then
        ' calculate 
        xtmp = tmpa - tmpb
      Else
        MsgBox(str(i)+": Anything worng !")
      End If
      ' store
      ptr.Value = xtmp
    Next i
  Next j
End Sub

 在庫数が0より小さいことは、ありえないので
 入庫と出庫の量を比較して対応しました。


目次

inserted by FC2 system