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

VB script 入门

发布时间:2020-12-17 07:38:46 所属栏目:百科 来源:网络整理
导读:这里简单介绍下vb script 脚本的基本语法: 后面可以参考这个例子: Sub 创建任务脚本_Click()Dim Line As String Dim ColumnStr As String Dim Substr As String Dim Str,Val,n max_line = 20000 Set fs = CreateObject("Scripting.FileSystemObject") sFil

这里简单介绍下vb script 脚本的基本语法:

后面可以参考这个例子:

Sub 创建任务脚本_Click()
Dim Line As String
  Dim ColumnStr As String
  Dim Substr As String
  Dim Str,Val,n
  
  
  max_line = 20000
  
  Set fs = CreateObject("Scripting.FileSystemObject")
    sFilename = ThisWorkbook.Path + "....Sourcessqloutput.sql"
  Set fhandle = fs.CreateTextFile(sFilename,True)
  
  i = 1
  For i = 1 To 200  '显示修改历史记录预设200行
    If (Cells(i,1) = "修改历史") And UCase(Cells(i,2)) = "BEGIN" Then
        j = i + 1
        fhandle.WriteLine ("-- 修改历史:")
        While Not (Cells(j,1) = "修改历史" And UCase(Cells(j,2)) = "END")
            fhandle.WriteLine ("-- " & Cells(j,1) & " -" & Cells(j,2) & " -" & Cells(j,3) & " -" & Cells(j,4))
            j = j + 1
        Wend
        Exit For
    End If
  Next

  
  '1.定位到第一条数据所在行数
  menu_start = 0
  For i = 1 To max_line
    If Cells(i,2) = "交易市场" Then
      menu_start = i + 1
      Exit For
    End If
  Next
  
  If menu_start = 0 Then
    Exit Sub
  End If

 
  fhandle.WriteLine ("                                                       ")
  fhandle.WriteLine ("                                                       ")
    
  
    '3.生成任务脚本
    For i = menu_start To max_line
      If Cells(i,2) = "" Then
         Exit For
      End If
        fhandle.WriteLine ("--" & Cells(i,15) & " start")
        fhandle.WriteLine ("declare")
        fhandle.WriteLine ("    iCountNum number;")
        fhandle.WriteLine ("begin")
        fhandle.WriteLine ("    iCountNum := 0;")
        
        Line = "    select count(*) into iCountNum from TCONVERTSET where vc_module = '" & Cells(i,7) & "' and vc_function = '" & Cells(i,8) & "';"
        fhandle.WriteLine (Line)
        fhandle.WriteLine ("    if (iCountNum = 0) then")
       
        Line = "        insert into TCONVERTSET (L_SERIAL_NO,L_OPERATOR_NO,C_MARKET_NO,C_CONVERT_TYPE,L_THREAD_COUNT,L_BEGIN_TIME,L_END_TIME,VC_MODULE,VC_FUNCTION,C_CONVERT_STATUS,L_PRIORITY_LEVEL,VC_REMARKS,VC_INIT_FUNCTION,C_RUN_ONCE,C_VERSION )"
        fhandle.WriteLine (Line)
        Line = "        values ( SeqConvertSetNo.nextval,1000,'" & Cells(i,2) & "',3) & "'," & Cells(i,4) & ",5) & ",6) & ",7) & "',8) & "',9) & "',10) & ",11) & "',12) & "',13) & "',14) & "');"
        fhandle.WriteLine (Line)
        
        fhandle.WriteLine ("    end if; ")
        fhandle.WriteLine ("end; ")
        fhandle.WriteLine ("/ ")
        fhandle.WriteLine ("")
        
    ' End FOR
    Next
  
   fhandle.WriteLine ("commit; ")
   fhandle.Close

   MsgBox "任务脚本创建成功!" & Chr(10) & "文件名:" & sFilename
End Sub

(编辑:李大同)

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

    推荐文章
      热点阅读