以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.net/bbs/index.asp)
--  专家坐堂  (http://foxtable.net/bbs/list.asp?boardid=2)
----  循环代码求助  (http://foxtable.net/bbs/dispbbs.asp?boardid=2&id=177253)

--  作者:rongping
--  发布时间:2022/5/14 11:34:00
--  循环代码求助
Dim Products As List(Of String)
Products = DataTables("客户").GetValues("客户名称")

Products集合中获得的值是:"张三","李四","王五","赵六","大卫","小伟","秘鲁","里奇","可达","披露","问止",
我想通过一个数值变量使它重新排列,比如这个数值是5,重新排列的结果是:
"里奇","可达","披露","问止","张三","李四","王五","赵六","大卫","小伟","秘鲁"
另外一个结果是:
"大卫","赵六","王五","李四","张三","问止","披露","可达","里奇","秘鲁","小伟"

求助这个循环要怎么写?

--  作者:有点蓝
--  发布时间:2022/5/14 12:13:00
--  
Dim sr() As String = {"张三", "李四", "王五", "赵六", "大卫", "小伟", "秘鲁", "里奇", "可达", "披露", "问止"}
Dim a As Integer = 5
Dim lst As New List(Of String)
For i As Integer = a To sr.Length - 1
    lst.add(sr(i))
Next 
For i As Integer = 0 To a - 1
    lst.add(sr(i))
Next 
For Each s As String In lst
    Output.Show(s)
Next 
Dim lst2 As New List(Of String)
For i As Integer = a To 0 Step - 1
    lst2.add(sr(i))
Next 
For i As Integer = sr.Length - 1 To a + 1 Step - 1
    lst2.add(sr(i))
Next 
For Each s As String In lst2
    Output.Show(s)
Next 

--  作者:rongping
--  发布时间:2022/5/14 13:02:00
--  
Dim sr() As String = {"张三", "李四", "王五", "赵六", "大卫", "小伟", "秘鲁", "里奇", "可达", "披露", "问止"}

这一句用集合行不行?因为这个都是从数据表中提出来的集合。

--  作者:rongping
--  发布时间:2022/5/14 13:03:00
--  
以下是引用有点蓝在2022/5/14 12:13:00的发言:
Dim sr() As String = {"张三", "李四", "王五", "赵六", "大卫", "小伟", "秘鲁", "里奇", "可达", "披露", "问止"}
Dim a As Integer = 5
Dim lst As New List(Of String)
For i As Integer = a To sr.Length - 1
    lst.add(sr(i))
Next 
For i As Integer = 0 To a - 1
    lst.add(sr(i))
Next 
For Each s As String In lst
    Output.Show(s)
Next 
Dim lst2 As New List(Of String)
For i As Integer = a To 0 Step - 1
    lst2.add(sr(i))
Next 
For i As Integer = sr.Length - 1 To a + 1 Step - 1
    lst2.add(sr(i))
Next 
For Each s As String In lst2
    Output.Show(s)
Next 

我用表事件的GetValues只能提出集合


--  作者:有点蓝
--  发布时间:2022/5/14 13:34:00
--  
可以的,用法完全一样。这种自己试试就知道了