VB中MsFlexGrid控件的使用细则

WinCC笔记:02.MSHFlex控件 —— (7) 多表格联合操作 有两张表格grid和grid2,grid中通过数据表写入数据,grid2显示选择的grid中的数据。 阅读详情

 

VB中MsFlexGrid控件的使用细则(收集)

>> 将文本赋值给MsFlexGrid的单元格
MsFlexGrid.TextMatrix(3,1)=”Hello”

>> 在MsFlexGrid控件单元格中插入背景图形
Set MsFlexGrid.CellPicture=LoadPicture(“C:/temp/1.bmp”)

>>选中某个单元
MsFlexGrid.Row=1
MsFlexGrid.Col=1

>>用粗体格式化当前选中单元
MsFlexGrid.CellFontBold=True

>> 添加新的一行
使用AddItem方法,用Tab字符分开不同单元格的内容
dim row as string
row=”AAA”&vbtab&”bbb”
MsFlexFrid1.addItem row


>>怎样来实现MSFlexGrid控件单数行背景为白色,双数的行背景为蓝色?
Dim i As Integer
With MSFlexGrid1
.AllowBigSelection = True ’ 设置网格样式
.FillStyle = flexFillRepeat
For i = 0 To .Rows - 1
.Row = i: .Col = .FixedCols
.ColSel = .Cols() - .FixedCols - 1
If i Mod 2 = 0 Then
.CellBackColor = &HC0C0C0 ’ 浅灰
Else
.CellBackColor = vbBlue ’ 兰色
End If
Next i
End With

>> MSFlexGrid控件如何移到最后一行
MSFlexGrid1.TopRow = MSFlexGrid1.Rows – 1

>>如何判断msflexgrid有无滚动条
Declare Function GetScrollRange Lib "user32" (ByVal hWnd As Long, ByVal nBar As Long, lpMinPos As

Long, lpMaxPos As Long) As Long
Public Const SB_HORZ = &H0
Public Const SB_VERT = &H1

Public Function VsScroll(MshGrid As MSHFlexGrid) As Boolean ’判断水平滚动条的可见性
Dim i As Long
VsScroll = False
i = GetScrollRange(MshGrid.hWnd, SB_HORZ, lpMinPos, lpMaxPos)
If lpMaxPos <> lpMinPos Then VsScroll = True
End Function

Public Function HeScroll(MshGrid As MSHFlexGrid) As Boolean ’判断垂直滚动条的可见性
Dim i As Long
HeScroll = False
i = GetScrollRange(MshGrid.hWnd, SB_VERT, lpMinPos, lpMaxPos)
If lpMaxPos <> lpMinPos Then HeScroll = True
End Function

>>程序运行时,想动态增加MSFlexgrid的列数
在第2列后插入一列:
Private Sub Form_Load()
Me.MSHFlexGrid1.Cols = 5
MSHFlexGrid1.Rows = 2
For i = 0 To Me.MSHFlexGrid1.Cols - 1
Me.MSHFlexGrid1.TextMatrix(0, i) = i
Me.MSHFlexGrid1.TextMatrix(1, i) = i
Next
End Sub

Private Sub Command1_Click()
Me.MSHFlexGrid1.Cols = Me.MSHFlexGrid1.Cols + 1
Me.MSHFlexGrid1.ColPosition(5) = 3
End Sub

>> 请教MSFlexGrid中的对齐功能的使用
设置MSFlexGrid1.ColAlignment(index)=n


>>得到MSFlexGrid控件中当前选中的一行
msflexgrid1.rowsel就是当前选中行

>> 如何通过代码调节列宽度
msflexgrid1.colwidth(i)=4000
将MsFlexGrid控件的内容输出到文本

