📄 vbtips10.htm
字号:
<html>
<head>
<meta http-equiv="Content-Type"
content="text/html; charset=gb_2312-80">
<meta name="GENERATOR" content="Microsoft FrontPage Express 2.0">
<title>VB技巧</title>
</head>
<body>
<h1 align="center"><a name="Return"></a>VB技巧<font size="5"><strong>(9)</strong></font></h1>
<blockquote>
<p><b>1 </b><a
href="#怎样加速数据库的访问速度?"><b>怎样加速数据库的访问速度?</b></a><b><br>
2 </b><a href="#怎么对付数据库中的空字符?"><font
face="宋体"><b>怎么对付数据库中的空字符?</b></font></a><font
face="宋体"><b><br>
</b></font><b>3 </b><a href="#怎样打开或关闭CD-ROM?"><font
face="宋体"><b>怎样打开或关闭CD-ROM?</b></font></a><font
face="宋体"><b><br>
</b></font><b>4 </b><a
href="#怎样使用VB程序退出Windows?"><font
face="宋体"><b>怎样使用VB程序退出Windows?</b></font></a><font
face="宋体"><b><br>
</b></font><b>5 </b><a
href="#怎样用VB断开与internet的连接?"><font
face="宋体"><b>怎样用VB断开与internet的连接?</b></font></a><font
face="宋体"><b><br>
</b></font><b>6 </b><a
href="#怎样用VB得知系统当前是否处于internet链结状态?"><font
face="宋体"><b>怎样用VB得知系统当前是否处于internet链结状态?</b></font></a><font
face="宋体"><b><br>
</b></font><b>7 </b><a href="#放置透明的图片"><strong>放置“透明”的图片
</strong></a><strong><br>
8 </strong><a href="#设置打印边距"><strong>设置打印边距</strong></a></p>
<div align="center"><center><table border="0" cellspacing="1"
width="88%">
<tr>
<td width="80%"><p align="left"><a
href="vbtips.htm#Return">[1]</a> <a
href="vbtips1.htm">[2]</a> <a href="vbtips2.htm">[3]</a>
<a href="vbtips3.htm">[4]</a> <a href="vbtips4.htm">[5]</a>
<a href="vbtips5.htm">[6]</a> <a href="vbtips7.htm">[7]</a>
<a href="vbtips7.htm">[8]</a> <a href="vbtips9.htm">[9]</a>
[10]</p>
</td>
<td><p align="right"><font size="2">第十页(共十页)</font></p>
</td>
</tr>
</table>
</center></div>
</blockquote>
<hr>
<div align="center"><center>
<table border="0" cellspacing="1" width="88%">
<tr>
<td width="100%"><a
name="怎样加速数据库的访问速度?"><b>怎样加速数据库的访问速度?</b></a><p
id="content">下面的窍门将教会你如何加速数据库的访问速度,当人们要读取一个数据库时往往会这么做:</p>
<p id="content"><font face="宋体">Do while not
records.eof</font></p>
<p id="content"><font face="宋体">combo1.additem
records![Full Name]</font></p>
<p id="content"><font face="宋体">records.movenext</font></p>
<p id="content"><font face="宋体">loop </font></p>
<p id="content">经常遇到的问题是每次数据库移动到下一条记录的时候,它必须检查是否到达文件底部,这将使数据的访问速度大打折扣。当你需要在一个巨大的数据库中移动或寻找时,最好是这样做:</p>
<p id="content"><font face="宋体">records.movelast</font></p>
<p id="content"><font face="宋体">intRecCount=records.RecordCount</font></p>
<p id="content"><font face="宋体">records.movefirstfor
intCounter=1 to intRecCount combo1.additem records![Full
Name]</font></p>
<p id="content"><font face="宋体">records.movenext</font></p>
<p id="content"><font face="宋体">next intCounter</font></p>
<p id="content">试试看,你将得到<font
face="宋体">33%</font>的速度提升!<br>
<a href="#Return">返回</a></p>
<p id="content"><a
name="怎么对付数据库中的空字符?"><font
face="宋体"><b>怎么对付数据库中的空字符?</b></font></a></p>
<p id="content"><font face="宋体">缺省时的数据库字段为空字符(并不是指一个字符串值为“空格”,而是什么也没有),当你读取这些字段的时候把它们赋值给VB的String变量,你就会得到“变量类型不匹配”的错误。最好的解决方法应当是嵌入一串空格和字段连接起来,请看下面的代码:</font></p>
<p id="content"><font face="宋体">Dim DB As Database</font></p>
<p id="content"><font face="宋体">Dim RS As Recordset</font></p>
<p id="content"><font face="宋体">Dim sYear As String </font></p>
<p id="content"><font face="宋体">Set DB =
OpenDatabase("Biblio.mdb")</font></p>
<p id="content"><font face="宋体">Set RS =
DB.OpenRecordset("Authors")</font></p>
<p id="content"><font face="宋体">sYear = ""
& RS![Year Born]<br>
</font><a href="#Return">返回</a></p>
<p id="content"><a name="怎样打开或关闭CD-ROM?"><font
face="宋体"><b>怎样打开或关闭CD-ROM?</b></font></a></p>
<p id="content"><font face="宋体">如果你想通过VB打开或者关闭CD-ROM,你可以向Windows
Multimedia DLL发出一条相关的命令请求,但是你必须先声明DLL:</font></p>
<p id="content"><font face="宋体">在模块文件中加入以下代码:</font></p>
<p id="content"><font face="宋体">Declare Function
mciSendString Lib "winmm.dll" Alias
_"mciSendStringA" (ByVal lpstrCommand As
String, ByVal _lpstrReturnString As String, ByVal
uReturnLength As Long, _</font></p>
<p id="content"><font face="宋体">ByVal hwndCallback As
Long) As Long </font></p>
<p id="content"><font face="宋体">以下是打开CD-ROM的过程代码:</font></p>
<p id="content"><font face="宋体">retvalue =
mcisendstring("set CDAudio door open", _</font></p>
<p id="content"><font face="宋体">returnstring, 127, 0)
</font></p>
<p id="content"><font face="宋体">关闭CD-ROM用以下代码:</font></p>
<p id="content"><font face="宋体">retvalue =
mcisendstring("set CDAudio door closed",
_returnstring, 127, 0) <br>
</font><a href="#Return">返回</a></p>
<p id="content"><a
name="怎样使用VB程序退出Windows?"><font
face="宋体"><b>怎样使用VB程序退出Windows?</b></font></a></p>
<p id="content"><font face="宋体">Public Const
EWX_LOGOFF = 0</font></p>
<p id="content"><font face="宋体">Public Const
EWX_SHUTDOWN = 1</font></p>
<p id="content"><font face="宋体">Public Const
EWX_REBOOT = 2</font></p>
<p id="content"><font face="宋体">Public Const
EWX_FORCE = 4</font></p>
<p id="content"><font face="宋体">Declare Function
ExitWindowsEx Lib "user32" Alias _</font></p>
<p id="content"><font face="宋体">"ExitWindowsEx"
(ByVal uFlags As Long, ByVal dwReserved _</font></p>
<p id="content"><font face="宋体">As Long) As Long</font></p>
<p id="content"><font face="宋体">退出Windows:</font></p>
<p id="content"><font face="宋体">t& =
ExitWindowsEx(EWX_FORCE OR EWX_REBOOT, 0)</font> <br>
<a href="#Return">返回</a></p>
<p id="content"><a
name="怎样用VB断开与internet的连接?"><font
face="宋体"><b>怎样用VB断开与internet的连接?</b></font></a></p>
<p id="content"><font face="宋体">如果你想终止与internet的连接,可以使用断开连接的方法,首先你必须声明以下函数和变量:</font></p>
<p id="content"><font face="宋体">Declarations</font></p>
<p id="content"><font face="宋体">Public Const
RAS_MAXENTRYNAME As Integer = 256Public Const
RAS_MAXDEVICETYPE As Integer = 16</font></p>
<p id="content"><font face="宋体">Public Const
RAS_MAXDEVICENAME As Integer = 128</font></p>
<p id="content"><font face="宋体">Public Const
RAS_RASCONNSIZE As Integer = 412Public Const
ERROR_SUCCESS = 0&</font></p>
<p id="content"><font face="宋体">Public Type
RasEntryName</font></p>
<p id="content"><font face="宋体">dwSize As Long</font></p>
<p id="content"><font face="宋体">szEntryName(RAS_MAXENTRYNAME)
As Byte</font></p>
<p id="content"><font face="宋体">End Type</font></p>
<p id="content"><font face="宋体">Public Type RasConn</font></p>
<p id="content"><font face="宋体">dwSize As Long</font></p>
<p id="content"><font face="宋体">hRasConn As Long</font></p>
<p id="content"><font face="宋体">szEntryName(RAS_MAXENTRYNAME)
As Byte</font></p>
<p id="content"><font face="宋体">szDeviceType(RAS_MAXDEVICETYPE)
As Byte</font></p>
<p id="content"><font face="宋体">szDeviceName(RAS_MAXDEVICENAME)
As Byte</font></p>
<p id="content"><font face="宋体">End Type</font></p>
<p id="content"><font face="宋体">Public Declare
Function RasEnumConnections Lib _</font></p>
<p id="content"><font face="宋体">"rasapi32.dll"
Alias "RasEnumConnectionsA" (lpRasConn As _</font></p>
<p id="content"><font face="宋体">Any, lpcb As Long,
lpcConnections As Long) As Long</font></p>
<p id="content"><font face="宋体">Public Declare
Function RasHangUp Lib "rasapi32.dll" Alias _</font></p>
<p id="content"><font face="宋体">"RasHangUpA"
(ByVal hRasConn As Long) As Long </font></p>
<p id="content"><font face="宋体">Public gstrISPName As
String</font></p>
<p id="content"><font face="宋体">Public ReturnCode As
Long</font></p>
<p id="content"><font face="宋体">断开过程:</font></p>
<p id="content"><font face="宋体">Public Sub HangUp()</font></p>
<p id="content"><font face="宋体">Dim i As Long</font></p>
<p id="content"><font face="宋体">Dim lpRasConn(255) As
RasConn</font></p>
<p id="content"><font face="宋体">Dim lpcb As Long</font></p>
<p id="content"><font face="宋体">Dim lpcConnections As
Long</font></p>
<p id="content"><font face="宋体">Dim hRasConn As Long</font></p>
<p id="content"><font face="宋体">lpRasConn(0).dwSize =
RAS_RASCONNSIZE</font></p>
<p id="content"><font face="宋体">lpcb =
RAS_MAXENTRYNAME * lpRasConn(0).dwSize</font></p>
<p id="content"><font face="宋体">lpcConnections = 0</font></p>
<p id="content"><font face="宋体">ReturnCode =
RasEnumConnections(lpRasConn(0), lpcb, _</font></p>
<p id="content"><font face="宋体">lpcConnections)</font></p>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -