newuser 发表于 2010-6-23 11:01:44

二维数组输出的问题?[已解决]

本帖最后由 newuser 于 2010-6-23 13:29 编辑

以下是学习CroosDoor老师的教程遇到的二维数组输出的问题:

Dim $Week=[["周一","周二","周三"],["语文","数学","数学"],["英语","语文","体育"],["历史","音乐","班会"]]
ReDim $Week ;上面是1天3节课,现在多加了1行,既每天增加了1节课
For $i=0 To 2
        $Week[$i]="美术" ;因为行数是从0开始,新加的第5行下标自然就是,这里表示加的课都是美术
Next

For $x=0 To 2
        For $y=0 To 4
                MsgBox(0,"",$Week[$y][$x]&@CRLF)
        Next
Next
我本意是想显示标题为某一天,然后输出改天的所有课程,但越弄越乱?无法实现!

kxing 发表于 2010-6-23 11:34:54

个人认为这样初始化不好控制,修改为三行四列比较清晰:
Dim $Week=[ _
["周一","语文","数学","数学"], _
["周二","英语","语文","体育"], _
["周三","历史","音乐","班会"]]

For $i=0 To 2
MsgBox(0,$Week[$i],$Week[$i]&" - "&$Week[$i]&" - "&$Week[$i])
Next

Hen5ei 发表于 2010-6-23 11:37:42

试试楼上的.,那样比较清晰

3mile 发表于 2010-6-23 11:52:39

Dim $Week=[["周一","周二","周三"],["语文","数学","数学"],["英语","语文","体育"],["历史","音乐","班会"]]
ReDim $Week ;上面是1天3节课,现在多加了1行,既每天增加了1节课
Local $str
For $i=0 To 2
      $Week[$i]="美术" ;因为行数是从0开始,新加的第5行下标自然就是,这里表示加的课都是美术
Next

For $i=0 To 4
        For $n=0 To 2
                $str&=$week[$i][$n]&@TAB
        Next
        $str&=@CRLF
Next
MsgBox(0,0,$str)

masterpcc 发表于 2010-6-23 13:08:56

新手!!学习了!谢谢!!

newuser 发表于 2010-6-23 13:20:30

回复 4# 3mile
& @tab @crlf应用的真的是太棒了!我费了2个多小时也没想出,非常谢谢!

newuser 发表于 2010-6-23 13:27:10

回复 2# kxing
我想了2个多小时,也想到把行列互换好整些,但只是在循环顺序下手,没想到把数组的结构调整就容易多了,真是退一步海阔天空!

tjwen 发表于 2011-10-28 17:29:06

新手!!学习了!谢谢!!
页: [1]
查看完整版本: 二维数组输出的问题?[已解决]