I am having problem with my script, specially the array.
I am reading an excel worksheet (ShipData) and trying to read specific cells into my array if the load number matches user input.
I can get the wscript.echo to populate and the msgbox shows the right data, but when it begins to generate my data file, i have to stop it when it gets too big ( 75 mb plus) and I see that no data from the array made it into the loop as variables.
This is lengthy, but i'm new at this, so lots of screen feedback.
'-----------------------------------------------------------------------------------
'Define Dynamic Array - Works
'-----------------------------------------------------------------------------------
Dim shipmentsArray()
i = 0
nCount = 0
'-----------------------------------------------------------------------------------
'Ask User for Shipment Information Input - Works
'-----------------------------------------------------------------------------------
nShipments = InputBox ( "Count of DC's in Shipment ?", "How many DC's are in this shipment ?", "DC Shipment Count")
MsgBox ( "Count of DC's in Shipment is: " & nShipments )
nLoadNumber = InputBox ( "What is the Shipment Load Number ?", "What is shipment load number ?", "Shipment Load Number")
MsgBox ( "Shipment Load Number is: " & nLoadNumber )
strShipDate = InputBox ( "What is the Shipment Date ?", "Date of Shipment ?", "Ship Date")
MsgBox ( "Shipment Date is: " & strShipDate )
strShipTime = InputBox ( "What is the Time the Shipment left the Dock ?", "Time of Shipment ?", "Ship Time")
MsgBox ( "Shipment Date is: " & strShipTime )
'-----------------------------------------------------------------------------------
'ReDimension Dynamic Array - Works
'-----------------------------------------------------------------------------------
nCount = nShipments
ReDim shipmentsArray((nCount*4)*11)
'ReDim shipmentsArray(nCount*4,11)
For i = 0 To nCount - 1
shipmentsArray(i) = ""
Next
MsgBox "The upper bound of the shipmentsArray() array is " & UBound(shipmentsArray)
'-----------------------------------------------------------------------------------
'Open Excel File and read row information with For Next Loop.
'-----------------------------------------------------------------------------------
Set objExcel = CreateObject("Excel.Application")
Set objWorkbook = objExcel.Workbooks.Open("C:\Users\David Potter\Desktop\Worldwise\Tar_856_11-20-09.xlsm")
objExcel.ActiveWorkbook.Sheets("ShipData").Visible = True
intRow = 29 'What row to start on
Do Until objExcel.Cells(intRow,2).Value = "137646" ' Loop until column 2 is past 2nd order
' change to blank after testing.
If objExcel.Cells(intRow, 12).Value = CLng(nLoadNumber) Then 'User input = nLoadNumber = 409500
'MsgBox ("Row : " & intRow & ": Value is true: " & nLoadNumber)
shipmentsArray(i) = ( objExcel.Cells(intRow, 20).Value & _
objExcel.Cells(intRow, 3).Value & _
objExcel.Cells(intRow, 13).Value & _
objExcel.Cells(intRow, 17).Value & _
objExcel.Cells(intRow, 5).Value & _
objExcel.Cells(intRow, 1).Value & _
objExcel.Cells(intRow, 4).Value & _
objExcel.Cells(intRow, 18).Value & _
objExcel.Cells(intRow, 8).Value & _
objExcel.Cells(intRow, 11).Value & _
objExcel.Cells(intRow, 9).Value )
WScript.Echo ( intRow & vbCrLf & "ControlID#: " & objExcel.Cells(intRow, 20).Value & vbCrLf & _
"Order #: " & objExcel.Cells(intRow, 3).Value & vbCrLf & _
"SCAC #: " & objExcel.Cells(intRow, 13).Value & vbCrLf & _
"Carrier #: " & objExcel.Cells(intRow, 17).Value & vbCrLf & _
"DC Name #: " & objExcel.Cells(intRow, 5).Value & vbCrLf & _
"DC 4-digit #: " & objExcel.Cells(intRow, 1).Value & vbCrLf & _
"PO Number #: " & objExcel.Cells(intRow, 4).Value & vbCrLf & _
"PO Date #: " & objExcel.Cells(intRow, 18).Value & vbCrLf & _
"Carton Qty. #: " & objExcel.Cells(intRow, 8).Value & vbCrLf & _
"DPCI #: " & objExcel.Cells(intRow, 11).Value & vbCrLf & _
"SKU #: " & objExcel.Cells(intRow, 9).Value & vbCrLf )
MsgBox ( intRow & vbCrLf & "ControlID#: " & objExcel.Cells(intRow, 20).Value & vbCrLf & _
"Order #: " & objExcel.Cells(intRow, 3).Value & vbCrLf & _
"SCAC #: " & objExcel.Cells(intRow, 13).Value & vbCrLf & _
"Carrier #: " & objExcel.Cells(intRow, 17).Value & vbCrLf & _
"DC Name #: " & objExcel.Cells(intRow, 5).Value & vbCrLf & _
"DC 4-digit #: " & objExcel.Cells(intRow, 1).Value & vbCrLf & _
"PO Number #: " & objExcel.Cells(intRow, 4).Value & vbCrLf & _
"PO Date #: " & objExcel.Cells(intRow, 18).Value & vbCrLf & _
"Carton Qty. #: " & objExcel.Cells(intRow, 8).Value & vbCrLf & _
"DPCI #: " & objExcel.Cells(intRow, 11).Value & vbCrLf & _
"SKU #: " & objExcel.Cells(intRow, 9).Value & vbCrLf )
intRow = intRow + 1
Else MsgBox ("Row : " & intRow & ": Value is false" )
intRow = intRow + 1
End If
Loop
objExcel.Quit
I am reading an excel worksheet (ShipData) and trying to read specific cells into my array if the load number matches user input.
I can get the wscript.echo to populate and the msgbox shows the right data, but when it begins to generate my data file, i have to stop it when it gets too big ( 75 mb plus) and I see that no data from the array made it into the loop as variables.
This is lengthy, but i'm new at this, so lots of screen feedback.
'-----------------------------------------------------------------------------------
'Define Dynamic Array - Works
'-----------------------------------------------------------------------------------
Dim shipmentsArray()
i = 0
nCount = 0
'-----------------------------------------------------------------------------------
'Ask User for Shipment Information Input - Works
'-----------------------------------------------------------------------------------
nShipments = InputBox ( "Count of DC's in Shipment ?", "How many DC's are in this shipment ?", "DC Shipment Count")
MsgBox ( "Count of DC's in Shipment is: " & nShipments )
nLoadNumber = InputBox ( "What is the Shipment Load Number ?", "What is shipment load number ?", "Shipment Load Number")
MsgBox ( "Shipment Load Number is: " & nLoadNumber )
strShipDate = InputBox ( "What is the Shipment Date ?", "Date of Shipment ?", "Ship Date")
MsgBox ( "Shipment Date is: " & strShipDate )
strShipTime = InputBox ( "What is the Time the Shipment left the Dock ?", "Time of Shipment ?", "Ship Time")
MsgBox ( "Shipment Date is: " & strShipTime )
'-----------------------------------------------------------------------------------
'ReDimension Dynamic Array - Works
'-----------------------------------------------------------------------------------
nCount = nShipments
ReDim shipmentsArray((nCount*4)*11)
'ReDim shipmentsArray(nCount*4,11)
For i = 0 To nCount - 1
shipmentsArray(i) = ""
Next
MsgBox "The upper bound of the shipmentsArray() array is " & UBound(shipmentsArray)
'-----------------------------------------------------------------------------------
'Open Excel File and read row information with For Next Loop.
'-----------------------------------------------------------------------------------
Set objExcel = CreateObject("Excel.Application")
Set objWorkbook = objExcel.Workbooks.Open("C:\Users\David Potter\Desktop\Worldwise\Tar_856_11-20-09.xlsm")
objExcel.ActiveWorkbook.Sheets("ShipData").Visible = True
intRow = 29 'What row to start on
Do Until objExcel.Cells(intRow,2).Value = "137646" ' Loop until column 2 is past 2nd order
' change to blank after testing.
If objExcel.Cells(intRow, 12).Value = CLng(nLoadNumber) Then 'User input = nLoadNumber = 409500
'MsgBox ("Row : " & intRow & ": Value is true: " & nLoadNumber)
shipmentsArray(i) = ( objExcel.Cells(intRow, 20).Value & _
objExcel.Cells(intRow, 3).Value & _
objExcel.Cells(intRow, 13).Value & _
objExcel.Cells(intRow, 17).Value & _
objExcel.Cells(intRow, 5).Value & _
objExcel.Cells(intRow, 1).Value & _
objExcel.Cells(intRow, 4).Value & _
objExcel.Cells(intRow, 18).Value & _
objExcel.Cells(intRow, 8).Value & _
objExcel.Cells(intRow, 11).Value & _
objExcel.Cells(intRow, 9).Value )
WScript.Echo ( intRow & vbCrLf & "ControlID#: " & objExcel.Cells(intRow, 20).Value & vbCrLf & _
"Order #: " & objExcel.Cells(intRow, 3).Value & vbCrLf & _
"SCAC #: " & objExcel.Cells(intRow, 13).Value & vbCrLf & _
"Carrier #: " & objExcel.Cells(intRow, 17).Value & vbCrLf & _
"DC Name #: " & objExcel.Cells(intRow, 5).Value & vbCrLf & _
"DC 4-digit #: " & objExcel.Cells(intRow, 1).Value & vbCrLf & _
"PO Number #: " & objExcel.Cells(intRow, 4).Value & vbCrLf & _
"PO Date #: " & objExcel.Cells(intRow, 18).Value & vbCrLf & _
"Carton Qty. #: " & objExcel.Cells(intRow, 8).Value & vbCrLf & _
"DPCI #: " & objExcel.Cells(intRow, 11).Value & vbCrLf & _
"SKU #: " & objExcel.Cells(intRow, 9).Value & vbCrLf )
MsgBox ( intRow & vbCrLf & "ControlID#: " & objExcel.Cells(intRow, 20).Value & vbCrLf & _
"Order #: " & objExcel.Cells(intRow, 3).Value & vbCrLf & _
"SCAC #: " & objExcel.Cells(intRow, 13).Value & vbCrLf & _
"Carrier #: " & objExcel.Cells(intRow, 17).Value & vbCrLf & _
"DC Name #: " & objExcel.Cells(intRow, 5).Value & vbCrLf & _
"DC 4-digit #: " & objExcel.Cells(intRow, 1).Value & vbCrLf & _
"PO Number #: " & objExcel.Cells(intRow, 4).Value & vbCrLf & _
"PO Date #: " & objExcel.Cells(intRow, 18).Value & vbCrLf & _
"Carton Qty. #: " & objExcel.Cells(intRow, 8).Value & vbCrLf & _
"DPCI #: " & objExcel.Cells(intRow, 11).Value & vbCrLf & _
"SKU #: " & objExcel.Cells(intRow, 9).Value & vbCrLf )
intRow = intRow + 1
Else MsgBox ("Row : " & intRow & ": Value is false" )
intRow = intRow + 1
End If
Loop
objExcel.Quit