2004-03-19 14:25:18
'OutDataToText
'将MsFlexGrid控件中显示的内容输出到文本文件
Public Sub OutDataToText(Flex As MSFlexGrid)
Dim s As String
Dim i As Integer
Dim j As Integer
Dim k As Integer
Dim strTemp As String
On Error GoTo Ert
Me.MousePointer = 11
On Error Resume Next
DoEvents
Dim FileNum As Integer
FileNum = FreeFile
Open "d:aa.txt" For Output As #FileNum
With Flex
k = .Rows
For i = 0 To k - 1
strTemp = ""
For j = 0 To .Cols - 1
DoEvents
strTemp = strTemp & .TextMatrix(i, j) & ","
Next j
Print #FileNum, Left(strTemp, Len(strTemp) - 1)
Next i
End With
Close #FileNum
Me.MousePointer = 0
MsgBox "导出成功"
Ert:
MsgBox Err.Description
Me.MousePointer = 0
End Sub
增加 MsFlexGrid 的编辑功能

(作者:佚名 加载日期: 2002/3/31)


概述
MsFlexGrid 控件没有提供文本编辑的功能,下面的例子演示了如何利用一个TextBox 实现编辑当前网格的功能

。

在按下一个键后, 就把TextBox 移动到当前的位置, 并激活。 在键入回车或移动到其他网格时,

就把TextBox 中的内容放到网格中。

实现步骤
1 打开 VB5, 开启一个新的工程。

2 在菜单“工程” 中选择 “部件”, 在列表中选中 “Microsoft FlexGrid Control ..”

3 放一个 MsFlexGrid 控件和一个TextBox 控件(Text1)到 Form1。 修改MsFlexGrid 控件的名称为 Grid1,

设置Grid1 的行,列 为 4, 固定行,列为 0。 设置 Text1 的 Visiable 为 False, BorderStyle 为

None(0)。

4 在Form1 的代码中增加声明:

Const ASC_ENTER = 13 '回车
Dim gRow As Integer
Dim gCol As Integer

5 增加代码到 Grid_KeyPress 过程:

Private Sub Grid1_KeyPress(KeyAscii As Integer)
' Move the text box to the current grid cell:
Text1.Top = Grid1.CellTop + Grid1.Top
Text1.Left = Grid1.CellLeft + Grid1.Left
' Save the position of the grids Row and Col for later:
gRow = Grid1.Row
gCol = Grid1.Col
' Make text box same size as current grid cell:
Text1.Width = Grid1.CellWidth - 2 * Screen.TwipsPerPixelX
Text1.Height = Grid1.CellHeight - 2 * Screen.TwipsPerPixelY
' Transfer the grid cell text:
Text1.Text = Grid1.Text
' Show the text box:
Text1.Visible = True
Text1.ZOrder 0 ' 把 Text1 放到最前面!
Text1.SetFocus
' Redirect this KeyPress event to the text box:
If KeyAscii <> ASC_ENTER Then
SendKeys Chr$(KeyAscii)
End If
End Sub

6 增加代码到 Text1_KeyPress 过程:

Private Sub Text1_KeyPress(KeyAscii As Integer)
If KeyAscii = ASC_ENTER Then
Grid1.SetFocus ' Set focus back to grid, see Text_LostFocus.
KeyAscii = 0 ' Ignore this KeyPress.
End If
End Sub

7 增加代码到 Text1_LostFocus 过程:

Private Sub Text1_LostFocus()
Dim tmpRow As Integer
Dim tmpCol As Integer
' Save current settings of Grid Row and col. This is needed only if
' the focus is set somewhere else in the Grid.
tmpRow = Grid1.Row
tmpCol = Grid1.Col
' Set Row and Col back to what they were before Text1_LostFocus:
Grid1.Row = gRow
Grid1.Col = gCol
Grid1.Text = Text1.Text ' Transfer text back to grid.
Text1.SelStart = 0 ' Return caret to beginning.
Text1.Visible = False ' Disable text box.
' Return row and Col contents:
Grid1.Row = tmpRow
Grid1.Col = tmpCol
End Sub

8 好了。 按 F5 开始测试。 您可以自由地在 Grid 中移动, 按回车可以开始或结束编辑。

使用MsFlexGrid控件的几个函数


作者:中国论坛网收集 来源:http://www.51one.net 加入时间:2004-8-25

在VB处理数据显示的时候,使用表格是一种好的方法,虽然DataGrid可以与数据源绑定,但是总有美中不足,就是

