帐号: 密码:
// 设为首页 // 收藏本站 // 请您留言 // 网址导航
远方教程-满足你的求知欲!
站内搜索:
HTML ASP PHP CSS DIV Dreamweaver Photoshop Word Excel PPT SEO技巧
您当前位置:网站首页 >> 统计之窗 >> VB专区 >> 阅读文章

VB基础教程第四章:VB程序设计

来源:远方教程 作者:VBFans 发布时间:2014-12-06 查看次数:13082 访问[新版]

  下面给出完整的程序代码:

Dim Num1, Num2 As Single
Dim StrNum1, StrNum2 As String
Dim FirstNum As Boolean ’判断是否是数字开头
Dim PointFlag As Boolean ’判断是否已有小数点
Dim Runsign As Integer ’储存运算符号
Dim SignFlag As Boolean ’判断是否已有运算符号

Sub ClearData()

  Num1 = 0
  Num2 = 0
  StrNum1 = ""
  StrNum2 = ""
  FirstNum = True
  PointFlag = False
  Runsign = 0
  SignFlag = False
  Text1.Text = "0."

End Sub

Sub Run()

  Num1 = Val(StrNum2)
  Num2 = Val(StrNum1)
  
Select Case Runsign
  
Case 1
    
equal = Num1 + Num2
  
Case 2
    
equal = Num1 - Num2
  
Case 3
    
equal = Num1 * Num2
  
Case 4
    
equal = Num1 / Num2
  
End Select
  
StrNum2 = Str(equal)
  
StrNum1 = StrNum2
  
Text1.Text = StrNum2

End Sub

Private Sub about_Click()

  MsgBox "Create by 周晓阳。1998/7/27", vbDefaultButton1, "VB教程第四章范例"

End Sub

Private Sub Command1_Click(Index As Integer)

  Select Case Index
  Case 0 To 9
  If FirstNum Then
    StrNum1 = Str(Index)
    FirstNum = False
  Else
    StrNum1 = StrNum1 + Str(Index)
  End If
  Text1.Text = StrNum1
  Case 10
  If Not PointFlag Then
    If FirstNum Then
      StrNum1 = "0."
      FirstNum = False
    Else
  
    StrNum1 = StrNum1 + "."
  
  End If
  Else
  
  Exit Sub
  End If

  PointFlag = True
  Text1.Text = StrNum1

  Case 12 To 15
    FirstNum = True
    PointFlag = False
    ’还原标记值
    If SignFlag Then
      Call Run
    Else
  
    SignFlag = True
      StrNum2 = StrNum1
      StrNum1 = ""
  
  End If
  
  Runsign = Index - 11
  
Case 11
  
  If Not SignFlag Then
      Text1.Text = StrNum1
    
  equal = Val(StrNum1)
    
  FirstNum = True
    
  PointFlag = False
  
  Else
    
  Call Run
    
  SignFlag = False
  
  End If
  Case Else
    Call ClearData
  End Select

End Sub

Private Sub Form_Load()

  Call ClearData

End Sub

感谢VBFans投稿查看TA的其他文章>>
打印 打印 | 关闭 关闭 评论
相关文章
图片新闻
站内搜索  
搜索
猜您喜欢  
最新更新  
阅读排行  
关于我们 | 联系方式 | 大事记 | 免责声明 | | 给我留言
部分广告源自金山联盟2345联盟 QQ咨询 站长之家QQ群:232617873
Copyright 2024 远方教程 © All Rights Reserved.

回顶部