Jump to content

ActiveX Script Questions


kwilliams

Recommended Posts

I'm using this ActiveX Script within a DTS package that imports data from a .txt file into a DB table. This is a sample of what the text file looks like:

text_registrant_id,text_name,date_of_birth01,01.01,01/01/198102,02.02,02/02/198203,03.03,03/03/1983...and so on

...and here's the ActiveX Script:

'**********************************************************************'  Visual Basic ActiveX Script'************************************************************************Function Main()	Main = DTSTaskExecResult_Success	Dim fso, f, i, j, k, t, row, datetime_array, StartingKeyValue, StartingOtherValue, NewStartingKey, NewStartingOther, swap_pos, DimensionToSort, OtherDimension	Dim NewFile, OldFile2, log, incoming, incoming_files, dir_count, willholddate	Set fso = CreateObject("Scripting.FileSystemObject")	Set incoming = fso.GetFolder("\\SERVERNAME\DIRECTORY\FOLDER1\") 	Set incoming_files = incoming.Files	dir_count = incoming_files.Count	ReDim datetime_array(dir_count, 1)	' *** This loop will load the array with the DateLastModified file attribute ***	For Each k in incoming_files  datetime_array(i, 0) = k.Name  datetime_array(i, 1) = k.DateLastModified  i = i + 1	Next 	' *** This loop will perform the DateTime sort ***	Const column = 1	DimensionToSort = 1	OtherDimension = 0	For row = 0 To dir_count - 1  StartingKeyValue = datetime_array ( row, DimensionToSort )  StartingOtherValue = datetime_array ( row, OtherDimension )  NewStartingKey = datetime_array ( row, DimensionToSort )  NewStartingOther = datetime_array ( row, OtherDimension )  swap_pos = row      For j = row + 1 to dir_count - 1 	 If datetime_array ( j, DimensionToSort ) < NewStartingKey Then    swap_pos = j    NewStartingKey = datetime_array ( j, DimensionToSort )    NewStartingOther = datetime_array ( j, OtherDimension ) 	 End If  Next  If swap_pos <> row Then 	 datetime_array ( swap_pos, DimensionToSort ) = StartingKeyValue 	 datetime_array ( swap_pos, OtherDimension ) = StartingOtherValue 	 datetime_array ( row, DimensionToSort ) = NewStartingKey 	 datetime_array ( row, OtherDimension ) = NewStartingOther  End If		Next	' *** This is where the file gets set ***	NewFile = "\\SERVERNAME\DIRECTORY\FOLDER1\" & datetime_array(dir_count - 1, 0)	RenamedFile = "\\SERVERNAME\DIRECTORY\FOLDER1\new_export.txt"	OldFile = "\\SERVERNAME\DIRECTORY\reg_voters2\" & datetime_array(dir_count - 1, 0)	Import = "\\SERVERNAME\DIRECTORY\reg_voters2\new_export.txt"	' *** Rename the file to the name that the Data Source expects ***	If fso.FileExists(NewFile) Then	fso.MoveFile NewFile, RenamedFile	fso.CopyFile RenamedFile, Import	fso.DeleteFile RenamedFile	End IfEnd Function

It works great, but now I need to do the following, and I'm not sure how to include it in this code.1) Split Precinct_ID and Part_ID (one value = "01.01") into two values ("01" and "01")2) 'Split and reformat DOB (from "01/01/1981" to "19810101")This is what I have so far:

Function newImport()	'Split Precinct_ID and Part_ID	Dim OldPP As String = text_name	If OldPP <> "" Then  Dim Precinct_ID As String = Substring-before(OldPP, ".")  Part_ID As String = Substring-after(OldPP, ".")	End If	'Split and reformat DOB	Dim FullDate As String = date_of_birth	If FullDate <> "" Then  Dim OldDate As String = RTrim(date_of_birth)  Dim Date_mm As String = Substring-before(OldDate, "/")  Dim Date_yyyy As String = Substring-after(OldDate, "/")  Dim Date_dd As String = Substring-before(Date_ddyyyy, "/")  Dim Date_ddyyyy As String = Substring-after(Date_ddyyyy, "/")  Dim NewDate As String = Date_yyyy + Date_mm + Date_dd	End IfEnd Function

...but I'm not sure how to include it within the ActiveX Script, being that I'm somewhat of a newbie. If anyone can help me out or point me in the right direction, it would be greatly appreciated. Thanks.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...