外观不好看,所以有时应用MsFlexGrid显示数据还是一种比较好的方法,以下几个函数是用来控制MsFlexGrid的

程序

(本人语言表达能力有限,还请见谅)

 

''MsFlexGrid操作函数

''合并列
Public Function MergeCol(GridObj As Object, ByVal StartCol As Long, ByVal EndCol As Long, ByVal

ColValue As String, ByVal CurrentRow As Long) As Boolean
If StartCol > EndCol Or StartCol > GridObj.Cols Or CurrentRow > GridObj.Rows Then
MsgBox "对不起,行列设置错误!", vbOKOnly, App.Title
MergeCol = False
Exit Function
End If

For I = StartCol To EndCol
GridObj.MergeCol(I) = True
GridObj.TextArray(faIndex(GridObj, CurrentRow, I)) = ColValue
GridObj.ColAlignment(I) = flexAlignCenterCenter
Next I


GridObj.MergeRow(CurrentRow) = True

MergeCol = True

End Function

 


''合并行
Public Function MergeRow(GridObj As Object, ByVal StartRow As Long, ByVal EndRow As Long, ByVal

RowValue As String, ByVal CurrentCol As Long) As Boolean
If StartRow > EndRow Or StartRow > GridObj.Rows Or CurrentCol > GridObj.Cols Then
MsgBox "对不起,行列设置错误!", vbOKOnly, App.Title
MergeRow = False
Exit Function
End If

For I = StartRow To EndRow
GridObj.MergeRow(I) = True
GridObj.TextArray(faIndex(GridObj, I, CurrentCol)) = RowValue
GridObj.ColAlignment(CurrentCol) = flexAlignCenterCenter

Next I
GridObj.MergeCol(CurrentCol) = True
MergeRow = True

End Function

''转换索引
Public Function faIndex(GridObj As Object, ByVal row As Integer, ByVal col As Integer) As Long
If row > GridObj.Rows Or row < 0 Or col > GridObj.Cols Or col < 0 Then
MsgBox "对不起,行列设置错误!", vbOKOnly, App.Title
faIndex = -1

Exit Function
End If

faIndex = row * GridObj.Cols + col

End Function


''插入行
Public Function SetItem(GridObj As Object, ByVal row As Integer, ByVal col As Integer, ByVal

SetValue As String) As Boolean
If row > GridObj.Rows Or row < 0 Or col > GridObj.Cols Or col < 0 Then
MsgBox "对不起,行列设置错误!", vbOKOnly, App.Title
SetItem = False
Exit Function
End If
GridObj.TextArray(faIndex(GridObj, row, col)) = SetValue

SetItem = True
End Function

''得到单元格值
Public Function GetItem(GridObj As Object, ByVal row As Integer, ByVal col As Integer) As String

If row > GridObj.Rows Or row < 0 Or col > GridObj.Cols Or col < 0 Then
MsgBox "对不起,行列设置错误!", vbOKOnly, App.Title
GetItem = ""
Exit Function
End If
GetItem = GridObj.TextArray(faIndex(GridObj, row, col))
End Function

在msflexgrid控件中每一个cell格的内容是不可以由用户直接编辑的但是我们可以通过一些小技
巧来方便的实现这编辑功能来扩展msflexgrid的应用(在实际应用中这是很常用的功能)。

你只需按下面的做即可轻松实现编辑msflexgrid控件数据的功能

例在窗体上放一文本框txtvalue,和一msflexgrid控件grid

‘文本框控件的keypress事件
private sub txtvalue_keypress(keyascii as integer)
‘放入一些处理过程,如只需输入数字时的处理

dim i
i=1
end sub

private sub txtvalue_change()
grid.text = txtvalue.text
end sub


'在grid的entercell事件中加入下例代码
private sub grid_entercell()
txtvalue.text = grid.text
txtvalue.selstart = 0
txtvalue.sellength = len(txtvalue.text)
end sub

'当用户输入数据时直接调用文本框的keypress事件
private sub grid_keypress(keyascii as integer)
txtvalue_keypress keyascii
end sub

