加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

VB学习之 按钮响应

发布时间:2020-12-16 22:18:35 所属栏目:大数据 来源:网络整理
导读:Sub 按钮5_Click() Dim strPath As String '输出SQL文件的路径 Dim strFile As String '输出SQL文件的路径+文件名 Dim strPrint As String '输出内容 Dim i,j As Integer '循环变量Dim strTable As String '表名Dim strField As String '字段名Dim strFieldN

Sub 按钮5_Click() Dim strPath As String '输出SQL文件的路径 Dim strFile As String '输出SQL文件的路径+文件名 Dim strPrint As String '输出内容

Dim i,j As Integer         '循环变量

Dim strTable As String      '表名
Dim strField As String      '字段名
Dim strFieldN As String      '字段名(汉字)
Dim strType As String       '字段类型
Dim strLength As String     '字段长度
Dim strNull As String       '非空
Dim strPrimaryKey As String '是否为主键
Dim strTmpPK As String      '是否为主键
'Dim strRemarks As String    '备注
Dim bFirst As Boolean


strPath = "E:"
'从第个工作表开始循环

    strPrimaryKey = ""

    
    'If strTable = "" Then Exit Sub
    strFile = strPath & "database.sql"
     '以输出的格式打开文件strFileName
    Open strFile For Output As #1
    For i = 4 To Worksheets.Count
     '获得表名
    strTable = Worksheets(i).Cells(4,3).Value
    strPrint = "USE CRMIS "
    strPrint = strPrint & vbNewLine & "CREATE TABLE " & strTable & "(" & vbNewLine
    '从第三开始循环至使用行
    bFirst = True
    
    For j = 6 To Worksheets(i).UsedRange.Rows.Count
        strLength = ""
        strNull = ""
        strDefault = ""
        strTmpPK = ""
    
        '字段名
        strField = Worksheets(i).Cells(j,2).Value
        If strField = "" Then Exit For
        strFieldN = Worksheets(i).Cells(j,6).Value
        '字段类型
        strType = Worksheets(i).Cells(j,3).Value
        '长度
        strLength = Worksheets(i).Cells(j,4).Value
        '非空
        strNull = Worksheets(i).Cells(j,5).Value
        '主键
        strTmpPK = Worksheets(i).Cells(j,7).Value
        If strTmpPK <> "" Then strPrimaryKey = "," & Worksheets(i).Cells(j,2).Value
        '备注
      '  strRemarks = Worksheets(i).Cells(j,8).Value

strPrint = strPrint & vbTab & strField

Select Case strType
        Case "INTEGER"
        strType = "bigint"
        'strPrint = strPrint & " " & strType
        Case "NUMBER"
        strType = "decimal"
        'strPrint = strPrint & " " & strType
        Case "DATE"
        strType = "datetime"
        'strPrint = strPrint & " " & strType
        Case "NCBOLB"
        strType = "text"
        'strPrint = strPrint & " " & strType
        Case "VARCHAR2"
        strType = "varchar"
        'strPrint = strPrint & " " & strType
        Case "NVARCHAR2"
        strType = "varchar"
        Case "FLOAT"
        strType = "float"
        Case Else
        strType = "text"
        End Select
          
          If bFirst = True Then
        
       strPrint = strPrint & " " & strType & " IDENTITY(1,1)"
        bFirst = False
        Else
       strPrint = strPrint & " " & strType
        End If
        
       ' strPrint = strPrint & " " & strType
        
        If strLength <> "" And strLength <> "-" Then strPrint = strPrint & "(" & strLength & ")"
        If strNull <> "" Then strPrint = strPrint & " " & "NOT NULL"
       ' If strRemarks <> "" Then strPrint = strPrint & " " & strRemarks
        'strPrint = strPrint & " COMMENT '" & strFieldN & "'"
        strPrint = strPrint & "," & vbNewLine
    Next
    
    If strPrimaryKey <> "" Then
        strPrimaryKey = Right(strPrimaryKey,Len(strPrimaryKey) - 1)
        strPrint = strPrint & vbNewLine & vbTab & "PRIMARY KEY(" & strPrimaryKey & ")"
    Else
        strPrint = Left(strPrint,Len(strPrint))
    End If
    
    strPrint = strPrint & vbNewLine & ");"
    
    Print #1,strPrint
    Next
    Close #1

End Sub

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读