Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Arrays 从数组中删除行_Arrays_Vb.net_Lines_Vb Power Pack - Fatal编程技术网

Arrays 从数组中删除行

Arrays 从数组中删除行,arrays,vb.net,lines,vb-power-pack,Arrays,Vb.net,Lines,Vb Power Pack,我有一个数组的线,我想在某个点上删除其中一些。 下面是代码示例: Dim canvas As New Microsoft.VisualBasic.PowerPacks.ShapeContainer Dim lines(20) As PowerPacks.LineShape Dim it As Integer = 0 Private Sub GoldenSpi_Load(sender As Object, e As EventArgs) Handles MyBase.Load canva

我有一个数组的线,我想在某个点上删除其中一些。 下面是代码示例:

Dim canvas As New Microsoft.VisualBasic.PowerPacks.ShapeContainer
Dim lines(20) As PowerPacks.LineShape
Dim it As Integer = 0

Private Sub GoldenSpi_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    canvas.Parent = Me
    lines.Initialize()
    iter.Text = 0
End Sub
Private Sub iter_TextChanged(sender As Object, e As EventArgs) Handles iter.TextChanged
   If (it > iter.Text And iter.Text <> 0) Then
        ReDim Preserve lines(iter.Text - 1)
   End If
   If (it <> iter.Text) Then
        it = iter.Text
   End If

   For i As Integer = 1 To iter.Text
      lines(i - 1) = New PowerPacks.LineShape(canvas)
      lines(i - 1).StartPoint = pA(i)
      lines(i - 1).EndPoint = pB(i)
      lines(i - 1).BringToFront()
   Next
End Sub
Dim canvas作为新的Microsoft.VisualBasic.PowerPacks.ShapeContainer
将线路(20)调整为电源组。LineShape
将其设置为整数=0
私有子GoldenSpi_Load(发送方作为对象,e作为事件参数)处理MyBase.Load
canvas.Parent=Me
line.Initialize()
iter.Text=0
端接头
私有子iter_TextChanged(发送方作为对象,e作为事件参数)处理iter.TextChanged
如果(it>iter.Text和iter.Text 0),那么
ReDim保留行(iter.Text-1)
如果结束
如果它(iter.Text)那么
it=iter.Text
如果结束
对于i作为整数=1到iter.Text
线条(i-1)=新的电源组。线条形状(画布)
行(i-1)。起始点=pA(i)
线(i-1)。端点=pB(i)
线(i-1).布林托夫隆()
下一个
端接头
在我执行程序之后,就创建了行。但是,当我给文本框的值小于变量“it”时,它只是删除最后一行,而不是其余的。在调试时,我还看到阵列的大小减小了。这意味着超出尺寸的内容仍然保留?为什么?。感谢您的帮助。谢谢

编辑:我试图创建如下列表:

Dim lines As New Generic.List(Of PowerPacks.LineShape)

Private Sub iter_ValueChanged(blabla) Handles iter.ValueChanged
    If (it > iter.Value And iter.Value <> 0) Then
        lines.RemoveRange(iter.Value - 1, lines.Count - iter.Value)
   End If

   For i As Integer = 1 To iter.Value
      InitPoints()

      If i - 1 = lines.Count Then
        Dim line As New PowerPacks.LineShape
        With line
            .StartPoint = pA(i)
            .EndPoint = pB(i)
            .BringToFront()
            .Parent = canvas
        End With
        lines.Add(line)
      End If
   Next

End Sub
Dim it As Integer = 0
Dim lines As New List(Of PowerPacks.LineShape)()

Sub iter_TextChanged(sender As Object, e As EventArgs) Handles iter.TextChanged
    Dim iTxt As Integer

    Try 
        iTxt = Integer.Parse(iter.Text)

        If it > iTxt AndAlso iTxt <> 0 Then

        End If

    Catch ex As Exception
        MessageBox.Show(ex.Message)
    End Try

End Sub
Dim line作为新的Generic.List(电源组的LineShape)
私有子iter_ValueChanged(blabla)处理iter.ValueChanged
如果(it>iter.Value和iter.Value为0),则
lines.RemoveRange(iter.Value-1,lines.Count-iter.Value)
如果结束
对于i,作为整数=1到iter.值
InitPoints()
如果i-1=行,则计数
将线路调暗为新的PowerPacks.LineShape
用线
.StartPoint=pA(i)
.EndPoint=pB(i)
.BringToFront()
.Parent=画布
以
行。添加(行)
如果结束
下一个
端接头

但这些线条在表单中仍然可见。我调试了它,发现列表的大小减小了。同样的问题,当我有一个数组。发生了什么?..

我建议将
iter.Text
更改为
cint(iter.Text)
,因为它可能会将两个值作为文本进行比较(比较方式不同)

我还建议将
Dim line(20)更改为PowerPacks.LineShape
,将
Dim line更改为新的generic.list(PowerPacks.LineShape)


这样,您就不必担心
ReDim Preserve
(在循环中执行时可能会很慢),而且如果您在项目中使用
选项Strict On
,您可以轻松地将项目插入到任何索引中,以避免类型之间的隐式转换,这可能会导致错误,或者更糟,意外的行为

另一方面,除非有必要,否则您不应该使用
文本框来存储数字。例如,使用
NumericUpDown
。请看下面的图片

现在,对于数组,我建议使用,它实现了处理元素所需的所有方法,并且有一个
.ToArray()
方法,如果需要,它将为您提供数组

试着这样做:

Dim lines As New Generic.List(Of PowerPacks.LineShape)

Private Sub iter_ValueChanged(blabla) Handles iter.ValueChanged
    If (it > iter.Value And iter.Value <> 0) Then
        lines.RemoveRange(iter.Value - 1, lines.Count - iter.Value)
   End If

   For i As Integer = 1 To iter.Value
      InitPoints()

      If i - 1 = lines.Count Then
        Dim line As New PowerPacks.LineShape
        With line
            .StartPoint = pA(i)
            .EndPoint = pB(i)
            .BringToFront()
            .Parent = canvas
        End With
        lines.Add(line)
      End If
   Next

End Sub
Dim it As Integer = 0
Dim lines As New List(Of PowerPacks.LineShape)()

Sub iter_TextChanged(sender As Object, e As EventArgs) Handles iter.TextChanged
    Dim iTxt As Integer

    Try 
        iTxt = Integer.Parse(iter.Text)

        If it > iTxt AndAlso iTxt <> 0 Then

        End If

    Catch ex As Exception
        MessageBox.Show(ex.Message)
    End Try

End Sub
将其设置为整数=0
将线路尺寸标注为新列表(PowerPacks.LineShape)()
子iter_TextChanged(发送方作为对象,e作为事件参数)处理iter.TextChanged
将iTxt设置为整数
尝试
iTxt=Integer.Parse(iter.Text)
如果它>iTxt并且也为iTxt 0,则
如果结束
特例
MessageBox.Show(例如Message)
结束尝试
端接头

我本想给你写个例子,但我意识到我不知道你到底想做什么。你能解释一下吗

当你把一个新的数字放在变量
it
下面时,它应该做什么?如果发生这种情况,它会出现在第一个“if”语句中是的,谢谢,我知道怎么读。但是我不明白你想用你的代码做什么。你能解释一下吗?从数组中删除最后一个元素?如果我放入文本框:3,它=6。然后从(3到5)中删除行,如果你把3放进去会发生什么,然后再放下去;8.