No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.

773 líneas
73KB

  1. Option Explicit
  2. Dim dev:dev = true
  3. Dim outFile
  4. Dim WaitTime:WaitTime = 15000
  5. Dim DataDirectory
  6. Dim ExportDirectory
  7. Dim PurpleEnvelopeProofReport,OfficeCopiesProofReport
  8. Dim WshShell:Set WshShell = WScript.CreateObject("Wscript.Shell")
  9. Dim oConn:Set oConn = WScript.CreateObject("ADODB.Connection")
  10. Dim ConnectionString
  11. Dim objFSO:Set objFSO = CreateObject("Scripting.FileSystemObject")
  12. Dim glob:set glob = CreateObject("Chilkat_9_5_0.Global")
  13. Dim success:success = glob.UnlockBundle("KENTCM.CB1022025_RGzBPM5J655e")
  14. If (success <> 1) Then
  15. WriteLine(glob.LastErrorText)
  16. WScript.Quit
  17. End If
  18. Dim objCSV:Set objCsv = CreateObject("Chilkat_9_5_0.Csv")
  19. Dim WorkingDirectory:WorkingDirectory = Replace(WScript.ScriptFullName,WScript.ScriptName,"")
  20. Select Case dev
  21. Case "local"
  22. DataDirectory = "C:\Share\TrackingDataImport\"
  23. ExportDirectory = "C:\Share\TrackingDataExport\"
  24. ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Jet OLEDB:Engine Type=5;Data Source=F:\Development\Tracking_Kits\Data\webdata - Copy.mdb;"
  25. PurpleEnvelopeProofReport = "F:\Development\Tracking_Kits\Data\Proofs.rep"
  26. OfficeCopiesProofReport="F:\Development\Tracking_Kits\Data\Office-Copy-Proof.rep"
  27. set outFile = objFSO.CreateTextFile("C:\Share\TrackingDataExport\temp.csv",True)
  28. Case true
  29. DataDirectory = "C:\Share\TrackingDataImport\"
  30. ExportDirectory = "C:\Share\TrackingDataExport\"
  31. ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Jet OLEDB:Engine Type=5;Data Source=C:\Git Repos\tracking_kits\Data\webdata - Copy.mdb;"
  32. PurpleEnvelopeProofReport = "C:\Git Repos\tracking_kits\Data\Proofs.rep"
  33. OfficeCopiesProofReport = "C:\Git Repos\tracking_kits\Data\Office-Copy-Proof.rep"
  34. set outFile = objFSO.CreateTextFile("C:\Share\TrackingDataExport\temp.csv",True)
  35. Case Else
  36. DataDirectory = "\\kci-syn-cl01\PC Transfer\TrackingDataImport"
  37. ExportDirectory = "\\kci-syn-cl01\PC Transfer\TrackingDataExport\"
  38. ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Jet OLEDB:Engine Type=5;Data Source=C:\inetpub\Data\webdata - Copy.mdb;"
  39. PurpleEnvelopeProofReport ="C:\inetpub\tracking\Data\Proofs.rep"
  40. OfficeCopiesProofReport = "C:\inetpub\tracking\Data\Office-Copy-Proof.rep"
  41. set outFile = objFSO.CreateTextFile("\\kci-syn-cl01\PC Transfer\TrackingDataExport\temp.csv",True)
  42. End Select
  43. 'ToDo create a checkstatus function so I dont need four functions of create a case switch that responds to the status of jobs
  44. Dim KitID:CheckForFiles:KitID = CheckForJobsToCass()
  45. If KitID > 0 Then
  46. ExportMMCsv(KitID)
  47. RunMailManager
  48. ImportCass
  49. End If
  50. KitID = CheckStatusFor("Ready to Assign Labels"):If KitID > 0 Then:createTrackingInfoForKit(KitID):End If
  51. KitID = CheckStatusFor("Ready For Export"):If KitID > 0 Then:CreateExportForSnailWorks(KitID):End If
  52. KitID = CheckStatusFor("Ready to Proof"):If KitID > 0 Then:CreateProofForJurisdiction(KitID):End If
  53. KitID = CheckStatusFor("Ready For Inkjet Export"):If KitID > 0 Then:ExportInkjetFile(KitID):End If
  54. if dev = False then
  55. CheckSnailWorksPurpleEnvelopeExport
  56. CheckSnailWorksTrakingKitExport
  57. End if
  58. WScript.Quit
  59. Sub CheckSnailWorksPurpleEnvelopeExport
  60. Dim Sftp:set Sftp = CreateObject("Chilkat_9_5_0.SFtp")
  61. Dim objFolder
  62. Dim success
  63. Set objFolder = objFSO.GetFolder("\\kci-syn-cl01\PC Transfer\TrackingDataExport\Export Purple Envelopes")
  64. If objFolder.Files.Count > 0 Then
  65. success = Sftp.Connect("sftp.snailworks.com",22)
  66. success = Sftp.AuthenticatePw("KCIHotFolder2024FTPUser","Z!4WXLSQMM#f")
  67. success = Sftp.InitializeSftp()
  68. Dim file
  69. For Each file In objFolder.Files
  70. debug.WriteLine file.Path
  71. Dim handle:handle = Sftp.OpenFile(file.Name,"writeOnly","createTruncate")
  72. Sftp.UploadFile handle,file.Path
  73. Sftp.CloseHandle handle
  74. file.Delete
  75. Next
  76. End If
  77. End Sub
  78. Sub CheckSnailWorksTrakingKitExport
  79. Dim Sftp:set Sftp = CreateObject("Chilkat_9_5_0.SFtp")
  80. Dim objFolder
  81. Dim success
  82. Set objFolder = objFSO.GetFolder("\\kci-syn-cl01\PC Transfer\TrackingDataExport\Export Tracking Kits")
  83. If objFolder.Files.Count > 0 Then
  84. success = Sftp.Connect("sftp.snailworks.com",22)
  85. success = Sftp.AuthenticatePw("KCI2024Type2FTPUser","Z!NXVRV5SH#f")
  86. success = Sftp.InitializeSftp()
  87. Dim file
  88. For Each file In objFolder.Files
  89. debug.WriteLine file.Path
  90. Dim handle:handle = Sftp.OpenFile(file.Name,"writeOnly","createTruncate")
  91. Sftp.UploadFile handle,file.Path
  92. Sftp.CloseHandle handle
  93. file.Delete
  94. Next
  95. End If
  96. End Sub
  97. Function ExportInkjetFile(KitID)
  98. If oConn.State = 0 Then:oConn.Open(ConnectionString):End If
  99. Dim KitRs:set KitRs = oConn.Execute("Select * From [Kit] Where [ID] =" & KitID & ";")
  100. Dim KitLabelsRs: Set KitLabelsRs = oConn.Execute("Select * FROM (SELECT IIf(Len([PRECINCT]) = 1, '0' & [PRECINCT] & Right([BALLOT_NUMBER],4), [PRECINCT] & Right([BALLOT_NUMBER],4)) AS SORT_ORDER," &_
  101. "InkjetRecords.ID, InkjetRecords.KitID, InkjetRecords.VOTERID, InkjetRecords.LASTNAME," &_
  102. " InkjetRecords.FIRSTNAME, InkjetRecords.MIDDLENAME, InkjetRecords.SUFFIX, InkjetRecords.PRECINCT," &_
  103. " InkjetRecords.ADDRESS1, InkjetRecords.ADDRESS2, InkjetRecords.ADDRESS3, InkjetRecords.ADDRESS4," &_
  104. " InkjetRecords.ADDRESS5, InkjetRecords.APPSENT, InkjetRecords.APPRETURNED, InkjetRecords.BALSENT," &_
  105. " InkjetRecords.BALRETURNED, InkjetRecords.CountingBoard, InkjetRecords.UOCAVASTATUS, InkjetRecords.EMAILADDRESS," &_
  106. " InkjetRecords.PHONENUMBER, InkjetRecords.BALLOT_NUMBER, InkjetRecords.CassADDRESS1, InkjetRecords.CassADDRESS2," &_
  107. " InkjetRecords.CassADDRESS3, InkjetRecords.CassADDRESS4, InkjetRecords.CassADDRESS5, InkjetRecords.KitLabelID," &_
  108. " KitLabels.ID, KitLabels.KitID, KitLabels.OutboundSerial, KitLabels.InBoundSerial, KitLabels.OutboundIMB," &_
  109. " KitLabels.InBoundIMB, KitLabels.OutboundIMBDigits, KitLabels.InBoundIMBDigits, KitLabels.OutboundIMBPNG," &_
  110. " KitLabels.INBOUNDIMBPNG, KitLabels.SetNumber" &_
  111. " FROM InkjetRecords" &_
  112. " LEFT JOIN [KitLabels] ON InkjetRecords.KitLabelID = KitLabels.ID" & _
  113. " WHERE InkjetRecords.KitID =" & KitID & ") as [Data] Order By SORT_ORDER Desc;")
  114. Dim JurisdictionRs:Set JurisdictionRs = oConn.Execute("SELECT * FROM Jurisdiction WHERE JCode ='" & KitRs("Jcode").Value & "';")
  115. Dim ContactRs:Set ContactRs = oConn.Execute("SELECT * FROM Contacts WHERE [JURISCODE] ='" & KitRs("Jcode").Value & "';")
  116. Dim ExportFileName:ExportFileName = objFSO.GetBaseName(KitRs("Filename")) & ".csv"
  117. If Not objFSO.FolderExists(ExportDirectory & KitRs("JobNumber").Value & "-" & JurisdictionRs("Name").value) Then:objFSO.CreateFolder(ExportDirectory & KitRs("JobNumber").Value & "-" & JurisdictionRs("Name").value):End If
  118. If objFSO.FileExists(ExportDirectory & KitRs("JobNumber").Value & "-" & JurisdictionRs("Name").value & "/" & ExportFileName) Then:objFSO.DeleteFile(ExportDirectory & KitRs("JobNumber").Value & "-" & JurisdictionRs("Name").value & "/" & ExportFileName):End If
  119. Dim ElectionDate:ElectionDate=GetSetting("ElectionDate")
  120. Dim objInkjetCSV:Set objInkJetCSV = CreateObject("Chilkat_9_5_0.Csv")
  121. objInkjetCSV.HasColumnNames = 1
  122. objInkjetCSV.EnableQuotes = 1
  123. objInkjetCSV.SetColumnName 0,"Full Name"
  124. objInkjetCSV.SetColumnName 1,"Address 1"
  125. objInkjetCSV.SetColumnName 2,"Address 2"
  126. objInkjetCSV.SetColumnName 3,"Address 3"
  127. objInkjetCSV.SetColumnName 4,"Address 4"
  128. objInkjetCSV.SetColumnName 5,"IM barcode Characters"
  129. objInkjetCSV.SetColumnName 6,"Precinct"
  130. objInkjetCSV.SetColumnName 7,"Ballot ID"
  131. objInkjetCSV.SetColumnName 8,"Ballot Number"
  132. objInkjetCSV.SetColumnName 9,"Jurisdiction code"
  133. objInkjetCSV.SetColumnName 10,"Election Date"
  134. objInkJetCSV.SetColumnName 11,"Combined Pct_Ballot Num"
  135. objInkJetCSV.SetColumnName 12,"Title"
  136. objInkJetCSV.SetColumnName 13,"G2 Full Name"
  137. objInkJetCSV.SetColumnName 14,"G2 Company"
  138. objInkJetCSV.SetColumnName 15,"G2 Alternate 1 Address"
  139. objInkJetCSV.SetColumnName 16,"G2 Delivery Address"
  140. objInkJetCSV.SetColumnName 17,"G2 City St ZIP+4"
  141. objInkJetCSV.SetColumnName 18,"G2 IM barcode Characters"
  142. objInkJetCSV.SetColumnName 19,"Matching Code"
  143. Dim AddressArray
  144. Dim row:row = 0
  145. While Not KitLabelsRs.EOF
  146. AddressArray = CompressArray(Array(KitLabelsRs("CassADDRESS1").Value,KitLabelsRs("CassADDRESS2").Value,KitLabelsRs("CassADDRESS3").Value,KitLabelsRs("CassADDRESS4").Value,KitLabelsRs("CassADDRESS5").Value))
  147. objInkjetCSV.SetCellByName row,"Full Name",AddressArray(0)
  148. objInkjetCSV.SetCellByName row,"Address 1",AddressArray(1)
  149. objInkjetCSV.SetCellByName row,"Address 2",AddressArray(2)
  150. objInkjetCSV.SetCellByName row,"Address 3",AddressArray(3)
  151. objInkjetCSV.SetCellByName row,"Address 4",AddressArray(4)
  152. If KitRs("OutboundSTID") <> "0" Then
  153. objInkJetCSV.SetCellByName row,"IM barcode Characters",KitLabelsRs("OutboundIMBDigits").Value
  154. End If
  155. objInkJetCSV.SetCellByName row,"Precinct",KitLabelsRs("PRECINCT").Value
  156. objInkJetCSV.SetCellByName row,"Ballot ID","*" & KitLabelsRs("VOTERID").Value & "*"
  157. objInkJetCSV.SetCellByName row,"Ballot Number",TrimLeadingZeros(KitLabelsRs("BALLOT_NUMBER").Value)
  158. objInkJetCSV.SetCellByName row,"Jurisdiction code",KitRs("Jcode").Value
  159. objInkJetCSV.SetCellByName row,"Election Date",ElectionDate
  160. objInkJetCSV.SetCellByName row,"Combined Pct_Ballot Num",KitLabelsRs("PRECINCT").Value & TrimLeadingZeros(KitLabelsRs("BALLOT_NUMBER").Value)
  161. objInkjetCSV.SetCellByName row,"Title",CleanNull(ContactRs("Title").Value)
  162. objInkJetCSV.SetCellByName row,"G2 Full Name",JurisdictionRs("Name").Value
  163. objInkJetCSV.SetCellByName row,"G2 Company",JurisdictionRs("Mailing_Address").Value
  164. objInkJetCSV.SetCellByName row,"G2 Alternate 1 Address",JurisdictionRs("CSZ").Value
  165. objInkJetCSV.SetCellByName row,"G2 Delivery Address",""
  166. objInkJetCSV.SetCellByName row,"G2 City St ZIP+4",""
  167. ' .Write(Truncate(Choice(IsNull(KitRs("InboundSTID")),"", _
  168. 'KitLabelsRs("InBoundIMBDigits").Value),31))
  169. objInkJetCSV.SetCellByName row,"G2 IM barcode Characters",Choice(IsNull(KitRs("InboundSTID")),JurisdictionRs("IMB_Digits").Value,KitLabelsRs("InBoundIMBDigits").Value)
  170. objInkJetCSV.SetCellByName row,"Matching Code",KitRs("Jcode").Value & TrimLeadingZeros(KitLabelsRs("PRECINCT").Value) & TrimLeadingZeros(KitLabelsRs("BALLOT_NUMBER").Value)
  171. 'Where do we put the roundtrip IMB
  172. row = row + 1
  173. KitLabelsRs.MoveNext
  174. Wend
  175. If KitRs("OfficeCopiesAmount").Value > 0 Then
  176. dim s
  177. For s = 0 to KitRs("OfficeCopiesAmount").Value -1
  178. objInkjetCSV.SetCellByName row + s,"Title",CleanNull(ContactRs("Title").Value)
  179. objInkJetCSV.SetCellByName row + s,"G2 Full Name",JurisdictionRs("Name").Value
  180. objInkJetCSV.SetCellByName row + s,"G2 Company",JurisdictionRs("Mailing_Address").Value
  181. objInkJetCSV.SetCellByName row + s,"G2 Alternate 1 Address",JurisdictionRs("CSZ").Value
  182. objInkJetCSV.SetCellByName row + s,"G2 Delivery Address",""
  183. objInkJetCSV.SetCellByName row + s,"G2 City St ZIP+4",""
  184. objInkJetCSV.SetCellByName row + s,"G2 IM barcode Characters",JurisdictionRs("IMB_Digits").Value
  185. Next
  186. End If
  187. objInkjetCSV.SaveFile(ExportDirectory & KitRs("JobNumber").Value & "-" & JurisdictionRs("Name").value & "/" & ExportFileName)
  188. oConn.Execute("UPDATE KIT SET [Status] ='Done',[InkJetJob]=1 WHERE [ID] =" & KitID & ";")
  189. If KitRs.State = 1 Then:KitRs.Close:End If
  190. If ContactRs.State =1 Then:ContactRs.Close:End If
  191. If KitLabelsRs.State = 1 Then:KitLabelsRs.Close: End If
  192. If JurisdictionRs.State = 1 Then:JurisdictionRs.Close:End If
  193. If oConn.State = 1 Then:oConn.Close:End If
  194. End Function
  195. Function CheckStatusFor(StatusString)
  196. If oConn.State = 0 Then:oConn.Open(ConnectionString):End If
  197. Dim rs:Set rs = oConn.Execute("Select TOP 1 [ID] FROM [Kit] Where Status ='" & StatusString & "' and JobType='Purple Envelopes';")
  198. If Not rs.EOF Then
  199. CheckStatusFor = rs("ID").value
  200. Else
  201. CheckStatusFor = 0
  202. End If
  203. If rs.State = 1 Then:rs.Close:End If
  204. If oConn.State = 1 Then:oConn.Close:End If
  205. End Function
  206. Function CreateProofForJurisdiction(KitID)
  207. Dim Qpdf:Set Qpdf = WScript.CreateObject("DebenuPDFLibraryAX1013.PDFLibrary")
  208. Dim Result:Result = Qpdf.UnlockKey("j564z3wi9i66k93cp3r798b3y")
  209. If oConn.State = 0 Then:oConn.Open(ConnectionString):End If
  210. Dim Rs:set Rs = oConn.Execute("SELECT MIN(ID) as [MIN],MAX(ID) as [MAX] FROM InkjetRecords WHERE KitID = " & KitID &";")
  211. Dim MIN:MIN = Rs("MIN").Value
  212. Dim MAX:MAX = Rs("MAX").Value
  213. Dim RecordCount:RecordCount = (MAX - MIN) + 1
  214. Rs.Close
  215. Dim KitRs:set KitRs = oConn.Execute("Select * From [Kit] Where [ID] =" & KitID & ";")
  216. Dim JurisdictionRs:set JurisdictionRs = oConn.Execute("SELECt * FROM [Jurisdiction] WHERE JCode='" & KitRs("Jcode").Value & "';")
  217. Dim ProofFileName:ProofFileName = objFSO.GetBaseName(KitRs("Filename")) & "-PROOF.PDF"
  218. If Not objFSO.FolderExists(ExportDirectory & KitRs("JobNumber").Value & "-" & JurisdictionRs("Name").value) Then:objFSO.CreateFolder(ExportDirectory & KitRs("JobNumber").Value & "-" & JurisdictionRs("Name").value):End If
  219. Dim reportManager:set reportManager = CreateObject("ReportMan.ReportManX")
  220. With reportManager
  221. .Preview = False
  222. .ShowProgress = False
  223. .ShowPrintDialog = False
  224. .filename = PurpleEnvelopeProofReport
  225. .SetDatabaseConnectionString "WEBDATA",ConnectionString
  226. .SetParamValue "PBKITID",KitID
  227. .SetParamValue "PBJCODE",KitRs("Jcode").Value
  228. Dim MAXRECORDS:MAXRECORDS = 3750
  229. If RecordCount > MAXRECORDS Then
  230. Dim i
  231. For i = 0 To RecordCount / MAXRECORDS
  232. Dim newMin:If MIN + (i * MAXRECORDS) > MIN Then:newMin = MIN + (i * MAXRECORDS) + 1:Else newMin = MIN:End If
  233. Dim newMax:If MIN + (i * MAXRECORDS) + MAXRECORDS > MAX Then:newMax = MAX:Else newMax = MIN + (i * MAXRECORDS) + MAXRECORDS:End If
  234. .SetParamValue "PBMIN",newMin
  235. .SetParamValue "PBMAX",newMax
  236. .SaveToPDF ExportDirectory & KitRs("JobNumber").Value & "-" & JurisdictionRs("Name").value & "\Part_" & i & "_" & ProofFileName,1
  237. Result = Qpdf.AddToFileList("Proofs",ExportDirectory & KitRs("JobNumber").Value & "-" & JurisdictionRs("Name").value & "\Part_" & i & "_" & ProofFileName)
  238. Next
  239. Result = Qpdf.MergeFileListFast("Proofs",ExportDirectory & KitRs("JobNumber").Value & "-" & JurisdictionRs("Name").value & "/" & ProofFileName)
  240. Dim test
  241. For test = 1 To Qpdf.FileListCount("Proofs")
  242. WshShell.Run "cmd.exe /c DEL /F /Q """ & Qpdf.FileListItem("Proofs",test) & """" ,0,True
  243. Next
  244. Else
  245. .SetParamValue "PBMIN",MIN
  246. .SetParamValue "PBMAX",MAX
  247. .SaveToPDF ExportDirectory & KitRs("JobNumber").Value & "-" & JurisdictionRs("Name").value & "/" & ProofFileName,1
  248. End If
  249. End With
  250. oConn.Execute("UPDATE KIT SET [Status] ='Ready For Inkjet Export' WHERE [ID] =" & KitID & ";")
  251. If KitRs.State = 1 Then:KitRs.Close:End If
  252. If JurisdictionRs.State = 1 Then:JurisdictionRs.Close:End If
  253. If oConn.State = 1 Then:oConn.Close:End If
  254. End Function
  255. Function CreateExportForSnailWorks(KitID)
  256. Dim State
  257. Dim ForeignTest
  258. If oConn.State = 0 Then:oConn.Open(ConnectionString):End If
  259. Dim KitRs:set KitRs = oConn.Execute("Select * From [Kit] Where [ID] =" & KitID & ";")
  260. If KitRs("OutboundSTID") <> "0" Then
  261. Dim KitLabelsRs: Set KitLabelsRs = oConn.Execute("SELECT InkjetRecords.ID, InkjetRecords.KitID, InkjetRecords.VOTERID, InkjetRecords.LASTNAME," &_
  262. " InkjetRecords.FIRSTNAME, InkjetRecords.MIDDLENAME, InkjetRecords.SUFFIX, InkjetRecords.PRECINCT," &_
  263. " InkjetRecords.ADDRESS1, InkjetRecords.ADDRESS2, InkjetRecords.ADDRESS3, InkjetRecords.ADDRESS4," &_
  264. " InkjetRecords.ADDRESS5, InkjetRecords.APPSENT, InkjetRecords.APPRETURNED, InkjetRecords.BALSENT," &_
  265. " InkjetRecords.BALRETURNED, InkjetRecords.CountingBoard, InkjetRecords.UOCAVASTATUS, InkjetRecords.EMAILADDRESS," &_
  266. " InkjetRecords.PHONENUMBER, InkjetRecords.BALLOT_NUMBER, InkjetRecords.CassADDRESS1, InkjetRecords.CassADDRESS2," &_
  267. " InkjetRecords.CassADDRESS3, InkjetRecords.CassADDRESS4, InkjetRecords.CassADDRESS5, InkjetRecords.KitLabelID," &_
  268. " KitLabels.ID, KitLabels.KitID, KitLabels.OutboundSerial, KitLabels.InBoundSerial, KitLabels.OutboundIMB," &_
  269. " KitLabels.InBoundIMB, KitLabels.OutboundIMBDigits, KitLabels.InBoundIMBDigits, KitLabels.OutboundIMBPNG," &_
  270. " KitLabels.INBOUNDIMBPNG, KitLabels.SetNumber" &_
  271. " FROM InkjetRecords" &_
  272. " LEFT JOIN [KitLabels] ON InkjetRecords.KitLabelID = KitLabels.ID" & _
  273. " WHERE InkjetRecords.KitID =" & KitID & " ;")
  274. Dim JurisdictionRs:Set JurisdictionRs = oConn.Execute("SELECT * FROM Jurisdiction WHERE JCode ='" & KitRs("Jcode").Value & "';")
  275. Dim ExportFileName:ExportFileName = objFSO.GetBaseName(KitRs("Filename")) & "_SW_EXPORT.csv"
  276. If Not objFSO.FolderExists(ExportDirectory & KitRs("JobNumber").Value & "-" & JurisdictionRs("Name").value) Then:objFSO.CreateFolder(ExportDirectory & KitRs("JobNumber").Value & "-" & JurisdictionRs("Name").value):End If
  277. If objFSO.FileExists(ExportDirectory & KitRs("JobNumber").Value & "-" & JurisdictionRs("Name").value & "/" & ExportFileName) Then:objFSO.DeleteFile(ExportDirectory & KitRs("JobNumber").Value & "-" & JurisdictionRs("Name").value & "/" & ExportFileName):End If
  278. Dim objExportFile:set objExportFile = objFSO.CreateTextFile(ExportDirectory & KitRs("JobNumber").Value & "-" & JurisdictionRs("Name").value & "/" & ExportFileName,2)
  279. With objExportFile
  280. .Write("""H"",") 'Record Type Required value must be = "H" (Header)
  281. .Write(Truncate("5.2",5)) 'Version Required value must be ="5.2" for current release
  282. .Write(Truncate("KCIHotFolder2024FTPUser",50)) 'UserId Required
  283. .Write(Truncate(KitRs("Jcode").Value,50)) 'Client Name Required (will create new subaccount if not already defined) - We decideded to make this the juriscode
  284. .Write(Truncate("",50)) 'Parent Client Name Optional (use if 3-tier account structure)
  285. .Write(Truncate("Purple envelope - " & KitRs("JobNumber").Value,50)) 'Job Name Required
  286. .Write(Truncate("",50)) 'Job Description Optional
  287. .Write(Truncate("",50)) 'Split Name Optional � will default to �Default�
  288. .Write(Truncate("",80)) 'Split Description Optional
  289. .Write(Truncate("L",1)) 'Piece Type Required L-Letters, C-Cards, F-Flats
  290. .Write(Truncate(Year(Now()) & "/" &_
  291. Right("0" & Month(Now()), 2) & "/" & Right("0" & Day(Now()), 2),10)) 'MailDate Required (YYYY/MM/DD)
  292. .Write(Truncate("N",1)) 'UploadType Required N = New job, new split A = Append new split to existing job R = Replace existing split
  293. .Write(Truncate("",8)) 'TrackedQuantity Optional
  294. .Write(Truncate("",8)) 'PiecesMailed Optional � shown as Estimated Quantity
  295. .Write(Truncate("",10)) 'Target InHomeDateStart Optional (YYYY/MM/DD)
  296. .Write(Truncate("",10)) 'Target InHomeDateEnd Optional (YYYY/MM/DD)
  297. .Write(Truncate("danielc@kentcommunications.com",100)) 'ConfirmationEmail Optional
  298. .Write(Truncate("",9)) 'JobId (SW) Optional for previously created jobs SWJobId
  299. .Write(Truncate("",4)) 'SplitId (SW) Optional for previously created jobs SWJobId
  300. .Write(Truncate(Choice(IsNull(KitRs("InboundSTID")),"O","R"),1)) 'TypeofTracking Required Values: O- Outbound Only I-Inbound Only R-Round Trip
  301. .Write(Truncate("",11)) 'ReturnedPostalRoutingCode
  302. .Write(Truncate("",2)) 'ReportId1
  303. .Write(Truncate("",255)) 'Report1Email
  304. .Write(Truncate("",2)) 'ReportId2
  305. .Write(Truncate("",255)) 'Report2Email
  306. .Write("""N""") 'INFOONLY
  307. .Write(vbCrLf)
  308. While Not KitLabelsRs.EOF
  309. ForeignTest = KitLabelsRs("CassADDRESS5").Value & " " & KitLabelsRs("CassADDRESS4").Value
  310. State = Truncate(Mid(KitLabelsRs("CassADDRESS5").Value, _
  311. InStr(KitLabelsRs("CassADDRESS5").Value, ",") + 2, 2),2)
  312. State = Replace(State," ","")
  313. If CheckStringDoesNotHaveForiegnCountries(ForeignTest) And State <> """""," then
  314. 'If InStr(ForeignTest,"CANADA") = 0 And InStr(ForeignTest,"AUSTRALIA") = 0 And State <> "" Then " ",
  315. .Write("""D"",") 'RecordType Required value must be = �D� (Detail)
  316. .Write(Truncate("",20)) 'CustomerUniqueIdentifier Optional- any identifier you designate
  317. .Write(Truncate(KitLabelsRs("OutboundIMBDigits"),31)) 'IMB Required � Unencoded, numeric IMB
  318. .Write(Truncate("",10)) 'Greeting Optional
  319. .Write(Truncate("",50)) 'First Name Optional
  320. .Write(Truncate("",2)) 'MI Optional
  321. .Write(Truncate("",50)) 'Last Name Optional
  322. .Write(Truncate("",10)) 'Suffix Optional
  323. .Write(Truncate((KitLabelsRs("CassADDRESS1").Value),100)) 'Full Name Optional
  324. .Write(Truncate("",50)) 'Company Optional
  325. .Write(Truncate("",50)) 'Title Optional
  326. .Write(Truncate(KitLabelsRs("CassADDRESS3").Value,128)) 'Address1 Optional
  327. .Write(Truncate(KitLabelsRs("CassADDRESS4").Value,128)) 'Address2 Optional
  328. .Write(Truncate(Left(KitLabelsRs("CassADDRESS5").Value, _
  329. InStr(KitLabelsRs("CassADDRESS5").Value, ",") - 1),50)) 'City Optional
  330. .Write(State) 'State Optional
  331. .Write Choice(InStr(KitLabelsRs("CassADDRESS5").Value,"-"),Truncate(Right(KitLabelsRs("CassADDRESS5").Value,11),11),Truncate(Right(KitLabelsRs("CassADDRESS5").Value,5),5)) 'Zip Optional
  332. .Write(Truncate(KitRs("Jcode"),100)) 'UserDefined1 Optional - Summary fields only
  333. .Write(Truncate("",100)) 'UserDefined2 Optional - Summary fields only
  334. .Write(Truncate("",100)) 'UserDefined3 Optional - Summary fields only
  335. .Write(Truncate(KitLabelsRs("PRECINCT").Value &_
  336. KitLabelsRs("BALLOT_NUMBER"),80)) 'UserDefinedIdentifier4 Optional � Allows for unique identifiers
  337. .Write(Truncate(KitLabelsRs("VOTERID").Value,80)) 'UserDefinedIdentifier5 Optional � Allows for unique identifiers
  338. .Write(Truncate("",1)) 'SeedIndicator Optional - if true provide �Y�
  339. .Write(Truncate("",80)) 'InductionPoint Optional
  340. .Write(Truncate("",10)) 'InductionDate Optional � Valid date format, ex. MM/DD/YYYY
  341. .Write(Truncate(Choice(IsNull(KitRs("InboundSTID")),"", _
  342. KitLabelsRs("InBoundIMBDigits").Value),31)) 'InboundIMB Optional � numeric IMB for Round trip jobs only
  343. .Write(Truncate("",24)) 'IMCB Optional � Container Barcode
  344. .Write("""""") 'IMTB Optional � Tray Barcode
  345. .Write(vbCrLf)
  346. End If
  347. KitLabelsRs.MoveNext
  348. Wend
  349. .Close
  350. End With
  351. If KitLabelsRs.State = 1 Then:KitLabelsRs.Close: End If
  352. If JurisdictionRs.State = 1 Then:JurisdictionRs.Close:End If
  353. End If
  354. oConn.Execute("UPDATE KIT SET [Status] ='Ready to Proof',[ExportedToSnailWorks] =#" & Now() & "# WHERE [ID] =" & KitID & ";")
  355. If oConn.State = 1 Then:oConn.Close:End If
  356. If KitRs.State = 1 Then:KitRs.Close:End If
  357. End Function
  358. Function createTrackingInfoForKit(KitID)
  359. If oConn.State = 0 Then:oConn.Open(ConnectionString):End If
  360. oConn.Execute("UPDATE Kit SET Status ='Applying Serial Numbers' WHERE ID =" & KitID & ";")
  361. Dim KitRs:set KitRs = oConn.Execute("Select * from Kit Where ID =" & KitID & ";")
  362. If KitRs("OutBoundSTID") = 0 Then
  363. oConn.Execute("UPDATE Kit Set [Status]='Ready For Export', LabelsPrinted=#" & Now() & "# WHERE [ID] =" & KitID &";")
  364. Else
  365. Dim InkjetRs:Set InkjetRs = oConn.Execute("Select * from InkjetRecords Where KitID =" & KitID & ";")
  366. Dim JurisRs:set JurisRs = oConn.Execute("Select Right(IMB_Digits,9) as IMBZip FROM Jurisdiction Where JCode ='" & KitRs("Jcode") & "';"):Dim Jcode:Jcode = JurisRs("IMBZip"):JurisRs.Close
  367. Dim SerialNumberStart:SerialNumberStart = GetSetting("SerialNumberStart")
  368. Dim serialOffset:serialOffset = GetSetting("SerialOffset")
  369. Dim serialStart:serialStart = CLng(GetSetting("SerialNumberStart")) + CLng(GetSetting("SerialOffset"))
  370. Dim Counter:Counter=0
  371. Dim KitLabelID
  372. Dim KitLabelRs
  373. Dim Mid:Mid = GetSetting("MailingID")
  374. Dim Step : If KitRs("InboundSTID") <> "" Then : Step = 2 : Else Step = 1
  375. serialStart = PadLeft(serialStart + CLng(Counter),9,"0")
  376. Dim oRsKitLabels : Set oRsKitLabels = CreateObject("ADODB.Recordset"):oRsKitLabels.Open "Select * FROM [KitLabels] Where KitID =" & KitID & ";",oConn,3,3
  377. While Not InkjetRs.EOF
  378. oRsKitLabels.AddNew
  379. KitLabelID = oRsKitLabels("ID").value
  380. If Step = 1 Then
  381. oRsKitLabels("KitID") = KitID
  382. oRsKitLabels("OutboundSerial") = serialStart
  383. oRsKitLabels("OutboundIMBDigits") = KitRs("OutBoundSTID").Value & Mid & serialStart
  384. Else
  385. oRsKitLabels("KitID") = KitID
  386. oRsKitLabels("OutboundSerial") = serialStart
  387. oRsKitLabels("InBoundSerial") = serialStart + 1
  388. oRsKitLabels("OutboundIMBDigits") = KitRs("OutBoundSTID").Value & Mid & serialStart
  389. oRsKitLabels("InBoundIMBDigits") = KitRs("InboundSTID").Value & Mid & serialStart + 1 & Jcode
  390. End If
  391. oRsKitLabels.Update
  392. oConn.Execute("UPDATE InkjetRecords Set [KitLabelID]=" & KitLabelID & " WHERE ID=" & InkjetRs("ID") & ";")
  393. Counter = Counter + Step
  394. serialStart = serialStart + Step
  395. InkjetRs.MoveNext
  396. Wend
  397. oRsKitLabels.Update
  398. oRsKitLabels.Close
  399. oConn.Execute("UPDATE Settings Set [Value]='" & serialOffset + Counter & "' WHERE [Name] = 'SerialOffset';")
  400. oConn.Execute("UPDATE Kit Set [Status]='Ready For Export', LabelsPrinted=#" & Now() & "# WHERE [ID] =" & KitID &";")
  401. oConn.Close
  402. End If
  403. End Function
  404. Function GetSetting(settingName)
  405. Dim rs:Set rs = oConn.Execute("Select Value From [Settings] Where [Name] = '" & settingName & "';")
  406. If Not rs.EOF Then
  407. GetSetting = rs(0).value
  408. rs.Close
  409. Else
  410. SetSetting = 0
  411. rs.Close
  412. End If
  413. End Function
  414. Function CheckForFiles()
  415. If objFSO.FolderExists(DataDirectory) Then
  416. Dim objFolder:Set objFolder = objFSO.GetFolder(DataDirectory)
  417. If objFolder.Files.Count > 0 Then
  418. 'WScript.Echo "Files found in directory: " & DataDirectory
  419. Dim objFile
  420. For Each objFile In objFolder.Files
  421. Dim CsvString:CsvString = ConvertCsvToString(objFile.Path)
  422. If ValidImportCSV(CsvString) Then
  423. SetupKit CsvString,objFile.Name
  424. objFSO.MoveFile objFile.Path, DataDirectory & "\import\" & objFile.Name
  425. End If
  426. Next
  427. Else
  428. 'WScript.Echo "No files found in directory: " & DataDirectory
  429. End If
  430. End If
  431. End Function
  432. Function ValidJcode(jcode)
  433. Dim oConn
  434. Set oConn = WScript.CreateObject("ADODB.Connection")
  435. oConn.ConnectionString = ConnectionString
  436. oConn.Open
  437. Dim oRs
  438. set oRs = oConn.Execute("Select * from Jurisdiction Where [JCode] = '" & jcode & "';")
  439. If oRs.EOF Then
  440. ValidJcode = 0
  441. Else
  442. ValidJcode = 1
  443. End If
  444. oRs.Close
  445. oConn.Close
  446. End Function
  447. Function CheckStringDoesNotHaveForiegnCountries(StringToCheck)
  448. Dim Countries
  449. Countries = Array("UNITED KINGDOM","NORWAY","AUSTRALIA","FRANCE","UK LL","KENT ENGLAND","CANADA","NETHERLANDS","GERMANY","TAIWAN","NICARAGUA","IREL")
  450. Dim Country
  451. For Each Country In Countries
  452. If InStr(StringToCheck,Country) Then
  453. CheckStringDoesNotHaveForiegnCountries = False
  454. Exit For
  455. End If
  456. CheckStringDoesNotHaveForiegnCountries = True
  457. Next
  458. End Function
  459. Function SetupKit(CsvString,FileName)
  460. Dim JobNumber:JobNumber = Mid(FileName,9,6)
  461. Dim JCode:JCode = Left(Filename,5)
  462. If IsNumeric(JobNumber) Then
  463. If ValidJcode(JCode) Then
  464. WScript.Echo FileName & " Is a Valid CSV for Importing"
  465. Dim oConn:Set oConn = WScript.CreateObject("ADODB.Connection")
  466. oConn.ConnectionString = ConnectionString
  467. oConn.Open
  468. oConn.Execute("Insert Into Kit ([JobNumber], [Jcode], [CreatedOn], [JobType],[Filename],[Status]) VALUES ('" & JobNumber & "','" & JCode & "',#" & Now() & "#,'Purple Envelopes','" & FileName & "','Importing');")
  469. Dim rs : set rs = oConn.Execute("Select TOP 1 ID from Kit ORDER BY ID DESC")
  470. Dim kitId : kitId = rs("ID").value
  471. rs.close
  472. Dim i
  473. For i = 1 To objCSV.NumRows -1
  474. oConn.Execute("Insert Into [InkjetRecords] (KitID,VOTERID,LASTNAME,FIRSTNAME,MIDDLENAME" & _
  475. ",SUFFIX,PRECINCT,ADDRESS1,ADDRESS2,ADDRESS3,ADDRESS4,ADDRESS5,APPSENT,APPRETURNED,BALSENT,BALRETURNED" & _
  476. ",CountingBoard,UOCAVASTATUS,EMAILADDRESS,PHONENUMBER,BALLOT_NUMBER) VALUES (" & kitId & _
  477. ",'" & Replace(objCSV.GetCell(i,0),"'","''") & _
  478. "','" & objCsv.GetCell(i,1) & _
  479. "','" & Replace(objCSV.GetCell(i,2),"'","''") & _
  480. "','" & Replace(objCSV.GetCell(i,3),"'","''") & _
  481. "','" & Replace(objCSV.GetCell(i,4),"'","''") & _
  482. "','" & Replace(objCSV.GetCell(i,5),"'","''") & _
  483. "','" & Replace(objCSV.GetCell(i,6),"'","''") & _
  484. "','" & Replace(objCSV.GetCell(i,7),"'","''") & _
  485. "','" & Replace(objCSV.GetCell(i,8),"'","''") & _
  486. "','" & Replace(objCSV.GetCell(i,9),"'","''") & _
  487. "','" & Replace(objCSV.GetCell(i,10),"'","''") & _
  488. "','" & Replace(objCSV.GetCell(i,11),"'","''") & _
  489. "','" & Replace(objCSV.GetCell(i,12),"'","''") & _
  490. "','" & Replace(objCsv.GetCell(i,13),"'","''") & _
  491. "','" & objCsv.GetCell(i,14) & _
  492. "','" & objCsv.GetCell(i,15) & _
  493. "','" & objCsv.GetCell(i,16) & _
  494. "','" & objCsv.GetCell(i,17) & _
  495. "','" & objCsv.GetCell(i,18) & _
  496. "','" & objCsv.GetCell(i,19) & _
  497. "')")
  498. Next
  499. oConn.Execute("Update Kit SET [Status] = 'Ready to Cass' Where ID = " & kitId &";")
  500. 'oConn.Close
  501. End If
  502. End If
  503. End Function
  504. Function ConvertCsvToString(FilePath)
  505. Dim objFSO:Set objFSO = CreateObject("Scripting.FileSystemObject")
  506. Dim objCsvFile:set objCsvFile = objFSO.OpenTextFile(FilePath)
  507. Dim strContent:strContent = ""
  508. Dim intLineCount:intLineCount = 0
  509. Do Until objCsvFile.AtEndOfStream Or intLineCount >= 3
  510. objCsvFile.SkipLine
  511. intLineCount = intLineCount + 1
  512. Loop
  513. ' Read the remaining content into a string
  514. Do Until objCsvFile.AtEndOfStream
  515. Dim strLine:strLine = objCsvFile.ReadLine
  516. strContent = strContent & strLine & vbCrLf
  517. Loop
  518. ConvertCsvToString = strContent
  519. End Function
  520. Function ValidImportCSV(CsvFileAsString)
  521. objCSV.LoadFromString(CsvFileAsString)
  522. If objCSV.NumColumns = 20 Then
  523. ValidImportCSV = True
  524. Else
  525. ValidImportCSV = False
  526. End If
  527. End Function
  528. Sub ImportCass
  529. Dim currentRow
  530. Select Case dev
  531. Case "local"
  532. objCsv.LoadFile("C:\Share\TrackingDataExport\FROM_MM.CSV")
  533. Case True
  534. objCsv.LoadFile("C:\Share\TrackingDataExport\FROM_MM.CSV")
  535. Case Else
  536. objCsv.LoadFile("\\kci-syn-cl01\PC Transfer\TrackingDataExport\FROM_MM.CSV")
  537. End Select
  538. For currentRow = 0 To objCsv.NumRows -1
  539. oConn.Execute("UPDATE InkJetRecords SET CassADDRESS1 = '" & Replace(objCsv.GetCell(currentRow,1),"'","''") & "', " &_
  540. "CassADDRESS2 = '" & Replace(objCSV.GetCell(currentRow,3),"'","''") & "', " &_
  541. "CassADDRESS3 = '" & Replace(objCSV.GetCell(currentRow,4),"'","''") & "', " &_
  542. "CassADDRESS4 = '" & Replace(objCSV.GetCell(currentRow,5),"'","''") & "', " &_
  543. "CassADDRESS5 = '" & Replace(objCsv.GetCell(currentRow,6) & ", " & objCsv.GetCell(currentRow,7) & " " & objCsv.GetCell(currentRow,8),"'","''") & "'" &_
  544. " WHERE ID = " & objCSV.GetCell(currentRow,0) & ";")
  545. Next
  546. oConn.Execute("UPDATE Kit SET Status ='Ready To Assign STIDS' WHERE ID =" & KitID & ";")
  547. oConn.Execute("UPDATE Kit SET [Cass] = 1 WHERE ID =" & KitID & ";")
  548. End Sub
  549. Sub RunMailManager
  550. Select Case dev
  551. Case "local"
  552. WshShell.Run "PsExec64.exe -i -e -u ntp\danielc -p SunBrightShine! \\MarkH2 ""\\MM2012\APPS\BCC\MM2010\mailman.exe"" -p -j MMJOB-LOCAL.mjb -u DAN",1,True
  553. Case True
  554. WshShell.Run "PsExec64.exe -i -e -u ntp\danielc -p SunBrightShine! \\MarkH2 ""\\MM2012\APPS\BCC\MM2010\mailman.exe"" -p -j MMJOB-DEV.mjb -u DAN",1,True
  555. Case Else
  556. WshShell.Run "PsExec64.exe -i -e -u ntp\danielc -p SunBrightShine! \\MarkH2 ""\\MM2012\APPS\BCC\MM2010\mailman.exe"" -p -j MMJOB.mjb -u DAN",1,True
  557. End Select
  558. End Sub
  559. Sub ExportMMCsv(KitId)
  560. Dim success
  561. objCsv.HasColumnNames = 1
  562. objCSV.EnableQuotes = 1
  563. success = objCsv.SetColumnName(0,"ID")
  564. success = objCsv.SetColumnName(1,"NAME")
  565. success = objCsv.SetColumnName(2,"ADDRESS1")
  566. success = objCsv.SetColumnName(3,"ADDRESS2")
  567. success = objCsv.SetColumnName(4,"ADDRESS3")
  568. success = objCsv.SetColumnName(5,"ADDRESS4")
  569. success = objCsv.SetColumnName(6,"ADDRESS5")
  570. Dim rs : Set rs = oConn.Execute("Select ID," & _
  571. "IIF(FIRSTNAME IS NULL,'',FIRSTNAME & ' ') & " & _
  572. "IIF(MIDDLENAME IS NULL,'',MIDDLENAME & ' ') & " & _
  573. "IIF(LASTNAME IS NULL,'',LASTNAME & ' ') & " & _
  574. "IIF(SUFFIX IS NULL,'',SUFFIX & ' ') " & _
  575. "AS NAME, ADDRESS1,ADDRESS2,ADDRESS3,ADDRESS4,ADDRESS5 FROM InkjetRecords WHERE KitID =" & KitID & " ORDER By ID;")
  576. Dim CurrentRow:CurrentRow = 0
  577. While Not rs.EOF
  578. objCSV.SetCell CurrentRow,0,rs("ID").value
  579. objCSV.SetCell CurrentRow,1,rs("NAME").value
  580. objCSV.SetCell CurrentRow,2,rs("ADDRESS1").value
  581. objCSV.SetCell CurrentRow,3,rs("ADDRESS2").value
  582. objCSV.SetCell CurrentRow,4,rs("ADDRESS3").value
  583. objCSV.SetCell CurrentRow,5,rs("ADDRESS4").value
  584. objCSV.SetCell CurrentRow,6,rs("ADDRESS5").value
  585. rs.MoveNext
  586. CurrentRow = CurrentRow +1
  587. Wend
  588. Dim CsvString:CsvString = objCSV.SaveToString()
  589. outFile.WriteLine CsvString
  590. outFile.Close
  591. End Sub
  592. Function CheckForJobsToCass()
  593. oConn.ConnectionString = ConnectionString
  594. oConn.Open
  595. 'oConn.Open
  596. Dim rs : set rs = oConn.Execute("Select TOP 1 ID from Kit Where Status ='Ready to Cass' ORDER BY ID DESC;")
  597. If Not rs.EOF Then
  598. Dim kitId : kitId = rs("ID").value
  599. rs.Close
  600. CheckForJobsToCass = KitID
  601. oConn.Execute("UPDATE Kit SET Status ='Cassing' WHERE ID =" & KitID & ";")
  602. Else
  603. CheckForJobsToCass = 0
  604. End If
  605. 'oConn.Close
  606. End Function
  607. Public Function PadLeft(originalString,desiredLength,Char)
  608. Dim padLength
  609. padLength = desiredLength - Len(originalString)
  610. If padLength > 0 Then
  611. ' Left pad the string with zeros
  612. PadLeft = String(padLength, Char) & originalString
  613. Else
  614. ' If the original string is already longer or equal to the desired length, no padding is needed
  615. PadLeft = originalString
  616. End If
  617. End Function
  618. Function Truncate(inputString, size)
  619. If Len(inputString) > size Then:Truncate = """" & Left(inputString,size) & """,":Else Truncate = """" & inputString & """,":End If
  620. End Function
  621. Function PadString(inputString, size)
  622. Dim paddedString
  623. Dim inputLength
  624. Dim i
  625. If IsNull(inputString) Then:inputString = ""
  626. ' Get the length of the input string
  627. inputLength = Len(inputString)
  628. ' If the input string is already equal to or longer than the specified size, return it as is
  629. If inputLength >= size Then
  630. PadString = inputString
  631. Exit Function
  632. End If
  633. ' Initialize the padded string with the input string
  634. paddedString = inputString
  635. ' Pad spaces to the right of the input string until it reaches the specified size
  636. For i = 1 To (size - inputLength)
  637. paddedString = paddedString & " "
  638. Next
  639. ' Return the padded string
  640. PadString = paddedString
  641. End Function
  642. Function CleanNull(StringToClean)
  643. If IsNull(StringToClean) Then:CleanNull = "":Else CleanNull = StringToClean:End If
  644. End Function
  645. Public Sub Assign(ByRef var, ByVal val)
  646. If IsObject(val) Then
  647. Set var = val
  648. Else
  649. var = val
  650. End If
  651. End Sub
  652. Public Function Choice(ByVal cond, ByVal if_true, ByVal if_false)
  653. If cond Then
  654. Assign Choice, if_true
  655. Else
  656. Assign Choice, if_false
  657. End If
  658. End Function
  659. Function CompressArray(arr)
  660. Dim temp,i,j
  661. For i = LBound(arr) To UBound(arr) - 1
  662. For j = i + 1 To UBound(arr)
  663. If arr(i) = "" Then
  664. temp = arr(i)
  665. arr(i) = arr(j)
  666. arr(j) = temp
  667. End If
  668. Next
  669. Next
  670. CompressArray = arr
  671. End Function
  672. Function TrimLeadingZeros(inputStr)
  673. Dim i
  674. For i = 1 To Len(inputStr)
  675. If Mid(inputStr, i, 1) <> "0" Then
  676. TrimLeadingZeros = Mid(inputStr, i)
  677. Exit Function
  678. End If
  679. Next
  680. ' If the input string is all zeros, return "0"
  681. TrimLeadingZeros = "0"
  682. End Function

Powered by TurnKey Linux.