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

📄 class_book_begin065.htm

📁 关于VB开发的教程
💻 HTM
📖 第 1 页 / 共 2 页
字号:
        <p ALIGN="JUSTIFY"> </p>
        <p ALIGN="JUSTIFY"><font size="3" color="#004080"><em><strong>Private Sub Command1_Click()</strong></em></font></p>
        <blockquote>
          <p ALIGN="JUSTIFY"><font size="3" color="#004080"><em><strong>Unload Me</strong></em></font></p>
        </blockquote>
        <p ALIGN="JUSTIFY"><font size="3" color="#004080"><em><strong>End Sub</strong></em></font></p>
        <p ALIGN="JUSTIFY"> </p>
        <p ALIGN="JUSTIFY"><font size="3" color="#004080"><em><strong>Private Sub Text1_Change()</strong></em></font></p>
        <blockquote>
          <p ALIGN="JUSTIFY"><em><strong><font size="3" color="#004080">Dim StrLength As Integer</font><font size="3" color="#008000">’字符串长度</font></strong></em></p>
          <p ALIGN="JUSTIFY"><em><strong><font size="3" color="#004080">Dim RandomNum As Single</font><font size="3" color="#008000">’随机数</font></strong></em></p>
          <p ALIGN="JUSTIFY"><font size="3" color="#004080"><em><strong>Dim Str1 As String</strong></em></font></p>
          <p ALIGN="JUSTIFY"><font size="3" color="#004080"><em><strong>Dim a As String</strong></em></font></p>
          <p ALIGN="JUSTIFY"><font size="3" color="#004080"><em><strong>Dim i, Temp</strong></em></font></p>
          <p ALIGN="JUSTIFY"><em><strong><font size="3" color="#004080">StrLength = 0</font><font size="3" color="#008000">’每次开始时把字符串长度还原为0</font></strong></em></p>
          <p ALIGN="JUSTIFY"><font size="3" color="#004080"><em><strong>a = Text1.Text</strong></em></font></p>
          <p ALIGN="JUSTIFY"><em><strong><font size="3" color="#004080">For i = 1 To Len(a)</font><font size="3" color="#008000">’Len(a)代表字符串的长度</font></strong></em></p>
          <blockquote>
            <p ALIGN="JUSTIFY"><em><strong><font size="3" color="#004080">Temp = Asc(Mid$(a, i, 1))</font><font size="3" color="#008000">’挨个取字符</font></strong></em></p>
            <p ALIGN="JUSTIFY"><em><strong><font size="3" color="#004080">If Temp &gt; 255 Or Temp 
            &lt; 0 Then</font><font size="3" color="#008000">’不是ASC码</font></strong></em></p>
            <blockquote>
              <p ALIGN="JUSTIFY"><font size="3" color="#004080"><em><strong>StrLength = StrLength + 2</strong></em></font></p>
            </blockquote>
            <p ALIGN="JUSTIFY"><font size="3" color="#004080"><em><strong>Else</strong></em></font></p>
            <blockquote>
              <p ALIGN="JUSTIFY"><font size="3" color="#004080"><em><strong>StrLength = StrLength + 1</strong></em></font></p>
            </blockquote>
            <p ALIGN="JUSTIFY"><font size="3" color="#004080"><em><strong>End If</strong></em></font></p>
          </blockquote>
          <p ALIGN="JUSTIFY"><font size="3" color="#004080"><em><strong>Next i</strong></em></font></p>
          <p ALIGN="JUSTIFY"> </p>
          <p ALIGN="JUSTIFY"><font size="3" color="#004080"><em><strong>StrLength = StrLength / 2</strong></em></font></p>
          <p ALIGN="JUSTIFY"><font size="3" color="#004080"><em><strong>Select Case StrLength</strong></em></font></p>
          <blockquote>
            <p ALIGN="JUSTIFY"><font size="3" color="#004080"><em><strong>Case 0 To 9</strong></em></font></p>
            <blockquote>
              <p ALIGN="JUSTIFY"><font size="3" color="#004080"><em><strong>Picture1.Visible = True</strong></em></font></p>
              <p ALIGN="JUSTIFY"><font size="3" color="#004080"><em><strong>Picture2.Visible = False</strong></em></font></p>
              <p ALIGN="JUSTIFY"><font size="3" color="#004080"><em><strong>Picture3.Visible = False</strong></em></font></p>
              <p ALIGN="JUSTIFY"><font size="3" color="#004080"><em><strong>Label2.Caption = &quot;慢慢说。你还有&quot; 
              &amp; Str(30 - StrLength) &amp; &quot;个字可以说&quot;</strong></em></font></p>
              <p ALIGN="JUSTIFY"><font size="3" color="#004080"><em><strong>Level = 1</strong></em></font></p>
            </blockquote>
            <p ALIGN="JUSTIFY"><font size="3" color="#004080"><em><strong>Case 10 To 19</strong></em></font></p>
            <blockquote>
              <p ALIGN="JUSTIFY"><font size="3" color="#004080"><em><strong>If Level = 1 Then</strong></em></font></p>
              <blockquote>
                <p ALIGN="JUSTIFY"><font size="3" color="#004080"><em><strong>RandomNum = Rnd * 10’得到随机数</strong></em></font></p>
                <p ALIGN="JUSTIFY"><font size="3" color="#004080"><em><strong>If RandomNum &lt;= 10 And 
                RandomNum &gt; 9 Then</strong></em></font></p>
                <p ALIGN="JUSTIFY"><font size="3" color="#004080"><em><strong>Text1.Enabled = False</strong></em></font></p>
                <p ALIGN="JUSTIFY"><font size="3" color="#004080"><em><strong>Label2.Caption = &quot;很抱歉这是个误会……&quot;</strong></em></font></p>
                <p ALIGN="JUSTIFY"><font size="3" color="#004080"><em><strong>Command1.Visible = True</strong></em></font></p>
                <p ALIGN="JUSTIFY"><font size="3" color="#004080"><em><strong>Command1.Caption = &quot;您可以离开了&quot;</strong></em></font></p>
              </blockquote>
              <p ALIGN="JUSTIFY"><font size="3" color="#004080"><em><strong>End If</strong></em></font></p>
              <p ALIGN="JUSTIFY"><font size="3" color="#004080"><em><strong>Level = 2</strong></em></font></p>
              <p ALIGN="JUSTIFY"><font size="3" color="#004080"><em><strong>Else</strong></em></font></p>
              <blockquote>
                <p ALIGN="JUSTIFY"><font size="3" color="#004080"><em><strong>Picture1.Visible = False</strong></em></font></p>
                <p ALIGN="JUSTIFY"><font size="3" color="#004080"><em><strong>Picture2.Visible = True</strong></em></font></p>
                <p ALIGN="JUSTIFY"><font size="3" color="#004080"><em><strong>Picture3.Visible = False</strong></em></font></p>
                <p ALIGN="JUSTIFY"><font size="3" color="#004080"><em><strong>Str1 = &quot;怎么还没说完!&quot;</strong></em></font></p>
                <p ALIGN="JUSTIFY"><font size="3" color="#004080"><em><strong>Label2.Caption = Str1 &amp; 
                &quot;你还有&quot; &amp; Str(30 - StrLength) &amp; &quot;个字可以说&quot;</strong></em></font></p>
              </blockquote>
              <p ALIGN="JUSTIFY"><font size="3" color="#004080"><em><strong>End If</strong></em></font></p>
            </blockquote>
            <p ALIGN="JUSTIFY"><font size="3" color="#004080"><em><strong>Case 20 To 29</strong></em></font></p>
            <blockquote>
              <p ALIGN="JUSTIFY"><font size="3" color="#004080"><em><strong>If Level = 2 Then</strong></em></font></p>
              <blockquote>
                <p ALIGN="JUSTIFY"><font size="3" color="#004080"><em><strong>RandomNum = Rnd * 10</strong></em></font></p>
                <p ALIGN="JUSTIFY"><font size="3" color="#004080"><em><strong>If RandomNum &lt;= 10 And 
                RandomNum &gt; 9 Then</strong></em></font></p>
                <p ALIGN="JUSTIFY"><font size="3" color="#004080"><em><strong>Text1.Enabled = False</strong></em></font></p>
                <p ALIGN="JUSTIFY"><font size="3" color="#004080"><em><strong>Label2.Caption = &quot;很抱歉这是个误会……&quot;</strong></em></font></p>
                <p ALIGN="JUSTIFY"><font size="3" color="#004080"><em><strong>Command1.Visible = True</strong></em></font></p>
                <p ALIGN="JUSTIFY"><font size="3" color="#004080"><em><strong>Command1.Caption = &quot;您可以离开了&quot;</strong></em></font></p>
              </blockquote>
              <p ALIGN="JUSTIFY"><font size="3" color="#004080"><em><strong>End If</strong></em></font></p>
              <p ALIGN="JUSTIFY"><font size="3" color="#004080"><em><strong>Level = 3</strong></em></font></p>
              <p ALIGN="JUSTIFY"><font size="3" color="#004080"><em><strong>Else</strong></em></font></p>
              <blockquote>
                <p ALIGN="JUSTIFY"><font size="3" color="#004080"><em><strong>Picture1.Visible = False</strong></em></font></p>
                <p ALIGN="JUSTIFY"><font size="3" color="#004080"><em><strong>Picture2.Visible = False</strong></em></font></p>
                <p ALIGN="JUSTIFY"><font size="3" color="#004080"><em><strong>Picture3.Visible = True</strong></em></font></p>
                <p ALIGN="JUSTIFY"><font size="3" color="#004080"><em><strong>Str1 = &quot;我已经不耐烦了!&quot;</strong></em></font></p>
                <p ALIGN="JUSTIFY"><font size="3" color="#004080"><em><strong>Label2.Caption = Str1 &amp; 
                &quot;你还有&quot; &amp; Str(30 - StrLength) &amp; &quot;个字可以说&quot;</strong></em></font></p>
              </blockquote>
              <p ALIGN="JUSTIFY"><font size="3" color="#004080"><em><strong>End If</strong></em></font></p>
            </blockquote>
            <p ALIGN="JUSTIFY"><font size="3" color="#004080"><em><strong>Case Else</strong></em></font></p>
            <blockquote>
              <p ALIGN="JUSTIFY"><font size="3" color="#004080"><em><strong>Text1.Enabled = False</strong></em></font></p>
              <p ALIGN="JUSTIFY"><font size="3" color="#004080"><em><strong>Label2.Caption = &quot;你已经没有机会了!&quot;</strong></em></font></p>
              <p ALIGN="JUSTIFY"><font size="3" color="#004080"><em><strong>Command1.Visible = True</strong></em></font></p>
              <p ALIGN="JUSTIFY"><font size="3" color="#004080"><em><strong>Command1.Caption = &quot;交钱吧,肇事犯!&quot;</strong></em></font></p>
            </blockquote>
          </blockquote>
          <p ALIGN="JUSTIFY"><font size="3" color="#004080"><em><strong>End Select</strong></em></font></p>
        </blockquote>
        <p ALIGN="JUSTIFY"><font size="3" color="#004080"><em><strong>End Sub</strong></em></font></p>
        <p ALIGN="JUSTIFY"><img src="06-07.gif" alt="06-07(岂有此理)" WIDTH="416" HEIGHT="321"></p>
        <p ALIGN="JUSTIFY"><font size="3">中间有几个函数需要解释一下:</font></p>
        <blockquote>
          <p ALIGN="JUSTIFY"><font size="3" color="#FF0000"><em><strong>Mid可以从字符串中取出一部分,返回字符型,格式:</strong></em></font></p>
          <p ALIGN="JUSTIFY"><font size="3" color="#FF0000"><em><strong>Mid(字符串,从第几个字符开始,取字符的长度)</strong></em></font></p>
          <p ALIGN="JUSTIFY"><font size="3" color="#FF0000"><em><strong>Asc可以把字符转换为ASCII码,格式:</strong></em></font></p>
          <p ALIGN="JUSTIFY"><font size="3" color="#FF0000"><em><strong>Asc(字符串)</strong></em></font></p>
          <p ALIGN="JUSTIFY"><font size="3" color="#FF0000"><em><strong>Rnd,取得大于0但小于1 
          的数值,可以没有参数。</strong></em></font></p>
        </blockquote>
        <p ALIGN="JUSTIFY"><font size="3">怎么样,十分简单吧,我们将在下一次继续讨论VB的输入机制,再见!</font></p>
        <p ALIGN="JUSTIFY"> </p>
        <p ALIGN="JUSTIFY"><font size="3">第六章完</font></td>
      </tr>
    </table>
    </center></div><p align="right"><strong><a href="#top"><img src="top2.gif" border="0" WIDTH="27" HEIGHT="30"></a></strong></td>
  </tr>
</table>
</center></div>

<p> </p>
</body>
</html>
<!--webbot bot="HTMLMarkup" TAG="XBOT" StartSpan --></SCRIPT><!--webbot BOT="HTMLMarkup" endspan -->

⌨️ 快捷键说明

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