免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 2719 | 回复: 6
打印 上一主题 下一主题

RPG中是否真的無法解決二維陣列問題? [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2004-11-23 09:52 |只看该作者 |倒序浏览
這幾天遇到一個問題,需要用到二維陣列解決,但是RPG中的Array只能宣告一維,請問各位先進都是如何處理二維陣列的問題呢?

论坛徽章:
0
2 [报告]
发表于 2004-11-23 10:41 |只看该作者

RPG中是否真的無法解決二維陣列問題?

[quote]原帖由 "╰●-●╯"]這幾天遇到一個問題,需要用到二維陣列解決,但是RPG中的Array只能宣告一維,請問各位先進都是如何處理二維陣列的問題呢?[/quote 发表:



有个关键字也许有点作用,但不会像C里二维数组那样方便好用。

你有 ILE RPG Reference 的书吧?看看 OCCUR 的用法,不知道能

不能解决你的问题,只是DS里不能用相对的方法去定位,不能实现C中

i++、j++这种模式。要是有啥新进展发上来让偶学习一下 ^^

论坛徽章:
0
3 [报告]
发表于 2004-11-23 11:58 |只看该作者

RPG中是否真的無法解決二維陣列問題?

感謝樓上大大提供一個方向。

OCCUR在RPG400中也有對應的指令OCUR,但我沒用過,也不曉得用法及目的是啥?不過查詢了一下資料,似乎無法用類似Array的ARY,X之類的語法,因為使用Array的最大好處是可以使用迴圈去控制每一個Array的值,二維的Array使用二層迴圈就搞定了,應該是我英文太破,無法領悟....

有沒有人願意提供一下自己用RPG處理類似二維Array的方式來分享一下呢?感謝!

论坛徽章:
0
4 [报告]
发表于 2004-11-23 12:27 |只看该作者

RPG中是否真的無法解決二維陣列問題?


  1. D dQryAutDds      DS                  OCCURS(10)   
  2. D  aQryAutAry1                 14A   DIM(5)      
  3. D  aQryAutAry2                 12A   DIM(5)      
复制代码


通过OCCURS、ARRAY、DS 可以组合出 3 维的数组。

论坛徽章:
0
5 [报告]
发表于 2004-11-24 01:29 |只看该作者

RPG中是否真的無法解決二維陣列問題?

楼上的高手,领教了!这样应该可以实现的!

论坛徽章:
0
6 [报告]
发表于 2004-11-24 15:05 |只看该作者

RPG中是否真的無法解決二維陣列問題?

[quote]原帖由 "╰●-●╯"]這幾天遇到一個問題,需要用到二維陣列解決,但是RPG中的Array只能宣告一維,請問各位先進都是如何處理二維陣列的問題呢?[/quote 发表:


也许这段内容能给你一些启发,我不太清楚你要二维矩阵做什么用,不过这段

算法应该可以模拟二维矩阵,你自己研究一下吧。


my experience is
that you typically only want to reference one element at a time to
either save or retrieve the element's contents.  With RPG IV, my
preference is to  just code a little subprocedure to return the index
when passed the desired dimensions.

c                   eval      Array( GetArrayIndex( X: Y )) = A

or

c                   eval      A = Array( GetArrayIndex( X: Y ))

This technique allows you to code as many dimensions as you want, and
still be (relatively) readable.  I don't put this one in a service
program, because I change the name of the procedure based on the
array, and change the number of arguments and array sizes.

By making the arguments Const, you can pass a variable, expression, or
constant for each dimension.  For example, a simple program:

     D Entry           S             10A
     D Array           S                   Like( Entry )
     D                                     Dim( 6000 )


     D GetArrayIndex   PR             5I 0
     D  X                             5I 0 Const
     D  Y                             5I 0 Const

     C                   Eval      Array( GetArrayIndex( 1: 2 )) =
'Rhinoceros'
     C                   Eval      Entry = Array( GetArrayIndex( 1: 2
))
     C                   Eval      *InLR = *On

     P GetArrayIndex   B

     D GetArrayIndex   PI             5I 0
     D  X                             5I 0 Const
     D  Y                             5I 0 Const

     D Array_Size_X    C                   100
     D Array_Size_Y    C                   60

     C                   Return    (( X - 1 ) * Array_Size_X + Y )

     P                 E

论坛徽章:
0
7 [报告]
发表于 2004-11-24 19:52 |只看该作者

RPG中是否真的無法解決二維陣列問題?


  1. D   Array         DS                 36         OCCURS(9999)
  2. D     ID                                   5         OVERLAY(Array)
  3. D     Name                             10        OVERLAY(Array:6)
  4. D     Salary                            11S  2  OVERLAY(Array:16)        
  5. D     Datex                                 D      OVERLAY(Array:26)
  6. **
  7. **     Active   17th occurence of  Array                         **
  8. C         17       OCCUR        Array

  9. //FREE

  10. ....
  11. ....

  12. *inLR=*ON;

  13. //END-FREE
  14.                         
复制代码
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP