找回密码
 注册会员
查看: 707|回复: 0

麻烦解释一些一下VB代码

[复制链接]
发表于 2010-7-1 09:42:09 | 显示全部楼层 |阅读模式
<p>麻烦解释一些一下VB代码</p>
<p><img src="http://img.baidu.com/img/iknow/icn_point.gif"> 悬赏分:0 -</p>
<p>解决时间:2010-7-1 09:40</p>
<p>Dim row As Long, col As Long</p>
<p>Dim width As Single, maxWidth As Single</p>
<p>Dim saveFont As StdFont, saveScaleMode As Integer</p>
<p>Dim cellText As String</p>
<p>Dim i As Integer</p>
<p>\'If number of records = 0 then exit from the sub</p>
<p>If intRecord = 0 Then Exit Sub</p>
<p>\'Save the form\'s font for DataGrid\'s font</p>
<p>\'We need this for form\'s TextWidth method</p>
<p>Set saveFont = DG.Parent.Font  [这是什么意思]</p>
<p>Set DG.Parent.Font = DG.Font   [这是什么意思]</p>
<p>\'Adjust ScaleMode to vbTwips for the form (parent).</p>
<p>saveScaleMode = DG.Parent.ScaleMode   [这是什么意思]</p>
<p>DG.Parent.ScaleMode = vbTwips     [这是什么意思]</p>
<p>\'Always from first record...</p>
<p>adoData.MoveFirst</p>
<p>maxWidth = 0</p>
<p>\'Tampung nilai maksimal dengan mengalikan variabel</p>
<p>\'jumlah field dan jumlah record, untuk menentukan</p>
<p>\'banyaknya sel yang akan diproses/disesuaikan lebarnya</p>
<p>maks = intField * intRecord  [这是什么意思]</p>
<p>\'Inisialisasi nilai maksimal progressbar</p>
<p>frmADOCode2.prgBar1.Visible = True</p>
<p>frmADOCode2.prgBar1.Max = maks</p>
<p>\'We begin from the first column until the last column</p>
<p>For col = 0 To intField - 1</p>
<p>\'Tampilkan nama field/kolom yg sedang diproses</p>
<p>frmADOCode2.lblField.Caption = _</p>
<p>"Column: " & DG.Columns(col).DataField</p>
<p>adoData.MoveFirst</p>
<p>\'Optional param, if true, set maxWidth to</p>
<p>\'width of DG.Parent</p>
<p>If AccForHeaders Then</p>
<p>maxWidth = DG.Parent.TextWidth(DG.Columns(col).Text) + 200</p>
<p>End If</p>
<p>\'Repeat from first record again after we have</p>
<p>\'finished process the last record in</p>
<p>\'former column...</p>
<p>adoData.MoveFirst</p>
<p>For row = 0 To intRecord - 1</p>
<p>\'Get the text from the DataGrid\'s cell</p>
<p>If intField = 1 Then</p>
<p>Else  \'If number of field more than one</p>
<p>cellText = DG.Columns(col).Text</p>
<p>End If</p>
<p>\'Fix the border...</p>
<p>\'Not for "multiple-line text"...</p>
<p>width = DG.Parent.TextWidth(cellText) + 200</p>
<p>\'Update the maximum width if we found</p>
<p>\'the wider string...</p>
<p>If width > maxWidth Then</p>
<p>maxWidth = width</p>
<p>DG.Columns(col).width = maxWidth</p>
<p>End If</p>
<p>\'Process next record...</p>
<p>adoData.MoveNext</p>
<p>DoEvents</p>
<p>\'Counter bertambah satu, dst</p>
<p>i = i + 1</p>
<p>frmADOCode2.lblAngka.Caption = _</p>
<p>"Finished " & Format((i / maks) * 100, "0") & "%"</p>
<p>DoEvents</p>
<p>frmADOCode2.prgBar1.Value = i</p>
<p>DoEvents</p>
<p>..............</p>
<p>提问者: vinflair - 二级</p>
<p>最佳答案</p>
<p>Set saveFont = DG.Parent.Font  [这是什么意思]</p>
<p>Set DG.Parent.Font = DG.Font   [这是什么意思]</p>
<p>第一句是把DG.Parent.Font(DataGrid控件的父窗体,一般如果你把DataGrid控件放到窗体Form1里边,那么DG.Parent就是窗体Form1,DG.Parent.Font就是Form1设置的字体,也就是Form1.Font)的值赋值给变量saveFont</p>
<p>第二句是把DG.Font(DataGrid控件的字体,DataGrid控件还有HeadFont设置标题栏字体的)的值赋值给DG.Parent.Font,即父窗体的字体设置为DataGrid控件的字体</p>
<p>这两句可以用来备份原来DG.Parent.Font的字体设置,先设置一种字体,以后要是觉得不爽想用回原来的字体,可以用Set DG.Parent.Font = saveFont 修改设置,因为saveFont变量保存了原来的字体。</p>
<p>saveScaleMode = DG.Parent.ScaleMode   [这是什么意思]</p>
<p>DG.Parent.ScaleMode = vbTwips     [这是什么意思]</p>
<p>主要作用和上面一样,也是备份的,不过这次是设置ScaleMode 属性的,ScaleMode 属性指当使用图形方法或调整控件位置时,返回或设置一个值,该值指示对象坐标的度量单位。可以说 ScaleMode 表示一把刻度尺,可以使用不同的单位(就像尺子可以有英尺、厘米、毫米等单位,ScaleMode 属性在标准坐标系统中使用的长度单位可以是0 user用户,1 twip 缇、2 point 磅、3 pixel 像素、4 character 字符、5 inch 英寸、6 millimeter 毫米和7 centimeter 厘米。)</p>
<p>这段代码先备份好DG.Parent.ScaleMode(父窗体的ScaleMode) 然后把DG.Parent.ScaleMode设置为 twip 缇 .</p>
<p>maks = intField * intRecord [这是什么意思]</p>
<p>这句。。。把两个变量intField和intRecord相乘赋值给第三个变量maks,这里没有什么语句可以找到赋值的,</p>
<p>单从字面意思看,</p>
<p>intField表示字段的数量吧,可能int一般是Integer的缩写,Field字段。</p>
<p>intRecord可能表示记录数量,Record表示记录,一般用RecordCount表示记录数量。</p>
<p>那么这两个相乘就是表示所有记录*所有字段了</p>
<p>0</p>
<p>回答者:</p>
<p><img src="http://www.baidu.com/search/zhidao/zhuti-5year/image/icon1.gif"></p>
<p><img src="http://img.baidu.com/img/iknow/icon_huizhang.gif"></p>
<p>mosesmoses0651 - 九级   2010-7-1 09:37</p>
<p>我来评论>></p>
<p>提问者对于答案的评价:</p>
<p>非常感谢这位哥们,呵呵</p>
您需要登录后才可以回帖 登录 | 注册会员

本版积分规则

QQ|文字版|手机版|小黑屋|襄阳城

GMT+8, 2025-5-16 18:24

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表