Link to home
Start Free TrialLog in
Avatar of aneilg
aneilgFlag for United Kingdom of Great Britain and Northern Ireland

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|RDCDATA000001SHELL|000001|SHELL
H|20110718|RDCDATA000002SHELL|000002|SHELL
H|20110718|RDCDATA000001TEXACO|000002|TEXACO
H|20110718|RDCDATA000002TEXACO|000002|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.

'**********************************************************************
'  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

Open in new window

SOLUTION
Avatar of X Layer
X Layer
Flag of Slovenia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of aneilg

ASKER

yeah but i will not know what the filename is until i have read the header record and got the file name from that.

Avatar of Bill Prew
Bill Prew

Where in your code are you reading the header record now?

~bp
Avatar of aneilg

ASKER

if i crate a function and use
          inLine = Split(.ReadLine, "|")
          For i = 0 To 3
            outline(i) = inLine(i)
          Next
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of aneilg

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\RDCDATA000001SHELL.dat, myClaims_Journal)

so what i need is RDCDATA000001SHELL.dat, read from the path.

once again sorry..
Avatar of aneilg

ASKER

if i do something like, it not returning the full path.
      Dim folderName
      folderName =  "("\\server\?????"

      Dim fso
      Set fso = CreateObject("Scripting.FileSystemObject")  
      Dim fullpath
      fullpath = fso.GetAbsolutePathName(folderName)
      
      msgbox  fullpath

You have if statement here:
       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

Open in new window

This check if myClaims_File_Name exist then load this file from variable else load file from "\\server\RDCDATA000001SHELL.dat". And as you don't have definied myClaims_File_Name this script always load this file "\\server\RDCDATA000001SHELL.dat".
Avatar of aneilg

ASKER

partially answered.