Power Designer 使用小记

一、通过Power Designer 自带命令窗口执行VB脚本时的乱码问题:

        Power Designer 支持vb脚本语言,在大批量数据建模时很方便,有时候需要读取外部文档资源替换数据模型中的某些标记。例如:数据模型的字段名都是英文,需要给其name赋为中文,可以通过vb脚本进行比对替换。读取外部txt文档时可能会出现乱码。由于未找到读取文档设置编码的方法,我们只能从根源处解决乱码问题,将txt文本转换为ANSI编码格式即可。

TXT文本示例:

EMP||员工表||EmpNo||员工号码||
EMP||员工表||EmpName||员工名||
DEPT||部门表||DEPTNO||部门号码||
DEPT||部门表||DEPTNAME||部门名称||
DEPT||部门表||DEPTNUM||部门员工数量||

VB脚本示例:

'******************************************************************************
'* Purpose:  通过txt文本替换表名、字段名
'* Title:
'* Category: 
'* Author:   Aikes	On 2019-08-21
'* Created:  2019-08-21

'* Use:      打开PDM,运行本脚本(Ctrl+Shift+X)
'*           txt 格式要求 按照||划分

'* Version:  2.0
'*
'* Comment:  Modified By Aikes On 2019-08-21
'*
'******************************************************************************

Option Explicit
ValidationMode = True
InteractiveMode = im_Batch

' 读取文本文件
Dim NoteApp
set NoteApp =createobject("scripting.filesystemobject")
Dim NoteObj
set NoteObj=NoteApp.opentextfile("E:/1.txt",1,true)

' the current model
Dim mdl 

' get the current active model
Set mdl = ActiveModel

If (mdl Is Nothing) Then
	MsgBox "There is no current Model "
ElseIf Not mdl.IsKindOf(PdPDM.cls_Model) Then
	MsgBox "The current model is not an Physical Data model. "
Else
	ProcessFolder mdl
End If

Private sub ProcessFolder(folder)
	On Error Resume Next
	Dim Tab 'running   table
	Dim i
	Dim flag
	Dim TCode
	do while NoteObj.atendofstream<>true
		flag = false
		' 读取文本文件一行的数据
		TCode = NoteObj.readline
		if TCode = "" then 
			' 如果读取的信息为空,则调出循环
			Exit do
		else
			Dim tArr
			Dim tLen
			tArr = Split(TCode,"||")
			tLen = ubound(tArr)
			for each Tab in folder.tables
				if not tab.isShortcut then
					' 找到table对象
					If LCase(Trim(tab.code)) = LCase(Trim(tArr(0))) Then
						tab.code = tArr(0)
						tab.name = tArr(1)
						' 循环处理table下面的column
						Dim col ' running column
						for each col in tab.columns
							If LCase(Trim(col.code)) = LCase(Trim(tArr(2))) Then
								col.code = tArr(2)
								col.name = tArr(3)
								exit for
							end if
						next
						Exit for
					end if
				end if
			next
		end if
	loop
	NoteObj.close
end sub

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Aikes902

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值