Foxtable(狐表)用户栏目专家坐堂 → 求助怎么写这个函数?


  共有3120人关注过本帖树形打印复制链接

主题:求助怎么写这个函数?

帅哥哟,离线,有人找我吗?
rongping
  1楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:小狐 帖子:358 积分:3077 威望:0 精华:0 注册:2018/3/15 16:46:00
求助怎么写这个函数?  发帖心情 Post By:2019/10/10 12:48:00 [只看该作者]

我想写这么一个函数:

我通过参数1传进去一个数组,通过参数2的值计算,通过参数3 确定正反。

比如我传进去这么一个数组,

Dim s1() As String = {"命宫","父母","福德","田宅","官禄","仆役","迁移","疾厄","财帛","子女","夫妻","兄弟"}

如果我参数2的值是5,参数3为0代表正转,那么返回的数组是以下内容:

{"财帛","子女","夫妻","兄弟","命宫","父母","福德","田宅","官禄","仆役","迁移","疾厄"}

再如我参数2的值是5,参数3为1代表反转.那么返回的数组是以下内容:

{"官禄,"田宅","福德","父母","命宫","兄弟","夫妻","子女","财帛","疾厄","迁移","仆役"}

请问该如何写这个函数?


 回到顶部
帅哥哟,离线,有人找我吗?
有点蓝
  2楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:超级版主 帖子:110333 积分:561507 威望:0 精华:9 注册:2015/6/24 9:21:00
  发帖心情 Post By:2019/10/10 13:51:00 [只看该作者]

如果我参数2的值是5,参数3为0代表正转,那么返回的数组是以下内容:

{"财帛","子女","夫妻","兄弟","命宫","父母","福德","田宅","官禄","仆役","迁移","疾厄"}


没看懂,结果怎么来的,和参数2有啥关系?


 回到顶部
帅哥哟,离线,有人找我吗?
rongping
  3楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:小狐 帖子:358 积分:3077 威望:0 精华:0 注册:2018/3/15 16:46:00
  发帖心情 Post By:2019/10/10 14:24:00 [只看该作者]

 

Dim s1() As string = Args(0) \\这是传进去的数组参数 比如Dim s1() As String = {"子","丑","寅","卯","辰","巳","午","未","申","酉","戌","亥"}

Dim i As integer = Args(1)    \\这是传进去数组的引用参数,如果是5代表数组的第4个参数 引用的是s1(4)

 

Dim z As integer = Args(2)    \\这是代表排序是逆时针还是顺时针

 


 回到顶部
帅哥哟,离线,有人找我吗?
有点蓝
  4楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:超级版主 帖子:110333 积分:561507 威望:0 精华:9 注册:2015/6/24 9:21:00
  发帖心情 Post By:2019/10/10 14:41:00 [只看该作者]

Dim s1() As String = {"命宫","父母","福德","田宅","官禄","仆役","迁移","疾厄","财帛","子女","夫妻","兄弟"}

如果我参数2的值是5,参数3为0代表正转,那么返回的数组是以下内容:

{"财帛","子女","夫妻","兄弟","命宫","父母","福德","田宅","官禄","仆役","迁移","疾厄"}


如果是5代表数组的第4个参数 引用的是s1(4),那么s1(4)不用应该是"官禄"?和上面的第二个结果有什么关系?


 回到顶部
帅哥哟,离线,有人找我吗?
rongping
  5楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:小狐 帖子:358 积分:3077 威望:0 精华:0 注册:2018/3/15 16:46:00
  发帖心情 Post By:2019/10/10 15:17:00 [只看该作者]

如果参数2的值是5,顺时针。结果是把传入进来的数组第一个值放到第5个位置,然后其他的统一向后移过去,首位相连。就是这个意思


 回到顶部
帅哥哟,离线,有人找我吗?
rongping
  6楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:小狐 帖子:358 积分:3077 威望:0 精华:0 注册:2018/3/15 16:46:00
  发帖心情 Post By:2019/10/10 15:29:00 [只看该作者]

可能这样表达更直观一点:

这个是传进去的数组

Dim s1() As String = {"1","2","3","4","5","6","7","8","9","10","11","12"}

 

我想要实现的返回值顺时针(假设参数2的值是5)结果是:

{"9","10","11","12","1","2","3","4","5","6","7","8"}

逆时针的结果是:

{"5","4","3","2","1","12","11","10","9","8","7","6"}


 回到顶部
帅哥哟,离线,有人找我吗?
有点蓝
  7楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:超级版主 帖子:110333 积分:561507 威望:0 精华:9 注册:2015/6/24 9:21:00
  发帖心情 Post By:2019/10/10 15:56:00 [只看该作者]

Dim s1() As String = {"1","2","3","4","5","6","7","8","9","10","11","12"}
Dim i1 As Integer = 5
Dim i2 As Integer = 0
Dim lst As new List(of String)
If i2 = 0 Then
    For i As Integer = 0 To s1.Length - i1
        lst.Add(s1(i))
    Next
    For i As Integer = s1.Length - 1 To s1.Length - i1 + 1 Step -1
        lst.Insert(0,s1(i))
    Next
Else
    For i As Integer = i1-1 To 0 Step -1
        lst.Add(s1(i))
    Next
    For i As Integer = s1.Length - 1 To i1 Step -1
        lst.Add(s1(i))
    Next
End If

Output.Show(String.Join(",",lst.ToArray))

 回到顶部
帅哥哟,离线,有人找我吗?
rongping
  8楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:小狐 帖子:358 积分:3077 威望:0 精华:0 注册:2018/3/15 16:46:00
  发帖心情 Post By:2019/10/10 16:04:00 [只看该作者]

超级感谢!

 回到顶部