熱點推薦:
您现在的位置: 電腦知識網 >> 編程 >> .NET編程 >> 正文

實用技術之用VB做通訊錄

2022-06-13   來源: .NET編程 

    如果你平時有許多同學和朋友的信息試試在電腦上編寫一個我這樣的通訊錄很方便的喲  
 先新建一個工程工具箱>右鍵>部件添加Microsoft windows common contr ol 然後在窗體上添加五個標簽標題分別為 姓名電話OicqEMail地址
 
   添加一個文本框(text 然後[復制/粘貼次]使其成為控件數組
 
   添加一個Listview控件(Listview在其屬性框中添加五個列首文本值分別為姓名電話OicqEMail地址查看屬性lvwReport 選中整行選擇取消隱藏選擇
 
   添加兩個按鈕其標題屬性分別為添加刪除添加如下代碼  
Option Explicit
  Dim fileName As String
  Private Sub Command_Click()
  將文本框中的信息添加到列表框中
  Dim i As Integer
   With ListViewListItemsAdd()
    Text = Text()
    For i = To
    SubItems(i) = Text(i)
   Next i
   End With
  End Sub

  Private Sub Command_Click()
  刪除列表框中信息
  If ListViewListItemsCount > Then
   If MsgBox(真的要刪除嗎? vbQuestion + vbYesNo + vbDefaultButton) = vbYes Then
   ListViewListItemsRemove ListViewSelectedItemIndex
   End If
  End If
  End Sub

  Private Sub Form_Load()
  Dim tpStr As String i As Integer
  fileName = AppPath & \datatxt
If Dir(fileName) <> Then
   加載數據
   Open fileName For Input As #
    Do While Not EOF()
     With ListViewListItemsAdd()
      For i = To
       Line Input # tpStr
       If i = Then
        Text = tpStr
       Else
        SubItems(i) = tpStr
       End If
      Next i
     End With
    Loop
   Close #
  End If
  End Sub

  Private Sub Form_Unload(Cancel As Integer)
  Dim i As Integer
  Dim tpList As ListItem
  保存數據
  Open fileName For Output As #
   For Each tpList In ListViewListItems
    Print # tpListText
    For i = To
     Print # tpListSubItems(i)
    Next i
   Next tpList
  Close #
  End Sub

  本程序已在windows+VB環境下調試通過
From:http://tw.wingwit.com/Article/program/net/201311/11502.html
  • 上一篇文章:

  • 下一篇文章:
  • 推薦文章
    Copyright © 2005-2022 電腦知識網 Computer Knowledge   All rights reserved.