| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1411 人关注过本帖, 1 人收藏
标题:关于2维数组的赋值
只看楼主 加入收藏
linandceline
Rank: 2
等 级:论坛游民
威 望:2
帖 子:88
专家分:47
注 册:2014-12-19
结帖率:78.95%
收藏(1)
已结贴  问题点数:20 回复次数:2 
关于2维数组的赋值
比如说有一个listview,上面有数据如下

a 1 2 3
b 2 3 4
a 3 4 5
c 3 6 6
b 3 5 5
d 4 2 2

现在要列一个2维数组,比如Ma()
Ma(1,1),Ma(2,1)等记录第一列的字母
Ma(1,2),Ma(1,2)分别记录所在Ma(1,1)这个值所对应的行数,1,3

这样要怎么赋值?


补充:要查找指定文件夹内的某个文件(只针对名,不包括后缀), DIR或者fileexits能实现吗

[此贴子已经被作者于2018-11-21 17:10编辑过]

搜索更多相关主题的帖子: 维数 赋值 记录 查找 指定文件 
2018-11-21 16:49
风吹过b
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
等 级:贵宾
威 望:364
帖 子:4947
专家分:30084
注 册:2008-10-15
收藏
得分:20 
用数组直接搞不定,用结构体联合数组来搞定吧!

程序代码:
Option Explicit

Private Type jg
  字母 As String * 1
  位置() As Long
End Type

Dim ma() As jg

Private Sub Command1_Click()

Dim s As String, i As Long, j As Long
Dim f() As String
Dim macount

s = Text1.Text
f = Split(s, vbCrLf)

macount = 0
ReDim ma(0)

For i = 0 To UBound(f)
    s = Left(f(i), 1)
    For j = 0 To macount
        If ma(j).字母 = s Then
            ReDim Preserve ma(j).位置(UBound(ma(j).位置) + 1)
            ma(j).位置(UBound(ma(j).位置)) = i + 1
            Exit For
        End If
    Next j
    If j > macount Then
        macount = macount + 1
        ReDim Preserve ma(macount)
        ReDim ma(macount).位置(1)
        ma(macount).字母 = s
        ma(macount).位置(1) = i + 1
    End If
Next i

End Sub

Private Sub Form_Load()
Text1.Text = "a 1 2 3"
Text1.Text = Text1.Text & vbCrLf & "b 2 3 4"
Text1.Text = Text1.Text & vbCrLf & "a 3 4 5"
Text1.Text = Text1.Text & vbCrLf & "c 3 6 6"
Text1.Text = Text1.Text & vbCrLf & "b 3 5 5"
Text1.Text = Text1.Text & vbCrLf & "d 4 2 2"

End Sub


授人于鱼,不如授人于渔
早已停用QQ了
2018-11-22 11:47
ZHRXJR
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:版主
威 望:125
帖 子:1034
专家分:5519
注 册:2016-5-10
收藏
得分:0 
定义一个字符串数据类型的二维数组 Dim Ma(1 To 12, 1 To 4) As String,1 TO 12 是行数,1 TO 4 是列数
程序代码:

 Dim Ma(1 To 12, 1 To 4) As String, MC, DJ, HYJ, MBC, I As Integer, J As Integer

 MC = Array("", "a", "b", "c", "d", "e", "f", "g", "h", "i", "l", "k", "t")

 DJ = Array(0, 3, 2, 4, 2, 5, 8, 7, 6, 4, 3, 5, 8)

 HYJ = Array(0, 2, 2, 4, 2, 5, 7, 7, 6, 3, 3, 5, 8)

 MBC = Array(0, 7, 4, 5, 7, 1, 8, 1, 6, 9, 3, 3, 4)

 For I = 1 To 12

 Ma(I, 1) = MC(I)

 Ma(I, 2) = DJ(I)

 Ma(I, 3) = HYJ(I)

 Ma(I, 4) = MBC(I)

 Next I

 Text1.Text = ""

 For I = 1 To 12
    For J = 1 To 4
    Text1.Text = Text1.Text & Ma(I, J) & Space(4)
    Next J
    Text1.Text = Text1.Text & vbCrLf

 Next I

下面是数组显示结果
图片附件: 游客没有浏览图片的权限,请 登录注册

请不要选我!!!
2018-11-25 10:04
快速回复:关于2维数组的赋值
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.021939 second(s), 10 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved