VB代码块总结

前端之家收集整理的这篇文章主要介绍了VB代码块总结前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

1、字体颜色变化代码

Private Sub Timer1_Timer() Label1.ForeColor = RGB(255 * Rnd + 5,255 * Rnd + 5,255 * Rnd + 5) End Sub  

2、导出Excel表单:

Public Sub ExportToExcel(FormName As Form,FlexgridName As String) '导出Excel表的过程 Dim xlApp As Object 'Excel程序 Dim xlBook As Object 'Excel工作薄 Dim xlSheet As Object 'Excel工作表 Screen.MousePointer = vbHourglass '鼠标指示为等待状态 On Error GoTo Err_Proc Set xlApp = CreateObject("Excel.Application") '调用execel程序 Set xlBook = xlApp.Workbooks.Add '添加工作薄 Set xlSheet = xlBook.Worksheets(1) '添加工作单元 '向工作单元中添加数据 Dim i As Long Dim j As Integer With FormName.Controls(FlexgridName) For i = 0 To .Rows - 1 '行依次增加从0开始 外循环,外循环每增加1,内循环循环一周 For j = 0 To .Cols - 1 '一行有.cols列 从0开始循环 xlSheet.Cells(i + 1,j + 1).Value = "'" & .TextMatrix(i,j) '工作表中采用(x,y)坐标,都从1开始 Next j Next i End With xlApp.Visible = True '设定Excel程序可见 Screen.MousePointer = vbDefault '鼠标指针设为默认状态 Exit Sub Err_Proc: Screen.MousePointer = vbDefault '鼠标指针设为默认状态 MsgBox "请确认您的电脑已安装Excel,或是否安装正确!",vbExclamation,"提示" End Sub 
3、sql语句的拼接:
txtsql = "select * from 表名称 where " 此处where后面有个空格 txtsql = txtsql & " " & field(组合关系) & " " & field(某行条件中运算符前的内容) & " " & 该行条件中的运算符号 & "'" & 运算符后的内容 & "'" 
原文链接:https://www.f2er.com/vb/256142.html

猜你在找的VB相关文章