我写的东西对别人来说是天书,能看懂的是天才

dafu2003 2011-01-29 02:31:35
谁能看懂了,谁就是天才


Public Function genSingleXMLFile(title As String, txt As String, gs As String, desFile As String, Optional showName As Boolean) As Boolean
Dim objDOM As MSXML2.DOMDocument60
Dim objNode As MSXML2.IXMLDOMNode
Dim objHead As MSXML2.IXMLDOMNode
Dim objBody As MSXML2.IXMLDOMNode
Dim i As Integer, s As String
Static fileNo As Long
On Error GoTo errr

Set objDOM = createDOM
Set objNode = objDOM.CreateNode(NODE_ELEMENT, "snbc", "")
insertNewLine objDOM, objNode

Set objHead = objDOM.CreateNode(NODE_ELEMENT, "head", "")
insertNewLine objDOM, objHead
If m_cfp.isJpgLiked(gs) And showName = False Then
insertText objDOM, objHead, "title", ""
Else
insertText objDOM, objHead, "title", title
End If
objNode.AppendChild objHead
insertNewLine objDOM, objNode

Set objBody = objDOM.CreateNode(NODE_ELEMENT, "body", "")
insertNewLine objDOM, objBody
If m_cfp.isTxtLiked(gs) Then
' If gs = "txt" Then
insertText objDOM, objBody, "text", txt
ElseIf m_cfp.isJpgLiked(gs) Then
Dim desTmpFile As String, fname As String, newName As String
fname = txt
s = m_cfp.getFilePathName(desFile, True)
desTmpFile = s & "\images\" & m_cfp.GetFileName(fname)
m_cfp.createPath m_cfp.getFilePathName(desTmpFile, True)
If LCase(m_cfp.getFilePathName(fname)) <> LCase(m_cfp.getFilePathName(desTmpFile)) Then _
m_cfp.copyFile fname, desTmpFile, True
fileNo = fileNo + 1
newName = m_cfp.newFileName(desTmpFile, fileNo)
addSubNode objDOM, objBody, "img", Trim(m_cfp.GetFileName(newName))
End If
objNode.AppendChild objBody
insertNewLine objDOM, objBody

objDOM.AppendChild objNode
Set objNode = Nothing
If objDOM.parseError.errorCode = 0 Then
' m_cfp.createPath m_cfp.getFilePathName(desFile, True)
objDOM.Save desFile
genSingleXMLFile = True
Else
RaiseEvent showMsg(objDOM.parseError.reason)
End If
errr:
Set objDOM = Nothing
End Function

Public Function setTextsXMLFile(title As String, textFiles() As String, n As Long, desFile As String, Optional showName As Boolean) As Boolean
Dim objDOM As MSXML2.DOMDocument60
Dim objNode As MSXML2.IXMLDOMNode
Dim objHead As MSXML2.IXMLDOMNode
Dim objBody As MSXML2.IXMLDOMNode
Dim i As Long, s As String, cd
Dim fname As String, despath As String

On Error GoTo errr
' n = UBound(picfiles)
If n = 0 Then Exit Function
despath = m_cfp.getFilePathName(desFile, True)
despath = m_cfp.getFilePathName(despath) & "snbc"
m_cfp.createPath despath

Set objDOM = createDOM
Set objNode = objDOM.CreateNode(NODE_ELEMENT, "snbc", "")
insertNewLine objDOM, objNode

Set objHead = objDOM.CreateNode(NODE_ELEMENT, "head", "")
insertText objDOM, objHead, "title", title
objNode.AppendChild objHead
insertNewLine objDOM, objNode

Set objBody = objDOM.CreateNode(NODE_ELEMENT, "body", "")
insertNewLine objDOM, objBody

For i = 1 To n
Dim chapterTitle As String, buff As String, gs As String
gs = m_cfp.getFileExtName(textFiles(i))
If m_cfp.isTxtLiked(gs) Then
chapterTitle = vbCrLf & m_cfp.getFileTitleName(textFiles(i)) & vbCrLf
If showName Then insertText objDOM, objBody, "text", chapterTitle
buff = m_cfp.loadTxtFile(textFiles(i))
insertText objDOM, objBody, "text", buff
End If
Next i
insertNewLine objDOM, objBody
objNode.AppendChild objBody
insertNewLine objDOM, objNode

