数组代码中的问题...... [英] Problems in array code...

查看:68
本文介绍了数组代码中的问题......的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Private Sub Command1_Click()
Dim n As Integer, i As Integer, max As Integer


n = InputBox(" how many values to enter")
Dim arr(n) As Integer              // here is some problem n is not accepted


For i = 1 To n
arr(i) = InputBox("Enter number ")
Next
max = arr(1)
For i = 1 To n
If max < arr(i) Then
max = arr(i)
End If
Next
Print "maximum number is " & max





我的问题是如何在运行时获取数组大小



my question is that how to take size of array at run time

推荐答案

尝试这样:

Try like that:
Dim input As String = InputBox(" how many values to enter")
Dim n As Integer
If Not Int32.TryParse(input, n)
   '' Input was not an integer number
End If
Dim arr(n) As Integer



InputBox函数返回一个字符串,您必须将其转换为有效整数,以便将其用作数组大小的限定符。



希望这有帮助。


InputBox function returns a string, which you have to translate into a valid integer for it to be used as a qualifier for an array size.

Hope this helps.


试试这个:

Try this:
Private Sub Command1_Click()
Dim n As Integer, i As Integer, max As Integer
Dim arr(1) As Integer 

n = InputBox(" how many values to enter")
ReDim arr(n)





链接:

https://msdn.microsoft.com/en-us/library/cfkks19h%28v=vs.90%29.aspx [ ^ ]


这篇关于数组代码中的问题......的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