VB程式設計問題

時間 2021-07-01 02:02:50

1樓:匿名使用者

1/private sub command1_click()

vscroll1.value = 0

timer1.enabled = true

end sub

private sub form_load()

vscroll1.max = 100

vscroll1.min = 0

timer1.interval = 100

end sub

private sub timer1_timer()

vscroll1.value = vscroll1.value + 1

label1.caption = vscroll1.value

if vscroll1.value = 100 then

label1.caption = "水開了"

timer1.enabled = false

end if

end sub

2/基本的題目,自己試試

private sub command1_click()

dim n as integer

n = inputbox("輸入個數")

dim arr() as integer

redim arr(n - 1)

randomize

for i = 0 to n - 1

arr(i) = int(90 * rnd) + 10

print arr(i);

next i

print

if option1.value then

imax = 0

for i = 1 to n - 1

if arr(imax) < arr(i) then imax = i

next i

print "最大值"; arr(imax)

elseif option2.value then

imin = 0

for i = 1 to n - 1

if arr(imin) > arr(i) then imin = i

next i

print "最小值"; arr(imin)

elseif option3.value then

s = 0

for i = 0 to n - 1

s = s + arr(i)

next i

print "和"; s

elseif option4.value then

s = 0

for i = 0 to n - 1

s = s * arr(i)

next i

print "積"; s

elseif option5.value then

s = 0

for i = 0 to n - 1

s = s + arr(i)

next i

print "平均數"; s / n

elseif option6.value then

selectsort arr

for i = 0 to n - 1

print arr(i);

next i

end if

end sub

public sub swap(byref a, byref b)

'交換dim t

t = a: a = b: b = t

end sub

public sub selectsort(byref a, optional byval left, optional byval right)

'選擇排序

'基本思想是:每次選出第i小的記錄,放在第i個位置。

'i的起點是left。當i=right-1時就排完了。

dim i as integer, j as integer

dim k as integer

if ismissing(left) then left = lbound(a)

if ismissing(right) then right = ubound(a)

for i = left to right - 1

k = i

for j = i + 1 to right

if a(k) > a(j) then k = j

next j

if k <> i then swap a(k), a(i)

next i

end sub

3/public sub command1_click()

dim arr(14) as string

dim b(65 to 90) as boolean

for i = 0 to 14

do x = int(rnd * 26) + 65

loop while b(x)

b(x) = true

arr(i) = chr(x)

print arr(i);

next i

print

end sub

2樓:孤本輕狂

1.給你另一種方法。純**方式

option explicit

dim withevents pic as vb.picturebox

dim withevents shp as vb.shape

dim withevents command as vb.commandbutton

dim withevents timer as vb.timer

dim a as integer

private sub command_click()

timer.enabled = true

command.enabled = false

end sub

private sub form_load()

form1.height = 4000

form1.width = 3000

set pic = controls.add("vb.picturebox", "pic1", form1)

pic.left = 500

pic.top = 500

pic.width = 300

pic.height = 2000

pic.visible = true

set shp = controls.add("vb.shape", "shp1", pic)

shp.left = 0

shp.fillstyle = 0

shp.width = 300

shp.height = 0

shp.top = pic.height - shp.height

shp.fillcolor = vbgreen

shp.visible = true

set command = controls.add("vb.commandbutton", "command1", form1)

command.left = pic.left + pic.width + 300

command.top = pic.top + pic.height / 2

command.visible = true

command.caption = "開始"

set timer = controls.add("vb.timer", "timer1", form1)

timer.interval = 10

timer.enabled = false

end sub

private sub pic_click()

print "ok"

end sub

private sub timer_timer()

if a < 100 then

a = a + 1

if a > 90 then

shp.fillcolor = vbred

end if

shp.height = a * 20

shp.top = pic.height - shp.height

else

timer.enabled = false

print "水開了"

end if

end sub

2。dim n as integer

dim a() as integer

private function max(a() as integer, n as integer) as integer

dim temp as integer

temp = 0

for i = 1 to n

if temp < a(i) then temp = a(i)

next

max = temp

end function

private function min(a() as integer, n as integer) as integer

dim temp as integer

temp = 501

for i = 1 to n

if temp > a(i) then temp = a(i)

next

min = temp

end function

private function sum(a() as integer, n as integer) as double

dim temp as double

temp = 0

for i = 1 to n

temp = temp + a(i)

next

sum = temp

end function

private function mul(a() as integer, n as integer) as double

dim temp as double

temp = 1

for i = 1 to n

temp = temp * a(i)

next

mul = temp

end function

private sub px(a() as integer, n as integer)

dim temp as integer

for i = 1 to n - 1

for j = i to n

if a(i) < a(j) then

temp = a(i)

a(i) = a(j)

a(j) = temp

end if

next j

next i

text1.text = ""

for i = 1 to n

text1.text = text1.text + cstr(a(i)) + " "

next

end sub

private sub command1_click()

n = val(text2.text)

for i = 1 to n

redim preserve a(i) as integer

a(i) = int(rnd * 500)

next

end sub

private sub form_load()

dim s(6) as string

s(0) = "最大值"

s(1) = "最小值"

s(2) = "求 和"

s(3) = "求 積"

s(4) = "平均值"

s(5) = "排 序"

option1(0).caption = s(0)

for i = 1 to 5

load option1(i)

option1(i).top = option1(i - 1).top + 600

option1(i).visible = true

option1(i).caption = s(i)

next

load option1(6)

option1(6).value = true

text1.text = ""

text2.text = ""

end sub

private sub option1_click(index as integer)

select case index

case 0

text1.text = max(a(), n)

case 1

text1.text = min(a(), n)

case 2

text1.text = sum(a(), n)

case 3

text1.text = mul(a(), n)

case 4

text1.text = mul(a(), n) / n

case 5

call px(a(), n)

end select

end sub

VB程式設計問題,VB程式設計問題

dim a,b 定義兩個變體型變數a,b,在該模組範圍內有效 private sub form load 窗體載入事件觸發的函式 a picture1.width 記錄 框控制元件picture1的寬度到a變數 b picture1.height 記錄 框控制元件picture1的高度到b變數 hs...

vb程式設計,VB程式設計

大哥你這個問題很簡單,只不過在這裡不能把 全給你,你的問題描述的不清楚,我吧幾個關鍵的技術點告訴你 字型變化有font屬性來實現 按鈕始終在窗體又下放可以再窗體的form resize中設定 按鈕的top和left屬性讓他們分別 me.whith 50,me.heght 50 4 4個按鈕每單擊一次...

VB程式設計題(簡單),VB 程式設計題(簡單)

做個標記,等會發你郵箱 private sub form load timer1.interval 1000timer1.enabled trueend sub private sub timer1 timer if option1.value true then text1.text format...