末除去0.1我使用的Visual Basic编写的Autodesk Inventor宏。我创建了一个调用文件对话框的宏,参见下面的代码。一切正常,除非用户将文件名放在一个句号和一个大于零的数字之后。VBA文件对话框.FileName从文件名
例如,如果用户将在框中testfile.test和命中确定。当我询问他们使用.FileName时,我得到了“testfile.test”。就像我应该的。
然而,如果用户把testfile.1或testfile.10或testfile.1mdksj或什么,只要一个大于零的数直接跟我找回期“testfile的”。出于某种原因,在期间和期间之后的所有内容都将被删除。
,这是什么原因呢?这是一个视觉基础的错误还是我做错了什么?
'Set up the file dialog
Dim oFileDlg As FileDialog
' Create a new FileDialog object.
Call ThisApplication.CreateFileDialog(oFileDlg)
'Define the filter to select part and assembly files or any file.
oFileDlg.Filter = "All Files (*.*)|*.*"
'Define the part and assembly files filter to be the default filter.
oFileDlg.FilterIndex = 1
'Set the title for the dialog.
oFileDlg.DialogTitle = "Save File As"
'Tell the dialog box to throw up and error when cancel is hit by user
oFileDlg.CancelError = True
'Show the file dialog
On Error Resume Next
oFileDlg.ShowSave
'save the user specified file
Dim newFileName As String
newFileName = oFileDlg.FileName
UPDATE:
最后我做了下面的“黑客”,以使事情在处理一段时间仍然工作:
oFileDlg.fileName = sFname & "."
oFileDlg.ShowSave
fullName = Left$(oFileDlg.fileName, Len(oFileDlg.fileName) - 1)
在今后相当一段时间的运行良好Windows 7和Windows 10.不幸的是,Windows 10 Creative更新似乎改变了文件对话框的工作方式。与上面的代码,全名会回来的空白,如果有在名称中没有时间,如果有在名称中期内会从左边截断了从第1期。
我真的不知道在Windows 10是什么改变了,但它几乎毁了我的黑客。在广告素材更新运行之前,Windows 7仍然可以正常运行,而Windows 10仍然正常运行我最终做了以下工作,以使我在上面提到的Windows版本中再次运行。
oFileDlg.fileName = sFname & ".00"
oFileDlg.ShowSave
fullName = Left$(oFileDlg.fileName, Len(oFileDlg.fileName) - 3)
'ThisApplication.CreateFileDialog(oFileDlg)'做了什么? – Brad 2012-07-26 01:33:29
从Autodesk Inventor 2012 COM API参考:“创建新的FileDialog对象的方法。FileDialog对象与Microsoft常用对话框控件相似,并允许您重新使用Inventor打开保存对话框。” – BlueBeardo 2012-07-27 13:58:36