VB练习

1、VB三角形,杨辉三角

   For i = 1 To 9
        For j = 1 To 9 - i
           Print Spc(1);
        Next j
        
        For h = 1 To 2 * i - 1
            Print Trim(9 - i + 1);
        Next h
        Print
    Next i
2、计算 1/1! + 1/2! + ... + 1/n! 的值
    Dim t, sum As Double
    Dim temp As Integer
    
    n = InputBox("输入")
    t = 1
    sum = 0
    For i = 1 To n
        temp = 1
        For t = 1 To i
        
            temp = temp * t
        
        Next t
        sum = sum + 1 / temp
    Next i
    Print sum
	
	
	Dim t, sum As Double
    
    n = InputBox("输入")
    t = 1
    sum = 0
    For i = 1 To n
       t = t * i
       sum = sum + 1 / t
    Next i
    Print sum
	
    
Dim n As Integer, s As Single, x As Integer
 s = 0
 x = 1
n = Int(InputBox("输入一个数"))
For i = 1 To n
x = x * i
s = s + 1 / x
Next i
Print s
可以试下这两段代码,很神奇哦

3、统计文本框内单词个数
    

Private Sub Command1_Click()

Dim a, b, c As Variant
Dim flag As Boolean

Dim i As Integer, intWordCount As Integer
a = Split(Text1.Text)

intWordCount = 0
For i = 0 To UBound(a)
    If a(i) <> "" Then
        flag = True
        b = a(i)
        For j = 1 To Len(a(i))
            c = Mid(b, j, 1)
           ' If (Asc(c) >= 97 And Asc(c) <= 122) Or (Asc(c) >= 65 And Asc(c) <= 90) Then
                
            'End If
             If Asc(c) > 80 And Asc(c) < 89 Then
                flag = False
            End If
        Next j
        If (flag) Then
         intWordCount = intWordCount + 1
        End If
     'intWordCount = intWordCount + 1
    End If
Next i
MsgBox intWordCount & "个单词"
End Sub

4、动态的缓慢的加载图片
    

Private Sub Form_Load()
    Picture1.Visible = False
    Picture1.Picture = LoadPicture("E:/tt.jpg")
    Timer1.Enabled = True
    Picture1.Height = 0
    Timer1.Interval = 1000
End Sub

Private Sub Timer1_Timer()
    Dim a As Integer
    Picture1.Visible = True
    If (Timer1.Enabled) Then

     Picture1.Height = Picture1.Height + 100
     If (Picture1.Height > 3000) Then Timer1.Enabled = False
     End If
 
End Sub

 

知识共享许可协议
《VB练习》常伟华 创作。
采用 知识共享 署名-相同方式共享 3.0 中国大陆 许可协议进行许可。
相邻依据:发表时间
  • 多说评论
  • 签名
  • 新浪微博
  • 默认评论
  • Tab Header 5

0 条评论 / 点击此处发表评论

Tab Content 5

开发技术


开发平台和工具

sitemap     150.56ms