ok,这样一个可编辑的msflexgrid控件就完成了,简单吧!!

原理
当用户点击msflexgrid中的某个cell格要输入数据时,产生entercell事件,在这里我们对文本
框进行初始化,输入当前cell格中的内容,并且选中所有文本。当用户要按下按键进行输入时,就直
接调用txtvalue的事件,由文本框来处理.

处理的结果同grid的当前cell同步,使用户编辑cell格就象使用文本框一样方便

 

 

'MsFlexGrid操作函数

'合并列
Public Function MergeCol(GridObj As Object, ByVal StartCol As Long, ByVal EndCol As Long, ByVal ColValue As String, ByVal CurrentRow As Long) As Boolean
If StartCol > EndCol Or StartCol > GridObj.Cols Or CurrentRow > GridObj.Rows Then
MsgBox "对不起,行列设置错误!", vbOKOnly, App.Title
MergeCol = False
Exit Function
End If

For I = StartCol To EndCol
GridObj.MergeCol(I) = True
GridObj.TextArray(faIndex(GridObj, CurrentRow, I)) = ColValue
GridObj.ColAlignment(I) = flexAlignCenterCenter
Next I


GridObj.MergeRow(CurrentRow) = True

MergeCol = True

End Function




'合并行
Public Function MergeRow(GridObj As Object, ByVal StartRow As Long, ByVal EndRow As Long, ByVal RowValue As String, ByVal CurrentCol As Long) As Boolean
If StartRow > EndRow Or StartRow > GridObj.Rows Or CurrentCol > GridObj.Cols Then
MsgBox "对不起,行列设置错误!", vbOKOnly, App.Title
MergeRow = False
Exit Function
End If

For I = StartRow To EndRow
GridObj.MergeRow(I) = True
GridObj.TextArray(faIndex(GridObj, I, CurrentCol)) = RowValue
GridObj.ColAlignment(CurrentCol) = flexAlignCenterCenter

Next I
GridObj.MergeCol(CurrentCol) = True
MergeRow = True

End Function

'转换索引
Public Function faIndex(GridObj As Object, ByVal row As Integer, ByVal col As Integer) As Long
If row > GridObj.Rows Or row < 0 Or col > GridObj.Cols Or col < 0 Then
MsgBox "对不起,行列设置错误!", vbOKOnly, App.Title
faIndex = -1

Exit Function
End If

faIndex = row * GridObj.Cols + col

End Function


'插入行
Public Function SetItem(GridObj As Object, ByVal row As Integer, ByVal col As Integer, ByVal SetValue As String) As Boolean
If row > GridObj.Rows Or row < 0 Or col > GridObj.Cols Or col < 0 Then
MsgBox "对不起,行列设置错误!", vbOKOnly, App.Title
SetItem = False
Exit Function
End If
GridObj.TextArray(faIndex(GridObj, row, col)) = SetValue

SetItem = True
End Function

'得到单元格值
Public Function GetItem(GridObj As Object, ByVal row As Integer, ByVal col As Integer) As String

If row > GridObj.Rows Or row < 0 Or col > GridObj.Cols Or col < 0 Then
MsgBox "对不起,行列设置错误!", vbOKOnly, App.Title
GetItem = ""
Exit Function
End If
GetItem = GridObj.TextArray(faIndex(GridObj, row, col))
End Function

机房收费系统-MSFlexGrid控件的使用 前言:      机房收费系统中查询窗体几乎都用到了一个控件,就是MSFlexGrid控件。百度上给的官方解释是:MSFlexGrid控件显示和操作表格数据。其对包含字符串和图片的表格提供了灵活的排序、插入数据和格式编排功能。当与Data控件绑定时,MSFlexGrid控件只显示只读数据。我理解的是,显示符合条件的数据的一个展示栏。说的可能比较通俗,接下来,我就来详细给大家说说MSFlexGri 阅读详情

相关推荐

VB6.0中编辑MSHFlexGrid强制换行并调整列宽及行高.txt

VB6.0中根据每一个单元格的内容根据指定的列宽强制换行,并根据单元格的内容调整行高和列宽

