Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 192
  • Last Modified:

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

0
aneilg
Asked:
aneilg
  • 5
  • 2
  • 2
2 Solutions
 
X_layerCommented:
You can put this right after variable declarations:
dim myClaims_File_Name
dim myClaims_Journal

myClaims_File_Name = "c:\temp\somefile.dat"

Open in new window

And then that file will be used.
0
 
aneilgAuthor Commented:
yeah but i will not know what the filename is until i have read the header record and got the file name from that.

0
 
Bill PrewCommented:
Where in your code are you reading the header record now?

~bp
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
aneilgAuthor Commented:
if i crate a function and use
          inLine = Split(.ReadLine, "|")
          For i = 0 To 3
            outline(i) = inLine(i)
          Next
0
 
Bill PrewCommented:
Wouldn't you just do the following, where XXXXXXXX would be the string variable where you have "read" the header row into?

     strFields = Split(XXXXXXXX, "|")
     myClaims_File_Name = strFields(2) & ".dat"

~bp
0
 
aneilgAuthor Commented:
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..
0
 
aneilgAuthor Commented:
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

0
 
X_layerCommented:
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".
0
 
aneilgAuthor Commented:
partially answered.
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

  • 5
  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now