+ -
当前位置:首页 → 问答吧 → 请大家帮我看看下面代码的含义

请大家帮我看看下面代码的含义

时间:2007-09-11

来源:互联网

 Dim fs, txtFile, line, data, nvpair, nv
  Set fs = CreateObject("Scripting.FileSystemObject")
  If fs.FileExists(datafile) = False Then
   WScript.Echo "File " & datafile & " doesn't exist!"
   WScript.Quit
  End If
  
  Dim rootPartDic
  Set rootPartDic = CreateObject("Scripting.Dictionary")
  Set txtFile = fs.OpenTextFile(datafile)
  line = txtFile.ReadLine()
  data = Split(line, "|")
 
  For Each nvpair In data
   nv =Split(nvpair, "=")
   If UBound(nv)>0 Then
    rootPartDic.Add nv(0), nv(1)
   End If
  Next
    
      Dim Line_Num_Per_Page
  Line_Num_Per_Page = rootPartDic.Item("LineNumPerPage")
  
  Dim lineNum, contentDic
  lineNum = 1
  Set contentDic = CreateObject("Scripting.Dictionary")
  While Not txtFile.AtEndOfStream
   line = txtFile.ReadLine()
   contentDic.Add lineNum, line
   lineNum = lineNum + 1
  Wend
   
  Dim i, j, n, indent, tableID, table
  tableID = 1
  '.Selection.InsertDateTime "h时m分s秒", False, False, wdSimplifiedChinese, wdCalendarWestern
  Dim attrLenLimitArray
  attrLenLimitArray = Array(16, 4, 1, 3, 13, 50, 30, 20, 1, 3, 7, 2, 20, 30)
  
  For lineNum = 1 To contentDic.Count
  
     If lineNum Mod Line_Num_Per_Page = 1 Then     
      doc.Tables(tableID).Select
      
      .Selection.Copy
      doc.Range(doc.Range.End-1, doc.Range.End-1).Select
      ''WScript.Echo "select end"
      .Selection.InsertBreak wdPageBreak
      ''WScript.Echo "insert page"
      .Selection.Paste
      'WScript.Echo "Paste"
      '.Selection.InsertFile templatefile, "", False,False,False
    'WScript.Echo "Insert File"
    Set table=doc.Tables(tableID) 
    tableID=tableID + 1
    table.Cell(2,1).Select
     End If
   
     line = contentDic.Item(lineNum)
     data = Split(line, ",")
      
     indent = CInt(data(0))
     'omit by yujie20060228
     'n = 1
     'While n < indent
     ' .Selection.TypeText "."
     ' n= n+1
     'Wend
     .Selection.TypeText data(0)
     .Selection.MoveRight wdCell
     
     For i = 1 To UBound(data)
      data(i) = Left(rptDecodeString(data(i)), attrLenLimitArray(i))
      .Selection.TypeText data(i)
    .Selection.MoveRight wdCell
     Next    
     
         
  Next
  
   doc.Tables(tableID).Delete
     doc.Range(doc.Range.End-1, doc.Range.End-1).Select
     .Selection.TypeBackspace
     .Selection.TypeBackspace
     .Selection.TypeBackspace
    
     .ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader
   .Selection.ParagraphFormat.Alignment = wdAlignParagraphJustify
     .Selection.TypeText "打印日期: "
     .Selection.InsertDateTime "yyyy'年'M'月'd'日'", False, False, wdSimplifiedChinese, wdCalendarWestern
     .ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument

请大家给我注释一下.我不太清楚里面的含义!

作者: andylau112   发布时间: 2007-09-11

请选择不懂的问!

作者: 老申   发布时间: 2007-09-11

   If lineNum Mod Line_Num_Per_Page = 1 Then     
      doc.Tables(tableID).Select
      
      .Selection.Copy
      doc.Range(doc.Range.End-1, doc.Range.End-1).Select
      ''WScript.Echo "select end"
      .Selection.InsertBreak wdPageBreak
      ''WScript.Echo "insert page"
      .Selection.Paste
      'WScript.Echo "Paste"
      '.Selection.InsertFile templatefile, "", False,False,False
    'WScript.Echo "Insert File"
    Set table=doc.Tables(tableID) 
    tableID=tableID + 1
    table.Cell(2,1).Select
     End If

比如这段请帮忙注释!!

作者: andylau112   发布时间: 2007-09-11

高手们,是我讲的不清楚吗?在csdn上发表也没人回应,这边有没有吗?

作者: andylau112   发布时间: 2007-09-11

哎,我是彻底失望了

作者: andylau112   发布时间: 2007-09-11

觉得主要是楼主的提问技巧欠妥。这么长的代码,叫别人注释,工作量是一个方面,加上不知您的知识面,就算注释了也不知您能否看得明白,看不明白就是白费劲,所以别人不想介入。正如2楼所说,建议楼主还是提其中具体的问题,如果对代码一点也看不懂,这样的问题最好迟点再提。

作者: sylun   发布时间: 2007-09-11

唉,版主,我也看不懂这是什么意思啊,本想看看什么是VBA,因为自己刚刚接触点在表格,但是,您问的是这么的专业,看来自己是要进一步的加强学习了!!!

作者: 人在中行   发布时间: 2011-01-09