我正在使用 Visual Basic 为 Autodesk Inventor 编写宏。我创建了一个调用文件对话框的宏,请参见下面的代码。一切正常,除非用户将文件名放入一个句点和一个大于零的数字。
例如,如果用户将 testfile.test 放入框中并点击确定。当我询问他们使用 .FileName 放在那里的内容时,我得到“testfile.test”。就像我应该的那样。
但是,如果用户放置 testfile.1 或 testfile.10 或 testfile.1mdksj 或任何大于零的数字,则直接跟随我返回“testfile”的句点。由于某种原因,期间和期间之后的所有内容都会被删除。
这是什么原因?这是 Visual Basic 中的错误还是我做错了什么?
'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
更新:
我最终做了以下“hack”以使事情在处理一段时间时仍然有效:
oFileDlg.fileName = sFname & "."
oFileDlg.ShowSave
fullName = Left$(oFileDlg.fileName, Len(oFileDlg.fileName) - 1)
这在 Windows 7 和 Windows 10 上运行了很长一段时间。不幸的是,Windows 10 Creative 更新似乎改变了文件对话框的工作方式。使用上面的代码,如果名称中没有句点,则 fullName 将返回空白,如果名称中有句点,则会从左边的第一个句点截断所有内容。
我不太确定 Windows 10 发生了什么变化,但它几乎摧毁了我的 hack。Windows 7 仍然可以正常工作,而创意更新之前的 Windows 10 可以正常工作。我最终做了以下操作,以使一切在我上面提到的 Windows 版本中再次正常工作。
oFileDlg.fileName = sFname & ".00"
oFileDlg.ShowSave
fullName = Left$(oFileDlg.fileName, Len(oFileDlg.fileName) - 3)