Option Strict Off
發(fā)展壯大離不開廣大客戶長期以來的信賴與支持,我們將始終秉承“誠信為本、服務(wù)至上”的服務(wù)理念,堅持“二合一”的優(yōu)良服務(wù)模式,真誠服務(wù)每家企業(yè),認(rèn)真做好每個細(xì)節(jié),不斷完善自我,成就企業(yè),實現(xiàn)共贏。行業(yè)涉及會所設(shè)計等,在成都網(wǎng)站建設(shè)公司、營銷型網(wǎng)站建設(shè)、WAP手機網(wǎng)站、VI設(shè)計、軟件開發(fā)等項目上具有豐富的設(shè)計經(jīng)驗。
Option Explicit On
Friend Class Form1
Inherits System.Windows.Forms.Form
Private Sub Command1_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles Command1.Click
Dim j As Integer
Dim A(9) As Short
Dim D(9) As Short
Dim i As Short
Dim B As Short
Dim C As Short
Dim F As Short
Dim G As Boolean
Dim H() As Short
Dim K As Short
Dim S As String
C = 32767
For i = 1 To 10
A(i - 1) = CShort(InputBox("輸入第 " i "個數(shù)"))
If B A(i - 1) Then B = A(i - 1)
If C A(i - 1) Then C = A(i - 1)
D(i - 1) = Int(Rnd() * 100 + 0.5)
If F D(i - 1) Then F = D(i - 1)
Next i
For i = 2 To 100
For j = 2 To Int(System.Math.Sqrt(i) + 0.5)
'UPGRADE_WARNING: Couldn't resolve default property of object j. Click for more: 'ms-help://MS.VSExpressCC.v80/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
'UPGRADE_WARNING: Mod has a new behavior. Click for more: 'ms-help://MS.VSExpressCC.v80/dv_commoner/local/redirect.htm?keyword="9B7D5ADD-D8FE-4819-A36C-6DEDAF088CC7"'
If i Mod j 0 Then
G = True
Else
G = False
Exit For
End If
Next j
If G = True Then
ReDim Preserve H(K)
H(K) = i
K = K + 1
End If
Next i
S = "2;"
For i = 0 To K - 1
S = S H(i) ";"
Next i
MsgBox("最大數(shù)為:" B ";最小數(shù)為:" C)
MsgBox("最大的隨機數(shù)為:" F)
MsgBox("1--100之間共有" K + 1 "個素數(shù):" S)
End Sub
End Class
Dim?str?As?String?=?"",?temp,?n?As?Integer
Dim?str1?As?String?=?"12,45,2,9,41,31,66,83,2,1,-9,-91,-21"
Dim?a()?As?String?=?Split(str1,?",")
For?i?=?1?To?UBound(a)?Step?1
a(i)?=?Val(a(i))
Next
temp?=?0
n?=?0
For?i?=?1?To?UBound(a)
If?a(i)??temp?Then
temp?=?a(i)
End?If
If?a(i)??0?Then
n?=?n?+?1
End?If
Next
str?=?str??"正數(shù)的個數(shù)為?"??n
str?=?str??"最大元素的下標(biāo)為?"
For?i?=?1?To?UBound(a)
If?a(i)?=?temp?Then
str?=?str??i??"?"
End?If
Next
TextBox6.Text?=?str
1、點擊VS工具。
2、打開后,新建一個Windows窗體應(yīng)用程序。
3、新建完畢后,如圖所示。
4、拖動一個按鈕。
5、定義數(shù)組最常見的方法,如圖示。
6、運行后,點擊按鈕,彈出提示正常。
7、定義數(shù)組第二種方法,屬于動態(tài)的方法。
8、運行后,點擊按鈕,數(shù)組成功輸出。
private function maxnum(byval a() as integer) as integer
dim i as integer
maxnum=a(0)
for i = 1 to ubound(a)
if a(i)maxnum then maxnum=a(i)
next
end function
你是不是應(yīng)該對最大值和最小值賦初值(比如把 r(1) 賦給最大值和最小值)呢?不然最小值默認(rèn)初始值是‘0’,后面的判斷就不起作用了。你可以加個斷點試試,他們的初始值是多少。。。
'給數(shù)組賦值
dim d(6) as integer
d(1)=11
d(2)=32
d(3)=25
d(4)=45
d(5)=9
d(6)=5
'獲取最大值(采用打擂臺的思路)
dim MyMax as integer
dim i as integer
MyMax = d(1) '假設(shè)第1個元素最大
for i = 2 To Ubound(d) '從第2個元素開始到最后一個元素
'如果當(dāng)前元素比MyMax的值大,就把當(dāng)前元素保存到MyMax
if d(i) MyMax Then
MyMax = d(i)
end if
next i
msgbox MyMax