深入解析 MSHFlexGrid 和 MSFlexGrid 控件

MSFlexGrid1 一字之差,到底是个啥

李赛男 5881

stm32最小系统_完成一个最小FOC矢量控制系统所需的基本模块和功能配置

当我们读懂 FOC 矢量控制的基本原理之后,便迫不及待的想动手尝试,去实现一个矢量控制系统,让电机先转起来,有一个直观的感受。因此,我们需要设计实现一个矢量控制的最小系统,具备矢量控制的基本功能,满足电机矢量运行的基本条件。首先,看一下矢量控制的基本架构:矢量控制架构如上图所描述,矢量控制系统包括实时电流的采集、clarke 变换、park 变换、SVPWM 、实时角度的反馈和计算以及电流环和速...

weixin_39524048的博客 1790

强大的MSFlexGrid控件

前言:MSHFlexGrid的用途非常的广泛,在涉及到表格的时候,用起来非常的方便。今天研究了一下午这个控件。下面是一些总结,来和大家分享一下。如果错误,欢迎指正。 (1)简述: MSHFlexGrid控件显示和操作表格数据。其对包含字符串和图片的表格提供了灵活的排序、插入数据和格式编排功能。 当与Data控件绑定时,MSHFlexGrid控件只显示只读数据 MSFlexGrid的

Stephanie翟倩 1万+

STM32F103 CAN通信避坑指南:从标准库配置到收发测试的完整流程

本文详细介绍了STM32F103 CAN通信的实现流程,从标准库配置到收发测试,帮助开发者避开常见陷阱。内容涵盖硬件连接、波特率计算、过滤器配置及错误处理等关键环节,提供实用的代码示例和调试技巧,确保CAN通信的稳定性和可靠性。

weixin_30627341的博客 332

Overleaf+EndNote+BibTeX:手把手搞定Elsevier期刊投稿的参考文献格式(避坑指南)

本文详细介绍了如何利用Overleaf、EndNote和BibTeX三大工具无缝协作,解决Elsevier期刊投稿中的参考文献格式问题。从工具链配置、文献库导出、BibTeX文件优化到Overleaf集成与编译,提供全流程指南和常见问题解决方案,帮助学术新手高效完成Elsevier期刊投稿。

weixin_30616969的博客 514

VB中MsFlexGrid控件的使用细则(收集)

 >> 将文本赋值给MsFlexGrid的单元格 MsFlexGrid.TextMatrix(3,1)=”Hello” >> 在MsFlexGrid控件单元格中插入背景图形 Set MsFlexGrid.CellPicture=LoadPicture(“C:/temp/1.bmp”) >>选中某个单元 MsFlexGrid.Row=1 MsFlexGrid.Col=1 >>用粗体格式化当前选中

世界的边际的专栏 2241

【社区分享】从零开始学习 TinyML,建立 TensorFlow 深度学习模型(技术优化篇)

本文来自社区投稿与征集,作者王玉成,ML&IoT Google Developers Expert,温州大学智能锁具研究院总工程师。 了解更多:https://blog.csdn.net/wfing 经过前面几章的讨论,我们了解了TinyML 的概念,完成了一个最简单的TinyML 的模型并且运行在微控制器上,得出最基本的结果。但是在实际的工程应用中,模型建立之后,也需要再进一步结合许多优化方面的技术,这就是我们接下来想要探讨的。 5. 优化 TinyML 这本书也详细的向我...

tensorflowforum的博客 1万+

msflexgrid允许大选择_VB中MsFlexGrid控件的使用细则 -

GridColorUnpopulatedOle_Color设置/返回网格UNPOPULATED区域间的颜色 GrigLineEnum定义网格单元间的线的类型GrigLinesBandArray/Enum定义网格各BAND间的线的类型 GrigLinesFixedEnum定义网格固定单元的线的类型GrigLinesHeaderArray/Enum定义网格各头部间的线的类型GrigLinesInde...

weixin_29228203的博客 1113

eDP/DP接口简介

