Topic Options
#57942 - 04/08/21 06:10 PM need help with my VB script
Sami786 Offline
OL Expert

Registered: 01/29/14
Posts: 393
Loc: Home
Can I get some help on my below code.

my data is as below
I need to multiply NumOfPages by ImageQty to get total at the end of the file.

NumOfPages, ImageQty
1,5
2,3
3,10
1,2
3,25
2,15
...
20,5

output result should look like below
1 = 7
2 = 18
3 = 35
20 = 100

Option explicit

Dim fileName,strImageCounter, strNewCounter,strImageValue,TotalCounter,total1,total2,total3

strImageCounter = Watch.GetVariable("ImageValue")
strImageValue = Watch.GetVariable("CodeName")

if strImageValue = 1 then
strNewCounter = strImageCounter * strImageValue
TotalCounter = TotalCounter + strNewCounter
Watch.SetVariable "Total1", TotalCounter
end if

if strImageValue = 2 then
strNewCounter = strImageCounter * strImageValue
TotalCounter = TotalCounter + strNewCounter
Watch.SetVariable "Total2", TotalCounter
end if

...
...
if strImageValue = 20 then
strNewCounter = strImageCounter * strImageValue
TotalCounter = TotalCounter + strNewCounter
Watch.SetVariable "Total20", TotalCounter
end if

the above code is not incrementing total values, instead it's setting the total back to zero for each record !

your help is appreciated.


Edited by Sami786 (04/08/21 06:10 PM)
_________________________
Peace

Top
#57943 - 04/08/21 09:24 PM Re: need help with my VB script [Re: Sami786]
Jean-Cédric Offline
OL Expert

Registered: 10/03/16
Posts: 650
Loc: Québec, Canada
Try by giving a default value of 0 to your variable TotalCounter

And looking at your code, I fail to see how 1,5 will produce 1 = 7


Edited by Jean-Cédric (04/08/21 09:24 PM)
_________________________
♪♫♪♫
99 frigging bugs in my code
99 frigging bugs
Take one down
Code around
127 frigging bugs in my code
♪♫♪♫

Top
#57945 - 04/09/21 10:47 AM Re: need help with my VB script [Re: Sami786]
Sami786 Offline
OL Expert

Registered: 01/29/14
Posts: 393
Loc: Home
The default value for "Total1", "Total2" are set to zero but I don`t know how to set Dim TotalCounter variable to 0?

line 1 is
1,5

line 4 is
1,2

Type "1" the the sume of 5+2 = 7 that's how I should get 7

I need to find the total sum of each type, I have 20 type in total.
_________________________
Peace

Top
#57946 - 04/09/21 01:28 PM Re: need help with my VB script [Re: Sami786]
Sami786 Offline
OL Expert

Registered: 01/29/14
Posts: 393
Loc: Home
again, my calculation works fine but I do't know why the local Total variables (Total1, Total2...Total20) are set back to zero for each record?

What I need is to be able to keep adding to the Total values for each type "NumOfPages" until end of the file.

Thanks
_________________________
Peace

Top
#57947 - 04/09/21 03:10 PM Re: need help with my VB script [Re: Sami786]
Sami786 Offline
OL Expert

Registered: 01/29/14
Posts: 393
Loc: Home
this is my workflow steps

1 - folder capture
2 - Data Emulation Split (1) each record
3 - Set variable total to Dim variables
4 - run scrip to get the sum of each Total values
_________________________
Peace

Top
#57948 - 04/09/21 04:11 PM Re: need help with my VB script [Re: Sami786]
Jean-Cédric Offline
OL Expert

Registered: 10/03/16
Posts: 650
Loc: Québec, Canada
You need to store the value of TotalCounter into a variable of the process in between iteration of your loop (splitter). Any variable define inside the script is flushed once the script has finished


Edited by Jean-Cédric (04/09/21 04:11 PM)
_________________________
♪♫♪♫
99 frigging bugs in my code
99 frigging bugs
Take one down
Code around
127 frigging bugs in my code
♪♫♪♫

Top
#57949 - 04/09/21 06:14 PM Re: need help with my VB script [Re: Sami786]
Sami786 Offline
OL Expert

Registered: 01/29/14
Posts: 393
Loc: Home
below code is also not working ,can you please send me an example:

if strImageValue = 1 then
strNewCounter = strImageCounter * strImageValue
TotalCounter = TotalCounter + strNewCounter
end if
Watch.SetVariable "Total1", TotalCounter
_________________________
Peace

Top
#57950 - 04/12/21 01:53 PM Re: need help with my VB script [Re: Sami786]
Sami786 Offline
OL Expert

Registered: 01/29/14
Posts: 393
Loc: Home
resolved thanks.
_________________________
Peace

Top
#57951 - 04/12/21 01:58 PM Re: need help with my VB script [Re: Sami786]
Jean-Cédric Offline
OL Expert

Registered: 10/03/16
Posts: 650
Loc: Québec, Canada
Can you post how you resolved it so it can be a source for other users?
_________________________
♪♫♪♫
99 frigging bugs in my code
99 frigging bugs
Take one down
Code around
127 frigging bugs in my code
♪♫♪♫

Top
#57952 - 04/12/21 03:44 PM Re: need help with my VB script [Re: Sami786]
Sami786 Offline
OL Expert

Registered: 01/29/14
Posts: 393
Loc: Home
I followed your direction with many thanks!
So below VB script is working, but this could be rewritten very sweet and short! but it works smile

'after folder capture
'Branch starts with Data emulation on each record
'then below script

strImageValue = Watch.GetVariable("CodeName")
if strImageValue = 1 then
strCurrentCounter = Watch.GetVariable("Total1")
strNewCounter = strCurrentCounter + 1
Watch.SetVariable "Total1", strNewCounter
elseif (strImageValue = 2 ) then
strCurrentCounter = Watch.GetVariable("Total2")
strNewCounter = strCurrentCounter + 1
Watch.SetVariable "Total2", strNewCounter
....
....
....
end if


'on EOF branch exited
'next is new scrip to calculate total values
'by now I found total count for each type
'Then I multiplied the total count by value 5 to find the 'total number of images for the job

strImageValue = Watch.GetVariable("CodeName") 'in this case it's "5"

Sum1 = Watch.GetVariable("Total1")
Sum2= Watch.GetVariable("Total2")
...
...
Sum20= Watch.GetVariable("Total20")


'find total sum of all
strTotalSum = cstr(cint(Sum1) + cint(Sum2) + cint(Sum20))
'multiply total by 5

Totalmultiply = strTotalSum * 5

'save the value in a local variable
Watch.SetVariable "TotalSumMultiply", Totalmultiply

this works for me but again I'm sure you might be able to rewrite or use a loop or in a much better script!

Thanks
_________________________
Peace

Top