Skip to content
Newer
Older
100644 174 lines (146 sloc) 7.33 KB
71cb477 @emilefyon Update of filenames
authored
1 Attribute VB_Name = "LIB_File"
29488ee Signed-off-by: unknown <EMFYON@LBNL07489.corp.capgemini.com>
unknown authored
2 '---------------------------------------------------------------------------------------------------------------------------------------------
3 '
4 ' File Library v0.1
5 '
6 '
7 ' Functions lists
8 ' ---------------
9 '
10 ' + Function writeFile (ByVal file As String, ByVal content As String) As String : overwrite the content specified in the file specified.
11 ' * Specifications / limitations
12 ' - If the file does not exists, the file is created
13 ' - The folder has to exist
14 ' * Arguments
15 ' - file as String : the full path of the file
16 ' - content as String : the content that has to be written into the file
17 '
18 ' + Function readFile(ByVal file As String) As String : read the content of a file and return a single line with all the content
19 ' * Specifications / limitations
20 ' - The file has to Exists, no error handling
21 ' - The content is retrieved without any line returns (line returns are replaced by space)
22 ' * Arguments
23 ' - file as String : the full path of the file
24 ' + Function readFileAndTruncate(ByVal file As String) As String : calls readFile() and then truncate the text to 30000 characters in order to avoid Excel limitations
25 ' * Specifications / limitations
26 ' - The file has to Exists, no error handling
27 ' - The content is retrieved without any line returns (line returns are replaced by space)
28 ' - Only the 30.000 first characters are retrieved
29 ' * Arguments
30 ' - file as String : the full path of the file
31 '
32 ' Revisions history
33 ' -----------------
34 ' - Emile Fyon 11/07/2012 v0.1 Creation
35 '
36 '---------------------------------------------------------------------------------------------------------------------------------------------
37
38
39
40
41
42
43 '---------------------------------------------------------------------------------------------------------------------------------------------
44 ' + writeFile (ByVal file As String, ByVal content As String) : overwrite the content specified in the file specified.
45 ' * Specifications / limitations
46 ' - If the file does not exists, the file is created
47 ' - The folder has to exist
48 ' * Arguments
49 ' - file as String : the full path of the file
50 ' - content as String : the content that has to be written into the file
51 '
52 ' Last edition date : 11/07/2012
53 '
54 ' Revisions history
55 ' -----------------
56 ' - Emile Fyon 11/07/2012 Creation
57 '
58 '---------------------------------------------------------------------------------------------------------------------------------------------
59
6c3b6f4 @emilefyon Update and integration of a personal Excel Add-in
authored
60 Function writeFile(ByVal File As String, ByVal content As String) As String
29488ee Signed-off-by: unknown <EMFYON@LBNL07489.corp.capgemini.com>
unknown authored
61
6c3b6f4 @emilefyon Update and integration of a personal Excel Add-in
authored
62 Open File For Output As #1
29488ee Signed-off-by: unknown <EMFYON@LBNL07489.corp.capgemini.com>
unknown authored
63 Print #1, content
64 Close #1
65
66 writeFile = "File updated yet"
67
68 End Function
69
70 '---------------------------------------------------------------------------------------------------------------------------------------------
71 ' + readFile(ByVal file As String) As String : read the content of a file and return a single line with all the content
72 ' * Specifications / limitations
73 ' - The file has to Exists, no error handling
74 ' - The content is retrieved without any line returns (line returns are replaced by space)
75 ' * Arguments
76 ' - file as String : the full path of the file
71cb477 @emilefyon Update of filenames
authored
77 ' - Optional createFile as Boolean : indicates if we have to create the file if it does not exists (default False)
29488ee Signed-off-by: unknown <EMFYON@LBNL07489.corp.capgemini.com>
unknown authored
78 '
79 '
80 ' Last edition date : 11/07/2012
81 '
82 ' Revisions history
83 ' -----------------
84 ' - Emile Fyon 11/07/2012 Creation
71cb477 @emilefyon Update of filenames
authored
85 ' - Emile Fyon 12/07/2012 Added functionality in order to create the file if it does not exists
29488ee Signed-off-by: unknown <EMFYON@LBNL07489.corp.capgemini.com>
unknown authored
86 '
87 '---------------------------------------------------------------------------------------------------------------------------------------------
88
71cb477 @emilefyon Update of filenames
authored
89 Function readFile(ByVal File As String, Optional createFile As Boolean) As String
90
91 If (IsMissing(createFile)) Then createFile = False
92
93 If (fileExists(File) = False) Then
94 If (createFile = True) Then
95 temp = writeFile(File, "")
96 Else
97 readFile = "Error : File does not exists"
98 Exit Function
99 End If
100 End If
101
29488ee Signed-off-by: unknown <EMFYON@LBNL07489.corp.capgemini.com>
unknown authored
102 Dim MyString, MyNumber
6c3b6f4 @emilefyon Update and integration of a personal Excel Add-in
authored
103 Open File For Input As #1 ' Open file for input.
29488ee Signed-off-by: unknown <EMFYON@LBNL07489.corp.capgemini.com>
unknown authored
104 fileContent = ""
105 Do While Not EOF(1) ' Loop until end of file.
106 Line Input #1, MyString
107 Debug.Print MyString
108 fileContent = fileContent & MyString & " "
109 Loop
110 Close #1 ' Close file.
111 readFile = fileContent
112 End Function
113
114 '---------------------------------------------------------------------------------------------------------------------------------------------
115 ' + readFileAndTruncate(ByVal file As String) As String : calls readFile() and then truncate the text to 30000 characters in order to avoid Excel limitations
116 ' * Specifications / limitations
117 ' - The file has to Exists, no error handling
118 ' - The content is retrieved without any line returns (line returns are replaced by space)
119 ' - Only the 30.000 first characters are retrieved
120 ' * Arguments
121 ' - file as String : the full path of the file
122 '
123 '
124 ' Last edition date : 11/07/2012
125 '
126 ' Revisions history
127 ' -----------------
128 ' - Emile Fyon 11/07/2012 Creation
129 '
130 '---------------------------------------------------------------------------------------------------------------------------------------------
131
132
71cb477 @emilefyon Update of filenames
authored
133 Function readFileAndTruncate(ByVal File As String, Optional createFile As Boolean) As String
29488ee Signed-off-by: unknown <EMFYON@LBNL07489.corp.capgemini.com>
unknown authored
134
71cb477 @emilefyon Update of filenames
authored
135 If (IsMissing(createFile)) Then createFile = False
136 readFileAndTruncate = Left(readFile(File, createFile), 30000)
29488ee Signed-off-by: unknown <EMFYON@LBNL07489.corp.capgemini.com>
unknown authored
137
138 End Function
71cb477 @emilefyon Update of filenames
authored
139
140 '---------------------------------------------------------------------------------------------------------------------------------------------
141 ' + readFileAndTruncate(ByVal file As String) As String :
142 ' * Description : It is used to validate file path/link from a string variable. Return True if the file exist.
143 ' * Specifications / limitations
144 ' - The file has to Exists, no error handling
145 ' - The content is retrieved without any line returns (line returns are replaced by space)
146 ' - Only the 30.000 first characters are retrieved
147 ' * Arguments
148 ' - strFileFullPath As String : Full path to the file input file including the file name and the file extension.
149 ' * Output
150 '
151 '
152 '
153 ' Last edition date : 11/07/2012
154 '
155 ' Revisions history
156 ' -----------------
157 ' - Georgiev Velin 20/12/2011 Creation velin.georgiev@gmail.com
158 ' - Emile Fyon 11/07/2012 Creation emilefyon@gmail.com
159 '
160 '
161 '---------------------------------------------------------------------------------------------------------------------------------------------
162
163 Function fileExists(strFileFullPath As String) As Boolean
164
165
166 Dim objFSO As Object
167 Set objFSO = CreateObject("Scripting.FileSystemObject")
168 If objFSO.fileExists(strFileFullPath) Then fileExists = True
169 Set objFSO = Nothing
170
171
172 End Function
173
Something went wrong with that request. Please try again.