Retrieving an information from filename ...

J

Jiří

Hallo,

I just solve the problem how to retrieve an information from filename string
to the fields (eg. doc number, author, revision etc.). File storage system
works automatically and the export from repository generate the filename in
following form:
<DOC_ID>_<DOC_REV>_<DOC_PROD>_<DOC_NAME>.ext

Each part of this has defined length and it is possible to find exact index
possition of each substring. These strings may be then stored in specific
fields and (after update) printed with the document.

Any suggestions?

Thanks,
George
 
J

Jonathan West

Jiří said:
Hallo,

I just solve the problem how to retrieve an information from filename
string
to the fields (eg. doc number, author, revision etc.). File storage system
works automatically and the export from repository generate the filename
in
following form:
<DOC_ID>_<DOC_REV>_<DOC_PROD>_<DOC_NAME>.ext

Each part of this has defined length and it is possible to find exact
index
possition of each substring. These strings may be then stored in specific
fields and (after update) printed with the document.

Any suggestions?

Look up the following string handling functions in the VBA help

Split, Mid, Left, InStr, InStrRev, Right.

Between them, they provide all the tools you need for this task.


--
Regards
Jonathan West - Word MVP
www.intelligentdocuments.co.uk
Please reply to the newsgroup
Keep your VBA code safe, sign the ClassicVB petition www.classicvb.org
 
D

David Sisson

I'm not sure if you are asking about how to parse filename or data, so
I'll take a stab at the filename.

Sub ParseFields2()
Dim MyString As String

MyString = "<DOC_ID>_<DOC_REV>_<DOC_PROD>_<DOC_NAME>.ext"

Field1$ = Mid(MyString, 2, 6)
Field2$ = Mid(MyString, 11, 7)
Field3$ = Mid(MyString, 21, 8)
Field4$ = Mid(MyString, 32, 8)

MsgBox (Field1$ & vbCr & Field2$ & vbCr & Field3$ & vbCr & Field4$)

End Sub

Or, this one is a little more dynamic. If the field names change,
it'll still parse correctly. (Assuming the chevrons and underscores
don't change.)

Sub ParseFields()

Dim MyString As String
Dim MyArray() As String

MyString = "<DOC_ID>_<DOC_REV>_<DOC_PROD>_<DOC_NAME>.ext"
MyString = Mid(MyString, 2, InStr(MyString, ">.") - 2)
MyString = Replace(MyString, ">_<", ">=<")
MyArray = Split(MyString, ">=<")

MsgBox (MyArray(0) & vbCr & MyArray(1) & vbCr & MyArray(2) & vbCr &
MyArray(3))

End Sub
 
G

Graham Mayor

I rather suspect that the <> bracketed items are variables of unknown
length?

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top