HASH

方法一:使用fileOpen、fileGet、filePut、fileClose

 ‘先定義資料結構
 Structure RowOBS04
        Dim TDATE As String     ‘交易日期
        Dim ITEM_ID As String   ‘貨品代碼
        Dim KIND_ID As String   ‘品種代碼
        Dim ITEM_NAME As String ‘貨品名稱
        Dim KIND_NAME As String ‘品種名稱
        Dim ITEM_CAT As String  ‘產品分類
        Dim KIND_CAT As String  ‘品種分類
    End Structure

 sub GETDATA()
  Dim Cusdat As RowOBS04
        Dim fileNumber As Integer = FreeFile()

        FileOpen(fileNumber, fileName, OpenMode.Random)
        FileGet(fileNumber, Cusdat, CInt(TextBox1.Text))
        FileClose(fileNumber)
  
  TextBox2.Text = Cusdat.TDATE
        TextBox3.Text = Cusdat.ITEM_ID
        TextBox4.Text = Cusdat.KIND_ID
        TextBox5.Text = Cusdat.ITEM_NAME
        TextBox6.Text = Cusdat.KIND_NAME
        TextBox7.Text = Cusdat.ITEM_CAT
        TextBox8.Text = Cusdat.KIND_CAT
 end sub
 
 sub SETDATA()
  Dim Cusdat As RowOBS04
        Dim fileNumber As Integer = FreeFile()

        FileOpen(fileNumber, fileName, OpenMode.Random)

        ‘UPDATE資料
        Cusdat.TDATE = TextBox2.Text
        Cusdat.ITEM_ID = TextBox3.Text
        Cusdat.KIND_ID = TextBox4.Text
        Cusdat.ITEM_NAME = TextBox5.Text
        Cusdat.KIND_NAME = TextBox6.Text
        Cusdat.ITEM_CAT = TextBox7.Text
        Cusdat.KIND_CAT = TextBox8.Text
        FilePut(fileNumber, Cusdat, CInt(TextBox1.Text))
        FileClose(fileNumber)
 end sub

方法二:system.io.file

1.定義一筆RecordLen

2.計算位置=(筆數-1)*RecordLen

3.三種方式[適情況而定]
(1)索引條件為數字,且知道數字不大

==================
item_id | item_Name | kind
0070     
0071
  .
  .
  .
9999
====================
以上這種情況,可以用數字直接作索引條件,71塞到71的位置,73塞到73的位置,如72沒資料就留一筆RecordLen空白

(2)索引條件為數字,但數字大
建索引(也是一個文字檔)
no為item_id除某一質數的餘數
record_no為實際位置
==========================
[餘數出現重覆情況則放後面,如超過預計放置筆數,則用FLAG記錄之後從哪個NO開始]
no | item_id | record_no | item_id | record_no | item_id | record_no | flag
1  0000070 1     
2  0000071 2
 .
 .
 .
100  0071000     20000
 .
 .
 .
==========================

(3)索引條件不一定為數字
如出現字母,則可把字母排除,或把字母轉為數字來進行INDEX

Property的寫法

ms-help://MS.VSCC.v80/MS.MSDN.v80/MS.VisualStudio.v80.cht/dv_vbalr/html/3155edaf-8ebd-45c6-9cef-11d5d2dc8d38.htm

Class Class1
	'Define a local variable to store the property value.
	Private propertyValue As String
	'Define the property.
	Public Property prop1() As String
		Get
		'The Get property procedure is called when the value
		'of a property is retrieved.
		Return propertyValue
		End Get
		Set(ByVal value As String)
		'The Set property procedure is called when the value
		'of a property is modified. The value to be assigned
		'is passed in the argument to Set.
		propertyValue = value
		End Set
	End Property
End Class

Structure的寫法

ms-help://MS.VSCC.v80/MS.MSDN.v80/MS.VisualStudio.v80.cht/dv_vbalr/html/9bd1deea-2a89-4cdc-812c-6dcbb947c391.htm

Public Structure employee
    'Public members, accessible from throughout declaration region.
    Public firstName As String
    Public middleName As String
    Public lastName As String
    'Friend members, accessible from anywhere within the same assembly.
    Friend employeeNumber As Integer
    Friend workPhone As Long
    'Private members, accessible only from within the structure itself.
    Private homePhone As Long
    Private level As Integer
    Private salary As Double
    Private bonus As Double
    'Procedure member, which can access structure’s private members.
    Friend Sub calculateBonus(ByVal rate As Single)
        bonus = salary * CDbl(rate)
    End Sub
    'Property member to return employee’s eligibility.
    Friend ReadOnly Property eligible() As Boolean
        Get
            Return level >= 25
        End Get
    End Property
    'Event member, raised when business phone number has changed.
    Public Event changedWorkPhone(ByVal newPhone As Long)
End Structure

Timer的用法

sub main()
    Dim Timer1 As New System.Timers.Timer
    AddHandler Timer1.Elapsed, New System.Timers.ElapsedEventHandler(AddressOf Timer1_Elapsed)
Timer1.Interval = 10000
    Timer1.Enabled = True
    Timer1.AutoReset = False
End Sub
Private Sub Timer1_Elapsed(ByVal sender As System.Object, ByVal e As System.Timers.ElapsedEventArgs)
    MsgBox(”OK”)
End Sub

用表單名開啟FORM

Public Function OpenForm(ByVal FormName As String) As Form
    Dim mainAssembly As System.Reflection.Assembly = & _
        System.Reflection.Assembly.GetExecutingAssembly
    Dim objNewForm As Object = & _
        Activator.CreateInstance(Type.GetType(mainAssembly.GetName.Name + "." + FormName))
    Return DirectCast(objNewForm, Form)
End Function