Hi,

Is it possible to use a text file as a database and parse it using
VBScript? For example, let us assume that I have a text file with
following entries:

Identification No Name Date
xpern21 Bob 05/21/05

I want query this file using the Identificaiton number, which will be
unique, and get the remaining details like name & date.

Can I do this using VBScript? If so, can you point me to some example
code to learn this concept?

Thanks for your time,
Ravi

Re: Using a text file as database by Ginolard

Ginolard
Mon May 23 04:37:34 CDT 2005

Ravi,

Yes, it's possible but not very efficient as you will need to read the
file each time and then test each line for the existence of the
Idenfitication number (using Instr or Left) and the get the rest of the
line using more string manipulation (e.g. Mid).


Re: Using a text file as database by Ravi

Ravi
Mon May 23 04:46:48 CDT 2005

Hi,

Thanks for your reply.
What do u suggest?
I would not have access to a database. But, yes, I can have an excel
file with the same data? Would that help?

Ravi


Re: Using a text file as database by Ginolard

Ginolard
Mon May 23 05:01:12 CDT 2005

Ravi,

Vbscript isn't really an efficient front end for any sort of database
work, it's a scripting language after all ;)

An Excel file with the same data would probably be better. You could
then create a Macro/VBA script that would do a similar thing.


Re: Using a text file as database by Nic

Nic
Mon May 23 05:23:16 CDT 2005

Hi Ravi,


> I want query this file using the Identificaiton number, which will be
> unique, and get the remaining details like name & date.

What are you going to do with the recordset?
Is it going to be rendered for a report or for editing?


Nic Roche


"Ravi" <ravikanth.chaganti@gmail.com> wrote in message
news:1116832194.150743.306250@g47g2000cwa.googlegroups.com...
> Hi,
>
> Is it possible to use a text file as a database and parse it using
> VBScript? For example, let us assume that I have a text file with
> following entries:
>
> Identification No Name Date
> xpern21 Bob 05/21/05
>
> I want query this file using the Identificaiton number, which will be
> unique, and get the remaining details like name & date.
>
> Can I do this using VBScript? If so, can you point me to some example
> code to learn this concept?
>
> Thanks for your time,
> Ravi
>



Re: Using a text file as database by Ravi

Ravi
Mon May 23 05:28:15 CDT 2005

Okay...

Let me explain the context of my initial post to give you more
information on why i was preferring text file method.

I have a RIS setup that gives out WinPE ramdisk to image to network
boot clients. I am using this WinPE environment to image client
operating system. Pre-imaging process will use WMI to query SMBIOS
information and retreive system service tag. I have a text file where
in there are mappings of service tag to computer name. So, after
retreiving the service tag, I have to query the text file and retrieve
the associated computer name and then set it as SMBIOS asset tag.

So, my text file in this context would have the same format as the one
I had mentioned in my initial post.

What do you suggest now? I will have access to WSH, HTA, WMI & ADO
Within my WinPE environment.

Thanks for your time,
Ravi


Re: Using a text file as database by McKirahan

McKirahan
Mon May 23 06:19:39 CDT 2005

"Ravi" <ravikanth.chaganti@gmail.com> wrote in message
news:1116832194.150743.306250@g47g2000cwa.googlegroups.com...
> Hi,
>
> Is it possible to use a text file as a database and parse it using
> VBScript? For example, let us assume that I have a text file with
> following entries:
>
> Identification No Name Date
> xpern21 Bob 05/21/05
>
> I want query this file using the Identificaiton number, which will be
> unique, and get the remaining details like name & date.
>
> Can I do this using VBScript? If so, can you point me to some example
> code to learn this concept?
>
> Thanks for your time,
> Ravi
>

I gather that your text file is tab-delimited.

ADO or the Dictionary object are also candidates for a solution.

How many records are in the text file? How many fields?

What are you really trying to do? One or multiple lookups?

Please describe your application in more detail.



Re: Using a text file as database by jeff

jeff
Mon May 23 06:40:58 CDT 2005

On 23 May 2005 00:09:54 -0700, "Ravi" <ravikanth.chaganti@gmail.com>
wrote:

>Hi,
>
>Is it possible to use a text file as a database and parse it using
>VBScript? For example, let us assume that I have a text file with
>following entries:
>
>Identification No Name Date
>xpern21 Bob 05/21/05
>
>I want query this file using the Identificaiton number, which will be
>unique, and get the remaining details like name & date.
>
>Can I do this using VBScript? If so, can you point me to some example
>code to learn this concept?

Look at:

http://www.devguru.com/Technologies/vbscript/quickref/filesystemobject.html
http://www.4guysfromrolla.com/webtech/010401-1.shtml
http://www.codeproject.com/asp/readfile.asp

http://www.carlprothman.net/Default.aspx?tabid=90#ODBCDriverForText
http://www.codeproject.com/database/connectionstrings.asp
http://www.asp101.com/articles/john/connstring/default.asp

Jeff

Re: Using a text file as database by Ravi

Ravi
Mon May 23 06:56:00 CDT 2005

"I gather that your text file is tab-delimited."

Yes. The text file is tab-delimited

"How many records are in the text file? How many fields?"

Around 200 records and 3 fields each.

"What are you really trying to do? One or multiple lookups? "

No multiple lookups. Data in each of the 3 fields and 200 records will
be completely unique.

"Please describe your application in more detail."

Here you go.

Assume that this is my data file:

wstr1s client-001 10.1.1.1
wsed1s client-002 10.1.1.2
..................................................
...................................................
edqr1s client-200 10.1.1.200

Now, my WMI scripts within WinPE environment (check my previous post
for more info) would capture systems service tag. Then the VBScript in
the question should use the service tag captured to parse the above
data file and retrieve client name and IP address into two different
variables. For example, if the service tag is "wstr1s", CName should
contain "client-001" & CIp should contain "10.1.1.1"
At this point, i'll use some more scripts, which i have already
written, to store CName as asset tag information in SMBIOS.

I hope this explains the purpose. Please get back if you have any
questions.
How about changing this to XML format?? just a vague idea..!!!

Thanks for your time,
Ravi


Re: Using a text file as database by Torgeir

Torgeir
Mon May 23 09:57:21 CDT 2005

Ravi wrote:

> "I gather that your text file is tab-delimited."
>
> Yes. The text file is tab-delimited
>
> "How many records are in the text file? How many fields?"
>
> Around 200 records and 3 fields each.
>
> "What are you really trying to do? One or multiple lookups? "
>
> No multiple lookups. Data in each of the 3 fields and 200 records will
> be completely unique.
>
> "Please describe your application in more detail."
>
> Here you go.
>
> Assume that this is my data file:
>
> wstr1s client-001 10.1.1.1
> wsed1s client-002 10.1.1.2
> ..................................................
> ...................................................
> edqr1s client-200 10.1.1.200
>
> Now, my WMI scripts within WinPE environment (check my previous post
> for more info) would capture systems service tag. Then the VBScript in
> the question should use the service tag captured to parse the above
> data file and retrieve client name and IP address into two different
> variables. For example, if the service tag is "wstr1s", CName should
> contain "client-001" & CIp should contain "10.1.1.1"
> At this point, i'll use some more scripts, which i have already
> written, to store CName as asset tag information in SMBIOS.
>
> I hope this explains the purpose. Please get back if you have any
> questions.
> How about changing this to XML format?? just a vague idea..!!!
Hi,

Create this XML file:

<?xml version="1.0" encoding="UTF-8"?>
<ServiceTagList>
<wstr1s>
<ClientName>client-001</ClientName>
<IPAddress>10.1.1.1</IPAddress>
</wstr1s>

<edqr1s>
<ClientName>client-200</ClientName>
<IPAddress>10.1.1.200</IPAddress>
</edqr1s>

</ServiceTagList>


Run this VBScript file (adjust the path/file name in the sFilePath
variable):


'--------------------8<----------------------

sFilePath = "C:\test\data.xml"

' capture systems service tag and assign it to the sServiceTag variable
' Note: Case sensitive to the same value in the XML file
sServiceTag = LCase("Wstr1s")

sXPath = "/ServiceTagList/" & sServiceTag

