on 12-19-2015 8:05 AM
Hello everyone
I am trying to write a program with VBScript for transaction ZST1. I want to combine duplicate materials and calculate total quantity of each material, and finally remove extraneous rows. My script works fine until I try to process something like 300 or more rows, and I get 'Type mismatch: CInt' error. Script first sorts the rows by material in descending order, then get fed to this loop:
index = 0
mlast = table.getCellValue(0, "MATERIAL")
total = 0
For row = 0 To table.rowCount - 1
mnext = table.getCellValue(row, "MATERIAL")
qnext = CInt(table.getCellValue(row, "QUANTITY"))
If mlast = mnext Then
total = total + qnext
Else
Call table.ModifyCell(index, "MATERIAL", mlast)
Call table.ModifyCell(index, "QUANTITY", CStr(total))
index = index + 1
mlast = mnext
total = qnext
End If
If mlast = "" Then
table.DeleteRows(CStr(index) + "-" + CStr(table.rowCount - 1))
Exit For
End If
Next
There's only one instance of CInt there so it's easy to see where it fails, but I can't figure out why! Quantity column contains only numeric values, and I'm certain that the problem cannot be integer overflow. It seems that only when there's enough rows to deal with, the script just fails.
Could anyone help me to debug this thing?
Hello.
May you should add your code in Excel VBA.
When it got failed you can check which value cause it.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi
Thank you for response. I got script working by adding
table.CurrentCellRow = row
inside loop.
I think server dont send all data if there is lot of it. This forces it to do so because data needs to be shown. That is my guess only, though.
This is actually my first VBScript. Kind of fun learning it
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.