aneilg
asked on
vbscript read a filename, expanded.
I am reading in the following file.
The header of the file is as follows, the issue is I will be reading in different files, so the file could be.
H|20110718|RDCDATA000001SH ELL|000001 |SHELL
H|20110718|RDCDATA000002SH ELL|000002 |SHELL
H|20110718|RDCDATA000001TE XACO|00000 2|TEXACO
H|20110718|RDCDATA000002TE XACO|00000 2|TEXACO
The file format is header, number, filename.
The file is | delimited.
I want to put the filename in a variable and use that in the Process_Claims_File process.
The header of the file is as follows, the issue is I will be reading in different files, so the file could be.
H|20110718|RDCDATA000001SH
H|20110718|RDCDATA000002SH
H|20110718|RDCDATA000001TE
H|20110718|RDCDATA000002TE
The file format is header, number, filename.
The file is | delimited.
I want to put the filename in a variable and use that in the Process_Claims_File process.
'**********************************************************************
' Visual Basic ActiveX Script - Check Sequance Number
'**********************************************************************
Function Main()
Const adOpenForwardOnly = 0
Const adOpenKeyset = 1
Const adOpenDynamic = 2
Const adOpenStatic = 3
'---- CommandTypeEnum Values ----
Const adCmdUnknown = &H0008
Const adCmdText = &H0001
Const adCmdTable = &H0002
Const adCmdStoredProc = &H0004
dim myClaims_File_Name
dim myClaims_Journal
' Instantiate the ADO objects.
set mySourceConn = CreateObject("ADODB.Connection")
set mySourceRecordset = CreateObject("ADODB.Recordset")
'Set the connection properties to point to LMS Server, MIS Claims Data Database.
mySourceConn.Open = ???
mySQLCmdText = "SELECT MAX(Journal_No) + 1 AS nxtJrnlNo FROM ???"
' Execute the mySQLCmdText, and put the data into the myRecordset object.
mySourceRecordset.Open mySQLCmdText, mySourceConn, adOpenKeyset
If mySourceRecordset.RecordCount < 1 Then
Main = DTSTaskExecResult_Failure
Else
' For each record in the recordset I will see if a data load file exists
for countr = 1 to mySourceRecordset.RecordCount
myClaims_Journal = cstr(mySourceRecordset.Fields("nxtJrnlNo").value)
if myClaims_Journal < 10 then
myClaims_Journal = "00000" + cstr(myClaims_Journal)
elseif (myClaims_Journal >= 10 and myClaims_Journal < 100) then
myClaims_Journal = "0000" + cstr(myClaims_Journal)
elseif (myClaims_Journal >= 100 and myClaims_Journal < 1000) then
myClaims_Journal = "000" + cstr(myClaims_Journal)
elseif (myClaims_Journal >= 1000 and myClaims_Journal < 10000) then
myClaims_Journal = "00" + cstr(myClaims_Journal)
end if
set oFSO = CreateObject("Scripting.FileSystemObject")
If oFSO.FileExists(myClaims_File_Name) = True Then
load_success=Process_Claims_File (myClaims_File_Name, myClaims_Journal)
Else
load_success=Process_Claims_File ("\\server\RDCDATA000001SHELL.dat", myClaims_Journal)
End If
if load_success = False then
Main = DTSTaskExecResult_Failure
exit function
end if
mySourceRecordset.MoveNext
Next
Main = DTSTaskExecResult_Success
End If
End Function
Function Process_Claims_File (myClaims_File_Name,Journal_No)
Process_Claims_File = True
dim oFSO
dim x
dim z
const ForAppending=8
' instantiate the Scripting Object
set oFSO = CreateObject("Scripting.FileSystemObject")
' Open the input file
if oFSO.FileExists(myClaims_File_Name) then
set x = oFSO.OpenTextFile(myClaims_File_Name)
else
Process_Claims_File = False
exit function
end if
Do While x.AtEndOfStream <> True
' Read each line, determine the type of record and place in the appropriate file
z = x.readline
if Left(z,1) = "H" then
if Mid(z,32,6) <> Journal_No then
Process_Claims_File = False
exit function
end if
end if
Loop
end function
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Where in your code are you reading the header record now?
~bp
~bp
ASKER
if i crate a function and use
inLine = Split(.ReadLine, "|")
For i = 0 To 3
outline(i) = inLine(i)
Next
inLine = Split(.ReadLine, "|")
For i = 0 To 3
outline(i) = inLine(i)
Next
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
sorry to waste your time bp, but i think i have gone about it the wrong way.
in the above question i asked, i presumed the file had already been read in.
what i need to do is idenfify the file name.
the file will be placed on the above folder. ("\\server\RDCDATA000001SH ELL.dat, myClaims_Journal)
so what i need is RDCDATA000001SHELL.dat, read from the path.
once again sorry..
in the above question i asked, i presumed the file had already been read in.
what i need to do is idenfify the file name.
the file will be placed on the above folder. ("\\server\RDCDATA000001SH
so what i need is RDCDATA000001SHELL.dat, read from the path.
once again sorry..
ASKER
if i do something like, it not returning the full path.
Dim folderName
folderName = "("\\server\?????"
Dim fso
Set fso = CreateObject("Scripting.Fi leSystemOb ject")
Dim fullpath
fullpath = fso.GetAbsolutePathName(fo lderName)
msgbox fullpath
Dim folderName
folderName = "("\\server\?????"
Dim fso
Set fso = CreateObject("Scripting.Fi
Dim fullpath
fullpath = fso.GetAbsolutePathName(fo
msgbox fullpath
You have if statement here:
LL.dat". And as you don't have definied myClaims_File_Name this script always load this file "\\server\RDCDATA000001SHE LL.dat".
If oFSO.FileExists(myClaims_File_Name) = True Then
load_success=Process_Claims_File (myClaims_File_Name, myClaims_Journal)
Else
load_success=Process_Claims_File ("\\server\RDCDATA000001SHELL.dat", myClaims_Journal)
End If
This check if myClaims_File_Name exist then load this file from variable else load file from "\\server\RDCDATA000001SHEASKER
partially answered.
ASKER