首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > VB Dotnet >

vb.net 未将对象引用设置到对象的实例。该怎么解决

2012-03-14 
vb.net未将对象引用设置到对象的实例。Public Class Form1Dim a() As IntegerSub shuru(ByRef b() As Integ

vb.net 未将对象引用设置到对象的实例。
Public Class Form1
  Dim a() As Integer
  Sub shuru(ByRef b() As Integer)
  Dim n%, i%
  n = InputBox("请输入要比较的数字或字母的个数")
  For i = 0 To n - 1
  b(i) = InputBox("输入第" & i + 1 & " 个数字")
  MsgBox(b(i))
  Next

  End Sub
  Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

  Call shuru(a)

  End Sub
  Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

  Dim i%, j%, k%, temp%
  For i = 0 To UBound(a)
  For j = 0 To j - i - 1
  If (a(j) < a(j + 1)) Then
  temp = a(j)
  a(i) = a(j + 1)
  a(j + 1) = temp

  End If
  Next
  For k = 0 To UBound(a)
  Label1.Text &= a(k) & ","
  Next
  Label1.Text &= vbCrLf
  Next
  For i = 0 To UBound(a)
  TextBox1.Text &= a(i) & ","
  Next
  End Sub
End Class




未将对象引用设置到对象的实例。


[解决办法]

VB.NET code
        k = i 'i   '实际的可用串口总数        If k > 0 Then    '有一个以上串口就比较,出错则不管            Try                Dim t As Integer = 0                For i = 0 To k - 1                    For j = i + 1 To k - 1                        If portlis(j) < portlis(i) Then  '保证小的在数组的前面,排序                            t = portlis(j)                            portlis(j) = portlis(i)                            portlis(i) = t                        End If                    Next j                Next i                ComboBoxPortName.Items.Clear() '清空列表                For i = 0 To k - 1                    ComboBoxPortName.Items.Add("COM" + portlis(i).ToString)       '显示可用串口                Next i                If ComboBoxPortName.Items.Count > 0 Then                    ComboBoxPortName.SelectedIndex = 0                    '     有可用串口,可以打开操作                End If            Catch 'ex As Exception            End Try            ' Else            ' MsgBox("无可用串口!")        End If    '这是关于串口的冒泡排序法,作用将串口按数字大小排序,你    '可以参考下相关的部分
[解决办法]
VB.NET code
 ' n = InputBox("请输入要比较的数字或字母的个数") ReDim b(n)    '!!!!! please add this here ,HA HA 

热点排行