Set oXMLDoc = CreateObject("MSXML2.DOMDocument")
oXMLDoc.SetProperty "SelectionLanguage", "XPath"
oXMLDoc.Async = False

oXMLDoc.Load sFilePath

If (oXMLDoc.parseError.errorCode <> 0) Then

Set oErr = oXMLDoc.ParseError
WScript.Echo "Could not load file " & sFilePath _
& " , error: " & oErr.Reason

Else

On Error Resume Next
sClientName = oXMLDoc.SelectSingleNode(sXPath & "/ClientName").Text
sIPAddress = oXMLDoc.SelectSingleNode(sXPath & "/IPAddress").Text

If Err.Number <> 0 Then
WScript.Echo _
"Client name/IP address not found in XML file for service tag " _
& sServiceTag
Else
WScript.Echo "Client name: " & sClientName
WScript.Echo "IP address: " & sIPAddress

End If
End If
'--------------------8<----------------------



--
torgeir, Microsoft MVP Scripting and WMI, Porsgrunn Norway
Administration scripting examples and an ONLINE version of
the 1328 page Scripting Guide:
http://www.microsoft.com/technet/scriptcenter/default.mspx

Re: Using a text file as database by ahmed_sami

ahmed_sami
Mon May 23 12:56:10 CDT 2005

i'll demonstrate how to access a comma seperated file via vbs. Suppose that
you have a file called DB.csv formatted as follows

Identification No,Name,Date
xpern21,Bob,05/21/05

then u can create a script file in the same folder with the following code

dim oFSO, oFile
set oFSO = createobject("scripting.filesystemobject")
set oFile = oFSO.opentextfile("DB.csv",1)

do while not oFile.atEndOfStream
arrLines = split(oFile.readline,",",-1,1)
wscript.echo arrLines(0) ' This will always contain
the entries of the first column on each loop cycle
wscript.echo arrLines(1) ' This will always contain
the entries of the second column on each loop cycle
wscript.echo arrLines(2) ' This will always contain
the entries of the third column on each loop cycle
loop
'----------

you can seperate values with tabs, and hence the sixth line of code will be
[arrLines = split(oFile.readLine,vbTab,-1,1)]

cheers,
S@mi




"Ravi" <ravikanth.chaganti@gmail.com> wrote in message
news:1116844095.776105.242550@g44g2000cwa.googlegroups.com...
> Okay...
>
> Let me explain the context of my initial post to give you more
> information on why i was preferring text file method.
>
> I have a RIS setup that gives out WinPE ramdisk to image to network
> boot clients. I am using this WinPE environment to image client
> operating system. Pre-imaging process will use WMI to query SMBIOS
> information and retreive system service tag. I have a text file where
> in there are mappings of service tag to computer name. So, after
> retreiving the service tag, I have to query the text file and retrieve
> the associated computer name and then set it as SMBIOS asset tag.
>
> So, my text file in this context would have the same format as the one
> I had mentioned in my initial post.
>
> What do you suggest now? I will have access to WSH, HTA, WMI & ADO
> Within my WinPE environment.
>
> Thanks for your time,
> Ravi
>



Re: Using a text file as database by Christoph

Christoph
Mon May 23 15:51:11 CDT 2005

23.05.2005 09:09, Ravi schrieb:
> Hi,
>
> Is it possible to use a text file as a database and parse it using
> VBScript? For example, let us assume that I have a text file with
> following entries:
>
> Identification No Name Date
> xpern21 Bob 05/21/05
>
> I want query this file using the Identificaiton number, which will be
> unique, and get the remaining details like name & date.
>
> Can I do this using VBScript? If so, can you point me to some example
> code to learn this concept?

You can use the Jet Engines textdriver to read-write tab/comma-separated
text files (almost) like to 'real' databases.

see:
http://groups.google.de/group/microsoft.public.vb.general.discussion/msg/933de857648898cd

--
Gruesse, Christoph

Rio Riay Riayo - Gordon Sumner, 1979

Re: Using a text file as database by Ravi

Ravi
Mon May 23 22:34:23 CDT 2005

Thanks Torgeir.

Guys, I am opting for the XML based method. It is easier to maintain
data and the data looks very clear.

Thanks once again for your time,
Ravi