VB編程總結

目錄

1.打包

2.with

3. 多通道,每個通道格式一致

4.一些函數

5,使用ucHistogram1繪圖,


1.打包

打包時可使用自帶的Package & Deployment 嚮導生成安裝包文件,會將所用到的控件提取。也可使用VB-PowerWrap軟件進行生成exe,VB-PowerWrap中創建的時候,壓縮建議使用低,在使用高的時候,其中有些控件在別的電腦運行時出現缺失問題。

2.with

With MyLabel
.Height = 2000
.Width = 2000
.Caption = "This is MyLabel"
End With

意指,MyLabel.Height = 2000 MyLabel.Width = 2000

3. 多通道,每個通道格式一致

在有許多路相同的時候(多通道),建議使用數組的方式,

如創建一個textbox文本框Iset,對其進行復制粘貼,會讓你創建一個數組,雙擊文本框,會進入Iset_Change(Index As Integer),通過Index來區分不同的文本框,對於多路相同的軟件較爲方便,

如操作

Dim in_temp As String
in_temp = Iset(Index).Text,即可通過索引值,實現該數組下所有的文本操作。

4.一些函數

(1)IsNumeric(Iset(Index).Text) 判斷是否爲數字

(2)app.path 可以獲得當前app的路徑

(3)DataOutValue(3) = &HCD 十六進制發送,相當於發送0xCD

(4)Date 獲取當前的日期

(5)Replace(data, "/", "_") 文本替換,data中“/”替換爲“_”

        如用日期創建TXT時,/不允許使用/,故替換爲_(如果替換爲空,則會出現202018,月份表示不明確)

(6)判斷文件夾是否存在(字符串可直接通過+連接)

      If Dir(App.Path + "\BackUp", vbDirectory) = "" Then '判斷文件夾是否存在
           MkDir (App.Path + "\BackUp") '創建文件夾 
     End If

(7)pos= InStr(1, strBuff2, "V0") 在strBuff2中搜素字符串"V0",並返回位置。

(8)Mid(strBuff2, pos, posEnd)取strBuff2中pos到posEnd,中間的字符串

(9)創建TXT(data爲日期),並寫入

            Dim FileNumber
            FileNumber = FreeFile
            Open App.Path + "\BackUp\" + data + ".txt" For Append As #FileNumber
            pos = InStr(1, strBuff2, "V0")
            posEnd = InStr(1, strBuff2, "tEND")
            If posEnd > pos Then
            posEnd = posEnd - pos
            tmp = Mid(strBuff2, pos, posEnd)
             Print #FileNumber, Now(), tmp
             End If
            Close #FileNumber

(10)FileLen("D:\BackUp\1.txt") 可獲得文件大小。

5.使用ucHistogram1繪圖,

(1)先繪製控件picture1,然後在picture1中繪製ucHistogram1,(需要添加用戶控件ucHistogram.ctl)

(2)初始化時, Call Picture1_Resize,Picture1_Resize函數實現如下:

Private Sub Picture1_Resize()
   With ucHistogram1
       .Move 0, 0, Picture1.ScaleWidth, Picture1.ScaleHeight
        .Refresh
    End With
End Sub

(3)再創建一個定時器

Private Sub Timer2_Timer()
Static position As Double

Dim data_temp As String
    If Initflag = True Then
          position = position + 1
          Call Write_Graph(position)
    End If
End Sub

(4)Write_Graph(position)函數實現

Private Function Write_Graph(position As Double)
Dim lPoint As Long
          If position >= 5000000 Then position = 0
          lPoint = Va.Caption * 10
          ucHistogram1.NextPoint lPoin
End Function

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章