如何用vb制作計(jì)數(shù)器
作者:化工綜合網(wǎng)發(fā)布時(shí)間:2023-01-06分類:聚合物瀏覽:291
如何用vb制作計(jì)數(shù)器
使用數(shù)組 和 結(jié)構(gòu)體
相應(yīng)的數(shù)據(jù)類型自己看看哪個(gè)最合適就用哪個(gè),下面的例子全部用long,初始數(shù)據(jù)用100個(gè)隨機(jī)數(shù)
Option Explicit
Private Type dd
d1 As Long '存儲(chǔ)出現(xiàn)的數(shù)
d2 As Long '存儲(chǔ)出現(xiàn)次數(shù)
End Type
Private Sub Form_Load()
Me.AutoRedraw = True
Me.Width = 10000
Me.Height = 4500
Dim aa() As dd
Dim bb() As Long '原始數(shù)字的數(shù)組
Dim i, j, k, l, m As Long
ReDim aa(0)
k = 100 '隨機(jī)數(shù)個(gè)數(shù)
l = 500 '最大隨機(jī)數(shù)
m = 100 '最小隨機(jī)數(shù)
ReDim bb(k) As Long
'生成隨機(jī)數(shù),存儲(chǔ)在bb里面
Randomize
For i = 0 To k - 1
bb(i) = Int(((l - m) * Rnd) + m)
Next i
'統(tǒng)計(jì)bb里面各個(gè)數(shù)字出現(xiàn)次數(shù)
For i = 0 To UBound(bb) - 1
For j = 0 To UBound(aa) - 1
If aa(j).d1 = bb(i) Then
aa(j).d2 = aa(j).d2 + 1
Exit For
End If
Next j
If j >= UBound(aa) Then
ReDim Preserve aa(j + 1) As dd
aa(j).d1 = bb(i)
aa(j).d2 = 1
End If
Next i
'輸出出現(xiàn)數(shù)字及次數(shù)
Me.Print 數(shù)字, 出現(xiàn)次數(shù), 數(shù)字, 出現(xiàn)次數(shù), 數(shù)字, 出現(xiàn)次數(shù), 數(shù)字, 出現(xiàn)次數(shù)
For i = 0 To UBound(aa) - 1
Me.Print aa(i).d1, aa(i).d2,
If i Mod 4 = 3 Then Me.Print '設(shè)置輸出格式
Next i
End Sub
直接新建exe,復(fù)制黏貼就可以運(yùn)行了
單片機(jī)中計(jì)數(shù)器怎么做?
外加顯示的,延時(shí)查表自己寫
ORG 0000H
MAIN:MOV 30H,#00;(給 30H_40H付值)
MOV 31H,#00
MOV 32H,#00
MOV 33H,#00
MOV 34H,#00
MOV 35H,#00
MOV 36H,#00
MOV 37H,#00
L3: CALL L1 ;(調(diào)用子程序)
CALL DELAY2 ;(延時(shí))
INC 30H ;(將30中值遞增1)
MOV A,30H ;( 將30H)
CJNE A,#0AH,L3
MOV 30H,#0
INC 31H
ACALL L1
MOV A,31H
CJNE A,#06H,L3
MOV 31H,#0
INC 32H
ACALL L1
MOV A,32H
CJNE A,#0AH,L3
MOV 32H,#0
INC 33H
ACALL L1
MOV A,33H
CJNE A,#06H,L3
MOV 33H,#0
INC 34H
ACALL L1
MOV A,34H
CJNE A,#0H,L3
MOV 34H,#0
INC 35H
ACALL L1
MOV A,35H
CJNE A,#02H,L3
L4: ACALL L1
CALL DELAY2
INC 34H
ACALL L1
CALL DELAY2
MOV A,34H
CJNE A,#04H,L4
MOV P1,#0
JMP MAIN
L1: MOV DPTR,#TABLE
MOV A,30H
MOVC A,@A+DPTR
MOV P1,A
CLR P0.0
CALL DELAY
SETB P0.0
MOV A,31H
MOVC A,@A+DPTR
MOV P1,A
CLR P0.1
CALL DELAY
SETB P0.1
MOV A,32H
MOVC A,@A+DPTR
MOV P1,A
CLR P0.2
CALL DELAY
SETB P0.2
MOV A,33H
MOVC A,@A+DPTR
MOV P1,A
CLR P0.3
CALL DELAY
SETB P0.3
MOV A,34H
MOVC A,@A+DPTR
MOV P1,A
CLR P0.4
CALL DELAY
SETB P0.4
MOV A,35H
MOVC A,@A+DPTR
MOV P1,A
CLR P0.5
CALL DELAY
SETB P0.5
MOV A,36H
MOVC A,@A+DPTR
MOV P1,A
CLR P0.6
CALL DELAY
SETB P0.6
MOV A,37H
MOVC A,@A+DPTR
MOV P1,A
CLR P0.7
CALL DELAY
SETB P0.7
RET
END
- 聚合物排行
- 最近發(fā)表