文字檔轉隨機檔
將文字檔(classmate.csv)轉成隨機檔
一般模組
Structure info
<vbFixedString (6)> Dim Dept As String
Dim Grade As
byte
Dim
No As long
<vbFixedString (6)> Dim Name As String
<vbFixedString
(8)> Dim Picture As
String
End Structure
Public classmate as info '宣告為公用變數
表單模組
Private Sub Button1_Click( )
FileOpen(1,
"c:\classmate.csv", OpenMode.Input)FileOpen(2,
"c:\classmate.dat", OpenMode.Random, , , Len(Classmate))
Do While Not EOF(1)
Input(1, Classmate.Dept)
Input(1, Classmate.Grade)
Input(1, Classmate.No)
Input(1, Classmate.Name)
Input(1, Classmate.Picture)
FilePut(2, classmate)
Loop
FileClose ()
End Sub
以上程式執行完,確定轉檔無誤後,即將此按鈕Enabled屬性關掉,以免造成後續程式執行!
以選單查詢
Private Sub Form_Load()
Dim i as integer
FileOpen (1, "c:\classmate.dat", OpenMode.Random , , , Len(classmate))
For i = 1 To LOF(1) / Len(classmate)
FileGet (1,
classmate)
ComboBox1.Items.Add classmate.Name '將姓名加入拉下式選單中
Next
End Sub
Dim i As Integer
For i = 0 To ComboBox1.Items.Count - 1
If ComboBox1.SelectedIndex = i Then
FileGet(1, Classmate, i + 1)
TextBox1.Text = Classmate.No
TextBox2.Text = Classmate.Dept
TextBox3.Text = Classmate.Grade
End If
NextEnd Sub
以選單查詢(加入相片)
下載圖片
pig bean
Private Sub Combo1_Click()
Dim i as integer
Dim bmp As Bitmap
If ComboBox1.SelectedIndex = i Then
FileGet(1, Classmate, i + 1)
TextBox1.Text = Classmate.No
TextBox2.Text = Classmate.Dept
TextBox3.Text = Classmate.Grade
bmp =
New Bitmap("c:\" & Classmate.Picture)PictureBox1.Image = bmp
End If
Next
End sub