TAILIEUCHUNG - Mastering Excel 2003 Programming with VBA phần 3

không hợp lệ 'thư khac - không thay đổi bất cứ điều gì Cuối Nếu End Sub' Trả về vị trí hoặc chỉ số của nhân vật đầu tiên của tên tập tin một tên đầy đủ "tên đầy đủ bao gồm một con đường và một tên tập tin ra để cung cấp cho bạn một cách hữu ích để cô lập các thành phần đường dẫn và tên file từ một tên tập tin đầy đủ, | common file operations simplified 103 sPath Left sFullName nPos - 1 Else Invalid sFullName - don t change anything End If End Sub Returns the position or index of the first character of the filename given a full name A full name consists of a path and a filename Ex. FileNamePosition C Testing 11 Function FileNamePosition sFullName As String As Integer Dim bFound As Boolean Dim nPosition As Integer bFound False nPosition Len sFullName Do While bFound False Make sure we were not dealt a zero-length string If nPosition 0 Then Exit Do We are looking for the first from the right. If Mid sFullName nPosition 1 Then bFound True Else Working right to left nPosition nPosition - 1 End If Loop If bFound False Then FileNamePosition 0 Else FileNamePosition nPosition End If End Function In addition to providing you with a useful way to isolate path- and filename components from a full filename Listing includes one brand new concept which may not be apparent at first glance output parameters. Take a look at the declaration of the BreakdownName subroutine. Sub BreakdownName sFullName As String _ ByRef sName As String _ ByRef sPath As String 104 chapter 5 exploring the application object See the ByRef keyword in this declaration This keyword indicates that when if the BreakdownName function modifies these parameters the procedure that called BreakdownName will see the changes made to the variables. Listing uses a simple procedure to test the BreakdownName procedure. You simply use the Get-SaveAsFilename method to obtain a full filename and pass the filename to the BreakdownName procedure along with two empty variables sName and sPath. BreakdownName uses the FileNamePosition function to locate the beginning of the filename component. Once you know that it is simple to break the name down into the path- and filename components using the VBA Left and Right functions. Both Left and Right take a string variable and return the specified number of characters from either .

Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.