objDOM.AppendChild objNode
Set objNode = Nothing
If objDOM.parseError.errorCode = 0 Then
m_cfp.createPath m_cfp.getFilePathName(desFile, True)
objDOM.Save desFile
setTextsXMLFile = True
Else
RaiseEvent showMsg(objDOM.parseError.reason)
End If
errr:
Set objDOM = Nothing
End Function

Public Function setAllXMLFileByChapters(title As String, files() As String, n As Long, desSNBPath As String, Optional showName As Boolean) As Boolean
Dim i As Long, s As String, desFile As String
Dim fname As String, despath As String
Dim buff As String, gs As String, titleTmp As String
Dim istxt As Boolean, isjpg As Boolean, newName As String
Dim desTmpFile As String
On Error GoTo errr
If n = 0 Then Exit Function
despath = m_cfp.justPath(desSNBPath)
m_cfp.createPath despath
For i = 1 To n
fname = files(i)
titleTmp = m_cfp.getFileTitleName(fname)
gs = m_cfp.getFileExtName(fname)
If m_cfp.isTxtLiked(gs) Then
buff = m_cfp.loadTxtFile(fname)
gs = "txt"
ElseIf LCase(gs) = "htm" Or LCase(gs) = "html" Then
buff = m_Html.Html2Text1(fname, s)
gs = "txt"
ElseIf m_cfp.isJpgLiked(gs) Then
buff = fname
gs = "jpg"
ElseIf gs = "pdf" Then
desFile = despath & "\file_" & format(i, "000") & ".pdf"
m_cfp.copyFile fname, desTmpFile, True
End If
If gs <> "pdf" Then
desFile = despath & "\file_" & format(i, "000") & ".snbc"
If m_cfp.fileExist(desFile) Then m_cfp.delFile desFile, True
If genSingleXMLFile(titleTmp, buff, gs, desFile, showName) = False Then GoTo errr
End If
Next i
setAllXMLFileByChapters = True
errr:
End Function

Public Function setAllXMLFile(title As String, files() As String, n As Long, desFile As String, Optional showName As Boolean) As Boolean
Dim objDOM As MSXML2.DOMDocument60
Dim objNode As MSXML2.IXMLDOMNode
Dim objHead As MSXML2.IXMLDOMNode
Dim objBody As MSXML2.IXMLDOMNode
Dim i As Long, s As String, cd
Dim fname As String, despath As String
Dim chapterTitle As String, buff As String, gs As String, titleTmp As String
Dim istxt As Boolean, isjpg As Boolean, newName As String
Dim desTmpFile As String
On Error GoTo errr
' n = UBound(picfiles)
If n = 0 Then Exit Function
despath = m_cfp.getFilePathName(desFile, True)
despath = m_cfp.getFilePathName(despath) & "snbc"
m_cfp.createPath despath

Set objDOM = createDOM

Set objNode = objDOM.CreateNode(NODE_ELEMENT, "snbc", "")
insertNewLine objDOM, objNode

Set objHead = objDOM.CreateNode(NODE_ELEMENT, "head", "")
insertText objDOM, objHead, "title", title
objNode.AppendChild objHead
insertNewLine objDOM, objNode

Set objBody = objDOM.CreateNode(NODE_ELEMENT, "body", "")
insertNewLine objDOM, objBody

For i = 1 To n
fname = files(i)
gs = m_cfp.getFileExtName(fname)
titleTmp = m_cfp.getFileTitleName(fname)
istxt = m_cfp.isTxtLiked(gs)
isjpg = m_cfp.isJpgLiked(gs) '(gs = "jpg" Or gs = "png")
chapterTitle = vbCrLf & titleTmp & vbCrLf
If showName And istxt Then insertText objDOM, objBody, "text", chapterTitle
If istxt Then
buff = m_cfp.loadTxtFile(fname)
insertText objDOM, objBody, "text", buff
Else
desTmpFile = despath & "\images\" & m_cfp.GetFileName(fname)
m_cfp.createPath m_cfp.getFilePathName(desTmpFile, True)
If LCase(m_cfp.getFilePathName(fname)) <> LCase(m_cfp.getFilePathName(desTmpFile)) Then _
m_cfp.copyFile fname, desTmpFile, True
newName = m_cfp.newFileName(desTmpFile, i)
addSubNode objDOM, objBody, "img", Trim(m_cfp.GetFileName(newName))
End If
Next i
insertNewLine objDOM, objBody
objNode.AppendChild objBody
insertNewLine objDOM, objNode