目前,在视频传输协议以及接口领域,外部接口主要是DP与HDMI两分天下,当然之前出现过很多接口-VGA, DVI等等,最新平台基本以这两个为主;笔记本内部接口就基本上使用eDP((Embedded Display Port))作为标准接口来驱动液晶屏了。那么问题来了,eDP和DP,是完全兼容的么?eDP,DP,HDMI,这三种接口的显示器,可以插在同一个接口上使用么?这篇文章,就会从硬件和一部分协议的角度分析一下这三大协议。

weixin_50518899的博客 2万+

uniapp - 详解使用高德地图在地图上实现绘制边界/点聚合/行政区域高亮等功能,Uniapp高德地图点聚合标记及绘制点线面示例代码(全端兼容H5网页、小程序、安卓app、苹果app、nvue)

uni-app,h5移动端网页,微信小程序,支付宝小程序,Android安卓,苹果ios,app,nvue,高德地图,uniAPP高德地图实现点聚合,地图区域描边、点标记、点信息详情弹窗,实现绘制边界区域,uniapp H5使用高德地图实现点聚合、行政区域高亮,实现高德地图的marker聚合功能,高德地图进行marker标点,点信息展示,点击标记点弹出对话框,点击聚合点后显示信息模态框,打标点,【Uniapp】高德地图的接入自定义标点与信息窗体使用,绘制行政区域边界,绘制多边形,电子围栏,高德行政区划边界,

✅ 精选推荐文章 1万+

msflexgrid允许大选择_VB中MsFlexGrid控件的使用细则

VB利用ADO控件连接access数据库今天告诉大家VB利用ADO控件连接access数据库的两种方法:一种是在 adodc1的属性里设置数据库文件的路径,这种方法的优点是简单易操作,缺点是,当源文件换了地方后,要重新设置数据库的路径,否则连接不上数据库了。一种是用代码设置数据库的路径,这种方法的优点就是只要源文件和数据库在同一文件夹下,无论移动到哪里都能连接上。如果没有建立好数据库的话,先建立一...

weixin_39672160的博客 434

多物理场光学仿真软件:Lumerical_(15).多物理场耦合仿真案例分析

在多物理场光学仿真中,Lumerical 软件提供了强大的工具来模拟复杂的光学系统,包括光子学、热学、力学和电学等多物理场的耦合。本节将通过具体的案例分析,展示如何在 Lumerical 中进行多物理场耦合仿真的开发和实现。我们将从简单的热光效应仿真入手,逐步深入到更复杂的多物理场耦合场景,如光电效应和光力学效应。每个案例都将包括详细的原理说明和具体的代码示例,帮助读者更好地理解和应用这些技术。

kkchenjj的博客 1028

VB中MsFlexGrid控件的使用细则收集

>> 将文本赋值给MsFlexGrid的单元格 MsFlexGrid.TextMatrix(3,1)=”Hello” >> 在MsFlexGrid控件单元格中插入背景图形 Set MsFlexGrid.CellPicture=LoadPicture(“C:/temp/1.bmp”) >>选中某个单元 MsFlexGrid.Row=1 MsFlexGrid.Col=1 >>用粗体格式化当

鞠勇鸿的技术专栏 1732

机器学习笔记——30种常见机器学习算法简要汇总

本笔记介绍机器学习中常见的30种机器学习算法。

haopinglianlian的博客 3206

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

msflexgrid允许大选择_MsFlexGrid用法

VB中MsFlexGrid控件的使用细则(收集)>>将文本赋值给MsFlexGrid的单元格MsFlexGrid.TextMatrix(3,1)=”Hello”>>在MsFlexGrid控件单元格中插入背景图形SetMsFlexGrid.CellPicture=LoadPicture(“C:\temp\1.bmp”)>>选中某个单元MsFlexGrid.Row...

weixin_39723655的博客 265

ET2012新版免狗免安装绿色软件

ET2012新版免狗免安祖昂绿色软件。,新界面,新视觉,

上一篇: 在VB6中导出EXCEL,FOXPRO,PRODOX格式的表
下一篇: 用MsFlexGrid控件显示数据库中的记录
netcellsoft
博客等级 码龄21年 25粉丝 18原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值
⌂ 换网址