我有三个父目录(文件夹):A,B,C.
在这A,B,C三个文件夹中,每个都有相同的六个子文件:d,e,f,g,h,i
程序 依此读取A,B,C中的d,e,f,g,h,i文件的个数目标:
我现在希望用vb写一个嵌套的循环,当程序在命令行运行时,先输入父目录参数A,B,C (也可能只输入A,B,C三个中的一个或两个,根据需要定),然后再输入子目录参数:d,e,f,g,h,i,(也可能只输入d,e,f,g,h,i,个中的一个或两个,根据需要定)执行后,
程序依此读取A,B,C中的d,e,f,g,h,i文件的个数.

解决方案 »

  1.   

    dim str(0 to 8) as string
    dim x as long, y as long
    str(0)="A":str(1)="B":str(2)="C"
    str(3)="d":str(4)="e":str(5)="f":str(6)="g":str(7)="h":str(8)="i"for x=0 to 2
        :
        :
        for y=3 to 8
             :
             :   
        next y
    next x
    虽然不怎么明白你要的,应该是类似这样子吧?用For ... loop
      

  2.   

    Option Explicit
    '添加 Form1、TextBox1、TextBox2、Command1
    '在TextBox1中输入父目录,TextBox2中输入子目录
    '半角逗号分隔
    Private Sub CommandButton1_Click()    Dim arrParPath$(), arrSubPath$()
        Dim strParent$, strSub$, iFileNum&, i&, j&, k&
        
        arrParPath = Split(TextBox1.Text, ",")
        arrSubPath = Split(TextBox1.Text, ",")
        Me.cls
        For i = 0 To UBound(arrParPath)
            strParent = arrParPath(i)
            If (Len(strParent) = 0) Then Exit For
            For j = 0 To UBound(arrSubPath)
                strSub = arrSubPath(j)
                If (Len(strSub) = 0) Then Exit For
                iFileNum = 0
                k = Len(Dir$(strParent & "\" & strSub & "\*.*", 7))
                While (k > 0)
                    iFileNum = iFileNum + 1
                    k = Len(Dir$())
                Wend
                Me.Print strParent & "\" & strSub; " 有文件:"; iFileNum; " 个"
            Next
        Next
    End Sub