终将逝去的VB6

前端之家收集整理的这篇文章主要介绍了终将逝去的VB6前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

记得很多年以前,我第一次接触到VB6,很开心,拖拉控件就可以做出很漂亮的界面,比C有意思多了。

后来在中科院培训JAVA的时候,我们的杨景涛老师也精通VB。我开始对编程感兴趣源自VB6。在中科院我们只实践了一个项目,现在想起来,只有一个字矬

005936979.jpg

下面这个是我上大学的时候在给学校做门面房管理系统的时候,写的一个人员管理,目的是管理我们这些开发人员的上班情况。当时梦想着有朝一日能够自己开公司,叫做雷电科技。

010109425.jpg

我们门面房系统做了1个月,如下

010332803.jpg

这个当时是个JAVA版的CS系统,很简单的,这也是我做程序以来第一次赚钱。


OK,JAVA现在的用户量无可厚非,但是VB6已经接近消亡。今天我们就再一次记忆终将逝去的VB6,我发誓,写完这篇之后,我再也不会关注VB6了。我们先看一下界面

201400420.png

这个就是VB版本的个人理财查询界面,这个界面是根据C#版本的翻译过来的

013115325.png

当然了,我也没有做的C#那么细致。看一下代码

Option Explicit
Dim conn As ADODB.Connection
Dim res As ADODB.Recordset
Dim connString As String
Dim userName As String
Dim startDate As Date
Dim endDate As Date
Dim types As String
Dim sqlStr As String
Dim i As Integer
Dim strColums(0 To 8) As String
Dim strChecked As String

先声明一些变量在窗体加载的时候,初始化一部分

Private Sub Form_Load()
    Call Init
    strColums(1) = "选择"
    strColums(2) = "编号"
    strColums(3) = "姓名"
    strColums(4) = "性别"
    strColums(5) = "年龄"
    strColums(6) = "金额"
    strColums(7) = "日期"
End Sub
Private Function Init()
    connString = "Provider=sqlNCLI10;Server=ZZCYIC6VXOK5UXO\MSsqlSERVER08;Database=Bonus;Trusted_Connection=yes"
    Adodc1.ConnectionString = connString
End Function

初始化MSFlexGrid的列名以及连接字符串,这个是连接sqlServer2008的字符串,ADODC1是我们拖拽的一个数据库连接控件

013521881.png

我们接下来看一下查询

Private Sub CmdQuery_Click()
    On Error GoTo errorplay
    userName = Trim(txtUserNo.Text)
    startDate = DTPStartDate.Value
    endDate = DTPEndDate.Value
                                       
    If ChkEnter.Value Then
        types = 1
        Else: types = 0
    End If
    sqlStr = "SELECT a.TransactionNumber AS 编号,b.Name AS 姓名,(CASE b.Sex WHEN  1 THEN '男' WHEN '0' THEN '女' END) AS 性别,b.Age AS 年龄,"
    sqlStr = sqlStr & " a.Money AS 金额,a.InDate AS 日期"
    sqlStr = sqlStr & " FROM dbo.Bonus a WITH(NOLOCK) " & "INNER JOIN dbo.UerInfo b WITH(NOLOCK) ON a.UseNo=b.UseNo"
    sqlStr = sqlStr & " Where"
                                       
    If userName <> "" Then
        sqlStr = sqlStr & " UseNo LIKE '%" & userName & "%"
    End If
                                       
    If startDate < endDate Then
        If userName <> "" Then
            sqlStr = sqlStr & " AND"
        End If
                                      
        sqlStr = sqlStr & " InDate BETWEEN '" & startDate & "' AND '" & endDate & "'"
    End If
                                       
    If ChkEnter.Value Then
        sqlStr = sqlStr & " AND a.IsEnter='1'"
    Else
        sqlStr = sqlStr & " AND a.IsEnter='0'"
    End If
                                           
    Adodc1.RecordSource = sqlStr
    Adodc1.Refresh
                                       
    If Adodc1.Recordset.RecordCount > 0 Then
         MSFlexGridResult.AllowUserResizing = flexResizeBoth
         MSFlexGridResult.Cols = Adodc1.Recordset.Fields.Count + 2
         MSFlexGridResult.Rows = Adodc1.Recordset.RecordCount + 1
                                              
         For i = 1 To UBound(strColums)
            MSFlexGridResult.TextMatrix(0,i - 1) = strColums(i - 1)
         Next i
                                            
        With Adodc1.Recordset
                                           
           For i = 1 To .RecordCount
                MSFlexGridResult.Row = i
                MSFlexGridResult.Col = 1
                MSFlexGridResult.RowHeight(i) = 400
                Set MSFlexGridResult.CellPicture = ImageList1.ListImages(1).Picture
                MSFlexGridResult.CellPictureAlignment = 3
                                               
                MSFlexGridResult.TextMatrix(i,0) = i
                MSFlexGridResult.TextMatrix(i,2) = .Fields("编号")
                MSFlexGridResult.TextMatrix(i,3) = .Fields("姓名")
                MSFlexGridResult.TextMatrix(i,4) = .Fields("性别")
                MSFlexGridResult.TextMatrix(i,5) = .Fields("年龄")
                MSFlexGridResult.TextMatrix(i,6) = .Fields("金额")
                MSFlexGridResult.TextMatrix(i,7) = .Fields("日期")
                                                   
                .MoveNext
            Next i
                                               
        End With
                                           
        If (MSFlexGridResult.Rows > 0) Then
            CalculateTotal (MSFlexGridResult.Rows)
        Else: LabTotal.Caption = "0"
        End If
                                           
    End If
                                       
    Exit Sub
errorplay:
   ShowMessage ("查询出错")
End Sub

根据查询条件拼出查询语句,然后获取数据集,循环插入MSFlexGrid中。

查询完成后计算总额

Private Sub CalculateTotal(rowCount As Integer)
    Dim total As Single
    For i = 1 To rowCount - 1
        total = total + MSFlexGridResult.TextMatrix(i,6)
    Next i
                                                                                                                                                           
    LabTotal.Caption = total & ""
End Sub

这里第一列是个CellPicture,是用来删除数据用的,比如如下图片

@L_502_8@

201428667.png

代表第一行和第三行我要删除,那么图片之间的替换由下面的代码完成

Private Sub MSFlexGridResult_Click()
Dim oldx,oldy,cell2text As String,strTextCheck As String
    If MSFlexGridResult.Rows > 0 And MSFlexGridResult.Cols > 2 Then
        With MSFlexGridResult
            oldx = .Col
            oldy = .Row
            If MSFlexGridResult.Col = 1 Then
                If MSFlexGridResult.CellPicture = ImageList1.ListImages(1).Picture Then
                    Set MSFlexGridResult.CellPicture = ImageList1.ListImages(2).Picture
                    .Col = .Col + 1
                    strTextCheck = .Text
                    strChecked = Replace(strChecked,strTextCheck & ",","")
                Else
                    Set MSFlexGridResult.CellPicture = ImageList1.ListImages(1).Picture
                    .Col = .Col + 1
                    strTextCheck = .Text
                    strChecked = strChecked & strTextCheck & ","
                End If
            End If
            .Col = oldx
            .Row = oldy
        End With
    End If
End Sub

OK,上面的代码类似于实现ToggleButton一样,最后我们来看一下删除代码

Private Sub CmdDelete_Click()
    Dim strWhere As String
    sqlStr = "DELETE FROM dbo.Bonus WHERE "
                                                                     
    For i = 1 To MSFlexGridResult.Rows - 1
         MSFlexGridResult.Row = i
         MSFlexGridResult.Col = 1
         If MSFlexGridResult.CellPicture = ImageList1.ListImages(2).Picture Then
            strWhere = strWhere & MSFlexGridResult.TextMatrix(i,2) & ","
         End If
    Next i
                                                                     
    If strWhere <> "" Then
        strWhere = Mid(strWhere,1,Len(strWhere) - 1)
        sqlStr = sqlStr & "TransactionNumber IN(" & strWhere & ")"
        conn.Open connString
        conn.Execute (sqlStr)
        conn.Close
    Else
        ShowMessage ("请选择要删除的数据")
    End If
End Sub

OK,根据图片获取删除的编号,然后实现删除。如果没有选择,会提示

201446197.png

OK,VB6终将逝去,我们不必留恋,最后再次看一眼VB6的开发界面,然后睡觉吧。

202402629.png

运行,开始播放

202509435.png

原文链接:https://www.f2er.com/vb/258273.html

猜你在找的VB相关文章