⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ba59.htm

📁 VB教程
💻 HTM
📖 第 1 页 / 共 2 页
字号:
<HTML>
<HEAD>
<TITLE>如何用VisualBasic编写小型的网络系统 </TITLE>
 
<META content="text/html; charset=gb2312" http-equiv=Content-Type>
 
</head>
<p align="center"><script src="../../1.js"></script></a>
<BODY topMargin=4 vLink=#0000ff>
<TABLE border=0 cellPadding=0 cellSpacing=0 width="100%">
  <TBODY>
  <TR>
    <TD height="52"> 
      <DIV align=center>
      <CENTER>
          <table border=0 cellpadding=0 cellspacing=0 width=679 align="center">
            <tbody> 
            <tr> 
              <td width=200 height="59"> 
                 
    </TD></TR><!--msnavigation--></TBODY></TABLE>
<table border=0 cellpadding=0 cellspacing=0 width="100%">
  <tbody> 
  <tr><!--msnavigation--><td valign=top height="123"> 
      <div align=center> 
        <table border=1 bordercolor=#b9d9ff cellpadding=0 cellspacing=0 
      class=table width=755>
          <center>
            <tr> 
               
              <td width="100%" height="14"> 
                <div align="center"> <strong><b>如何用Visual 
                  Basic编写小型的网络系统</b> </strong></span></div>
              </td>
            </tr>
            <tr> 
              <td 
            width="100%" class="unnamed1" height="124"> 
                <div align="left">
                  <p align="center">&nbsp;</p>
                  <p align="left">   <font size="-1" face="宋体">Visual Basic 以 
                    下 简 称(VB) 十 一 个 功 能 强 大 的 编 程 语 言。 特 别 是4.0 以 后, 支 持 了OLE 
                    Automation 技 术, 给 编 程 带 来 了 更 大 的 方 便。 前 些 时, 我 试 着 编 写 一 
                    个 支 持 网 络 的 数 据 库。 但 是 由 于 没 有 联 网, 所 以 没 法 测 试。 于 是, 我 想 
                    到 了OLE Automation, 用 它 就 可 以 在 一 台 机 器 上 测 试 网 络 功 能。 经 过 
                    改 动, 还 可 以 用 它 通 过Modem 来 进 行 联 机。 下 面, 我 介 绍 一 下 如 何 用Visual 
                    Basic 编 写 小 型 的 网 络 系 统。&nbsp;<br>
                    <br>
                       首 先, 建 立 一 个 支 持 网 络OLE Automation&nbsp;<br>
                    <br>
                       启 动VB。 在 窗 体Form1 中 建 立 一 个 列 表 框List 1, 在 它 上 面 建 一 个Frame1, 
                    设 置 它 的Caption 属 性 为 空。 在 它 中 间 建 立 一 个Label1, 同 样, 设 置 它 
                    的Caption 也 为 空。 最 后, 在List1 上 建 立 一 个Caption 为UserList 的Label2。 
                    最 后, 把 一 个 定 时 器Timer1 安 上, 把 它 的Interval 设 为3000,Enabled 
                    设 为False 就 行 了。 至 此,NetWorkConnection 的 窗 体 部 分 就 完 成 了。<br>
                    <br>
                       随 后, 在VB 的Tools 菜 单 中 选Options, 按 照 填 好 各 项 内 容。&nbsp;<br>
                    <br>
                       接 下 来, 在Insert 菜 单 中 选 取Module 建 立 一 个 新 的 模 块Module1。 
                    在(General) 中 输 入 填 写 进 下 列 代 码。&nbsp;<br>
                    <br>
                    (UserInfo数据类型)<br>
                    Type UserInfo<br>
                    Username As String<br>
                    Alias As Integer&nbsp;<br>
                    End Type<br>
                    (最大的用户数)<br>
                    Public Const MaxUser = 10<br>
                    (定义消息)<br>
                    Public Const Msg_User_LogOn = 1<br>
                    Public Const Msg_User_LogOff = 2<br>
                    (设定数据类型)<br>
                    Public Users (MaxUser) As UserInfo<br>
                    Public Inbox (MaxUser) As String<br>
                    Public UserSystemInbox As Integer<br>
                    Public Online(MaxUser) As Boolean<br>
                    <br>
                    Sub main()<br>
                    Form1.Show<br>
                    End Sub<br>
                    <br>
                       UserInfo 数 据 类 型 记 录 了 已 经 登 录 的 用 户 的 用 户 名 和&nbsp;<br>
                    别 名。 在 显 示 和 通 讯 时 只 使 用 别 名。 用 户 名 只 作 为 判 断&nbsp;<br>
                    用 户 是 否 有 效 时 用。 出 于 安 全 考 虑, 以 上 数 据 用 户 不 能&nbsp;<br>
                    随 意 访 问, 必 须 通 过 下 面 的 子 程 序 来 访 问。&nbsp;<br>
                    <br>
                       在Insert 菜 单 中 选 取Class Module 建 立 一 个 新 的 类Class1。&nbsp;<br>
                    更 名 为Common, 并 设 置 它 的 各 个 属 性。&nbsp;<br>
                    <br>
                       填 写 进 下 列 代 码。&nbsp;<br>
                    <br>
                       ( 提 供 获 取 用 户ID 值 的 功 能, 用 户 可 以 通 过 此 功 能 使&nbsp;<br>
                    用 别 名 来 返 回ID 值)&nbsp;<br>
                    <br>
                    Public Function GetUserID(Alias As String) As Integer<br>
                    For i = 1 To MaxUser<br>
                    If Users(i).Alias = Alias Then GetUserID = i<br>
                    Next i<br>
                    End Function<br>
                    <br>
                       ( 提 供 获 得 系 统 信 息 的 功 能。 用 户 可 以 通 过 它 了 解&nbsp;<br>
                    用 户 是 否 有 改 动)&nbsp;<br>
                    <br>
                    Public Function GetSystemMessage() As Integer<br>
                    GetSystemMessage = UserSystemInbox<br>
                    End Function<br>
                    <br>
                       ( 提 供 获 得 用 户 信 息 的 功 能。 用 它 来 获 取 所 有 在 线&nbsp;<br>
                    用 户 的 别 名, 中 间 用&quot;|&quot; 分 开。)&nbsp;<br>
                    <br>
                    Public Function GetUserInfo() As String<br>
                    For i = 1 To MaxUser<br>
                    If Users(i).Username &lt; &gt; &quot;&quot; Then<br>
                    temp = temp + Users(i).Alias + &quot;|&quot;<br>
                    End If<br>
                    Next i<br>
                    GetUserInfo = temp<br>
                    End Function<br>
                    <br>
                       ( 提 供 获 得 用 户 私 有 信 息 的 功 能。 用 来 接 受 别 的 用&nbsp;<br>
                    户 发 送 的 信 息。)&nbsp;<br>
                    <br>
                    Public Function GetUserMessage(ID As Integer) As String<br>
                    If ID &lt; = 0 Or ID &gt; MaxUser Then<br>
                    Exit Function<br>
                    End If<br>
                    GetUserMessage = Inbox(ID)<br>
                    End Function<br>
                    <br>
                       ( 提 供 注 销 功 能。 用 来 退 出 网 络。)&nbsp;<br>
                    <br>
                    Public Function LogOff(ID As Integer) As Boolean<br>
                    If ID &lt; = 0 Or ID &gt; MaxUser Then<br>
                    LogOff = False<br>
                    Exit Function<br>
                    End If<br>
                    If Users(ID).Username &lt; &gt; &quot;&quot; Then<br>
                    Users(ID).Username = &quot;&quot;<br>
                    LogOff = True<br>
                    Else<br>
                    LogOff = False<br>
                    End If<br>
                    UserSystemInbox = Msg_User_LogOff<br>
                    `      -- Update Form1       <br>
                    For i = 0 To Form1.List1.ListCount - 1<br>
                    If Form1.List1.List(i) = Users(ID).Alias Then&nbsp;<br>
                    `查找List1中的用户别名并删除<br>
                    Form1.List1.RemoveItem i<br>
                    Exit For<br>
                    End If<br>
                    Next i<br>
                    If Form1.List1.ListCount = 0 Then `如果没有用户登录<br>
                    Form1.Label1.Caption = &quot;DisConnected&quot;<br>
                    Form1.timer1.Enabled = False<br>
                    End If<br>
                    End Function<br>
                    <br>
                       ( 提 供 登 录 功 能 来 上 网)&nbsp;<br>
                    <br>
                    Public Function LogOn(Username As String,<br>
                    Alias As String) As Integer<br>
                    For i = 1 To MaxUser<br>
                    If Users(i).Username = &quot;&quot; Then<br>
                    Users(i).Username = Username<br>
                    Users(i).Alias = Alias<br>
                    LogOn = i<br>
                    UserSystemInbox = Msg_User_LogOn `发送&quot;用户登录&quot;信息<br>
                    `      -- Update Form1       <br>
                    Form1.List1.AddItem Alias `有用户上网<br>
                    Form1.Label1.Caption = &quot;Connected&quot;<br>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -