乐筑天下

搜索
欢迎各位开发者和用户入驻本平台 尊重版权,从我做起,拒绝盗版,拒绝倒卖 签到、发布资源、邀请好友注册,可以获得银币 请注意保管好自己的密码,避免账户资金被盗
楼主: Fatty

2D阵列帮助

[复制链接]

0

主题

3

帖子

1

银币

初来乍到

Rank: 1

铜币
3
发表于 2008-2-12 09:02:43 | 显示全部楼层
这是一个过于简单的例子,但我已经伤透了时间。将其放入模块--
  1. Type TStrArray
  2.     Items() As String
  3. End Type
  4. Sub Test()
  5.     Dim jagged() As TStrArray
  6.    
  7. [color=green]    ''  add the first "record"[/color]
  8.    
  9.     ReDim jagged(0)
  10.    
  11. [color=green]    ''  add a "field"[/color]
  12.    
  13.     ReDim jagged(0).Items(0)
  14.    
  15. [color=green]    ''  populate it[/color]
  16.    
  17.     jagged(0).Items(0) = "Drawing1"
  18.    
  19. [color=green]    ''  oh my, we just discovered we have a layout, we need another "field"[/color]
  20.    
  21.     ReDim Preserve jagged(0).Items(1)
  22.    
  23. [color=green]    ''  ok, populate it[/color]
  24.    
  25.     jagged(0).Items(1) = "Layout2"
  26. [color=green]    ''  oh my, and yet another layout[/color]
  27.    
  28.     ReDim Preserve jagged(0).Items(2)
  29.    
  30. [color=green]    ''  populate it[/color]
  31.    
  32.     jagged(0).Items(2) = "Layout3"
  33.    
  34. [color=green]    ''  ok, let's add another "record"[/color]
  35.    
  36.     ReDim Preserve jagged(1)
  37.    
  38. [color=green]    ''  add 4 "fields" to this record (remember that basic is
  39.     ''  goofy, dim (3) = elements 0,1,2,3 so 4 elements total[/color]
  40.    
  41.     ReDim Preserve jagged(1).Items(3)
  42.    
  43.     jagged(1).Items(0) = "Drawing2"
  44.     jagged(1).Items(1) = "Layout1"
  45.     jagged(1).Items(2) = "Layout2"
  46.     jagged(1).Items(3) = "Layout3"
  47.    
  48. [color=green]    ''  yada. Add debug.print statments to suit to illuminate the contents
  49.    
  50.     ''  in practice one would try to know ahead of time the number
  51.     ''  of array elements required, for the primary and nested arrays.
  52.     ''  There's a significant performance hit every time you use redim
  53.     ''  preserve; use it only when absolutely necessary.[/color]
  54.    
  55. End Sub
回复

使用道具 举报

发表回复

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

QQ|关于我们|小黑屋|乐筑天下 繁体中文

GMT+8, 2025-7-5 09:46 , Processed in 0.546684 second(s), 52 queries .

© 2020-2025 乐筑天下

联系客服 关注微信 帮助中心 下载APP 返回顶部 返回列表