-
VB 簡單定時**:
**如下:DIM S
private sub command1_click()= true
end sub
private sub command2_click()= false
end sub
private sub command3_click()= ""
s = 0end sub
private sub command4_click()endend sub
private sub form_load()= "綜合應用"
計時(秒):"
總經過時間(秒):"
開始使用" "停"
重新定時"關閉"s = = 1000
falsetrueend sub
private sub timer1_timer()s = s + 1
s= send sub
private sub timer2_timer()= now
end sub
-
讓我們做乙個計算器,很簡單,我沒有時間寫。
-
您的問題主要出在 for 迴圈中。
在第乙個迴圈中,rent=160,你直接將客戶數到3,即客戶=客戶-c
這個時候,客戶數量已經是77個了,用這個客戶數量來計算收入是錯誤的(因為當租金是160時,是80人,收入也是按照80人來計算的)。
應該先計算,然後客戶可以數到3。
這就像將 customer = customer - c 移動到 end if 之後的行一樣簡單。
此外,變數定義也是乙個問題。
dim sum, room, rent, customer, p, c, maintain as integer
這樣,只有maintain是整數,其他都是變體型別,如果要將它們全部定義為整數,則應編寫:
dim sum as integer, room as integer, rent as integer, customer as integer, p as integer, c as integer, maintain as integer
此外,p、c 和 maitain 都是固定的,建議將它們定義為常量(使用 const)。
-
dim sum, room, rent, customer, p, c, maintain as integer
dim last_sum, last_rent, last_room as integer
private sub command1_click()
last_sum = 0for rent = 160 to 1000 step p
room = customer
sum = rent * room - maintain * room
if last_sum < sum then
last_sum = sum
last_rent = rent
last_room = room
end if
customer = customer - c '把這句話放在這裡。
next rent
最高租金為:" & last_rent & "元; 最大房間數如下" & last_room & ";最高收入為:" & last_sum & "元; "
end sub
private sub form_load()
room = 80
customer = 80
rent = 160
maintain = 40
p = 20
c = 3end sub
兩個命令按鈕,兩個標籤,兩個文字"
private sub command1_click()r = >>>More
好問題,用 for 迴圈和判斷語句寫。
private sub command1_click()dim tuzi as integer >>>More