objDOM.AppendChild objNode
Set objNode = Nothing
If objDOM.parseError.errorCode = 0 Then
m_cfp.createPath m_cfp.getFilePathName(desFile, True)
objDOM.Save desFile
setAllXMLFile = True
Else
RaiseEvent showMsg(objDOM.parseError.reason)
End If
errr:
Set objDOM = Nothing
End Function

Public Function setPicturesXMLFile(title As String, picFiles() As String, n As Long, desFile As String, Optional showName As Boolean) As Boolean
Dim objDOM As MSXML2.DOMDocument60
Dim objNode As MSXML2.IXMLDOMNode
Dim objHead As MSXML2.IXMLDOMNode
Dim objBody As MSXML2.IXMLDOMNode
Dim i As Long, s As String
Dim fname As String, despath As String, desTmpFile As String, newName As String

On Error GoTo errr
' n = UBound(picfiles)
If n = 0 Then Exit Function
despath = m_cfp.getFilePathName(desFile, True)
m_cfp.createPath despath

Set objDOM = createDOM

Set objNode = objDOM.CreateNode(NODE_ELEMENT, "snbc", "")
insertNewLine objDOM, objNode

Set objHead = objDOM.CreateNode(NODE_ELEMENT, "head", "")
insertNewLine objDOM, objHead
insertText objDOM, objHead, "title", title
objNode.AppendChild objHead
insertNewLine objDOM, objNode

Set objBody = objDOM.CreateNode(NODE_ELEMENT, "body", "")
insertNewLine objDOM, objBody

insertText objDOM, objBody, "text", title

For i = 1 To n
fname = despath & "\" & m_cfp.GetFileName(picFiles(i))
desTmpFile = despath & "\images\" & m_cfp.GetFileName(fname)
m_cfp.createPath m_cfp.getFilePathName(desTmpFile, True)
If LCase(m_cfp.getFilePathName(fname)) <> LCase(m_cfp.getFilePathName(desTmpFile)) Then _
m_cfp.copyFile fname, desTmpFile, True
newName = m_cfp.newFileName(desTmpFile, i)
If showName Then insertText objDOM, objBody, "text", m_cfp.getFileTitleName(fname)
addSubNode objDOM, objBody, "img", Trim(m_cfp.GetFileName(newName))
Next i

objNode.AppendChild objBody
insertNewLine objDOM, objNode
objDOM.AppendChild objNode
Set objNode = Nothing
If objDOM.parseError.errorCode = 0 Then
m_cfp.createPath m_cfp.getFilePathName(desFile, True)
objDOM.Save desFile
setPicturesXMLFile = True
Else
RaiseEvent showMsg(objDOM.parseError.reason)
End If
errr:
Set objDOM = Nothing
End Function

...全文
146 14 打赏 收藏 转发到动态 举报
写回复
用AI写文章
14 条回复
切换为时间正序
请发表友善的回复…
发表回复
贝隆 2011-01-30
  • 打赏
  • 举报
回复
4楼含蓄且强悍!服了
杨哥儿 2011-01-30
  • 打赏
  • 举报
回复
不就是XML文件操作吗?
码之魂 2011-01-29
  • 打赏
  • 举报
回复
垃圾~!
无·法 2011-01-29
  • 打赏
  • 举报
回复
不了解你用的那些组件。如果别人了用一些你从来没用过的组件来写一片代码你同样也看不懂。所以这没什么值得炫耀的。
熊孩子开学喽 2011-01-29
  • 打赏
  • 举报
回复
不想当将军的账房不是一个好厨师
网络菜鸟00 2011-01-29
  • 打赏
  • 举报
回复

4楼一针见血……
booksoon 2011-01-29
  • 打赏
  • 举报
回复
自己能懂吗?现在懂,再过一星期,一年,两年...
神马都能聊 2011-01-29
  • 打赏
  • 举报
回复
不想写注释的程序员不是好宅男
  • 打赏
  • 举报
回复
不知道哪里抄来的。
我是看不懂。
捧剑者 2011-01-29
  • 打赏
  • 举报
回复
dbcontrols 2011-01-29
  • 打赏
  • 举报
回复
楼主贴一下insertNewLine的代码吧
没良心 2011-01-29
  • 打赏
  • 举报
回复
挺漂亮的。。

7,763

社区成员

发帖
与我相关
我的任务
社区描述
VB 基础类
社区管理员
  • VB基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