Request a code - Forum

Forum Navigation
You need to log in to create posts and topics.

Request a code

(For visual neo win)

Hello my friends

I want to count of products in the first X days of each month !

For example, in January I want to count  to first 10 days and in February I want to count its number up to first 22 days !! (The number of days varies)

but :

I want to count the product numbers from X day to Y day (Within two specified days)

For example, from February 1 to February 20, I want to count the number of products !

Uploaded files:

  • You need to login to have access to uploads.

@yasin

I am confused about the purpose/intent of the LoadVariables/SaveVariables commands associated with the click event of the Load and Save buttons.

SaveVariables will save the names and values of every variable deployed by your application at the time this command is invoked ... and the LoadVariables command will restore/replace the values of all saved these variables.

 

I can not figure out how the product related information is desired to be structured i.e. ...

1) is the [count] of the product for a particular day the only value to be saved to a file ? e.g. ...

[PubDir]20-04-05.txt will contain one line with value of (say) 14
[PubDir]20-04-06.txt will contain one line with value of (say) 23
[PubDir]20-04-07.txt will contain one line with value of (say) 55
etc. etc.

or

2) will there be more than one product, requiring the product name/number to also be stored e.g. ...

[PubDir]20-04-05.txt will contain one line with value of (say) ABC,14
[PubDir]20-04-06.txt will contain one line with value of (say) YY3,23
[PubDir]20-04-07.txt will contain one line with value of (say) 897,55
etc. etc.

... and if so ...

a) will the counts of all products for a single day be stored in a single file ? (one line per product)

or

b) will the file name incorporate the product name/number (in addition to the date)

Also, please advise how many products and days the Application is anticipated to manage ? ... simple text files can handle low/medium number of lines, but if the number of lines becomes huge (thousands), a database approach should be considered.

 

hi @gaev

yes . This is my goal

Quote from Gaev on August 24, 2020, 11:34 pm

1) is the [count] of the product for a particular day the only value to be saved to a file ? e.g. ...

[PubDir]20-04-05.txt will contain one line with value of (say) 14
[PubDir]20-04-06.txt will contain one line with value of (say) 23
[PubDir]20-04-07.txt will contain one line with value of (say) 55
etc. etc.

@yasin

I will prepare some script tonight.

However, is it important to have one separate file for each day of the year ? ... with just one number per file ... or would it be better if there was just one file e.g. [PubDir]counts.txt ... and contain one line per day like this ...

2004-04-05,14
2004-05-05,23
2004-06-05,55

 

@gaev

It does not matter how it is

I just want to save the number of products every day and collect it at the end of the month .

 

@yasin

I have attached the pub with the initial functionality i.e. selection/verification of year, month day and count ... and saving the count to the associated file.

1) Please check out this part of the Application to make sure this is the exact behavior you wanted (note that you can check the contents of the file using notepad.exe or similar text editor).

2) Once verified by you, please return the pub file with the Interface for how you want the User to specify the start/end dates for which the sum of counts is to be displayed.

I will then develop the functionality for ...

- loading the count stored for a specified date
- displaying the sum of counts for a specified date range

Uploaded files:
  • You need to login to have access to uploads.

Thank you for your efforts dear @gaev

But that file was far from expected

I need a button to calculate the number of daily products for each month .

(I do not know how to convey the meaning)

 

For example, I have 10 products in 2020-10-15

and I have 15 products in 2020-10-16

and I have 5 products in 2020-10-20

Then I select the month 10 (October) to see the total of all products, That means 30 products in october (10+15+5 = 30)

@yasin

But that file was far from expected

I am not sure what you mean by this ... did the Save Button do what you expected ?

Note that what I supplied is just the first part i.e. a way to have counts for a specified date saved to a file.

I need a button to calculate the number of daily products for each month .
(I do not know how to convey the meaning)
For example, I have 10 products in 2020-10-15
and I have 15 products in 2020-10-16
and I have 5 products in 2020-10-20
Then I select the month 10 (October) to see the total of all products, That means 30 products in october (10+15+5 = 30)

I understand this.

However, you had earlier indicated that you also wanted the granularity of being able to get a total for a date range (e.g. 2020-10-03 to 20202-10-15) ... please clarify whether it is only by the month or within a specified date range.

The reason I want you to setup the interface (selection boxes and buttons) for the next part is because I want to see how you would like to present (to your user) the mechanism for specifying the range (yy-mm or yy-mm1-dd1 to yy2-mm2-dd2) for which the totals are to be calculated. I will then add the script commands to achieve those objectives.

I await a revised copy of the pub with the additional boxes/buttons.

Vadim has reacted to this post.
Vadim

please clarify whether it is only by the month or within a specified date range.

Both modes !!

did the Save Button do what you expected ?

It does not matter to me . I want to see the end result (Total number of products per month or in a range of months)

@gaev

@yasin

It does not matter to me .

It should; because the Save step is needed to generate the files/counts for a specified date ... which will later be used to read/calculate the total count for a specified date range.

Note: I have also completed the code for the Load button; which will let you read a previously saved value

I want to see the end result (Total number of products per month or in a range of months)

In the new attached pub file, I have done the interface and button code for the case where a year and month are specified.

1) Verify that the counts are as expected

2) Review all the script commands and let me know if you can do the other case (from/to date) or you need further assistance.

Uploaded files:
  • You need to login to have access to uploads.

You are doing great :)

 

 

I need explain these parts to me (The function of each command) :

... get list of matching files
FileList "[fileMask]" "Files" "[matchingFiles]"
If "[matchingFiles]" "=" ""
   AlertBox "Sorry" "!no matching files for [countyy]-[countmm]"
   Return
Else
   ... setup array of matching file names
   StrParse "[matchingFiles]" "[#13]" "[matchingFile]" "[matchingFilesCount]"
   AlertBox "matching files" "[matchingFilesCount][#13][matchingFiles]"
   ... init total count
   SetVar "[yymmcount]" "0"
   ... now read each file in list and add counts
   Loop "1" "[matchingFilesCount]" "[thisLoop]"
      SetVar "[thisMatchingFile]" "[matchingFile[thisLoop]]"
      FileRead "[thisMatchingFile]" "1" "[thisCount]"
      Math "[yymmcount]+[thisCount]" "0" "[yymmcount]"
   EndLoop
   ... show total count
   AlertBox "total count" "!for [countyy]-[countmm] is [yymmcount]"
EndIf

 

@yasin

Let us say that you have the following files (counts in brackets)

[PubDir]2020-05-13.txt (5)
[PubDir]2020-05-14.txt (16)
[PubDir]2020-08-03.txt (8)

... setup file mask
SetVar "[fileMask]" "![PubDir][countyy]-[countmm]*.txt"
... get list of matching files
FileList "[fileMask]" "Files" "[matchingFiles]"

If [countyy] was 2020 and [countmm] was 05 ...

The [fileMask] would be [PubDir]2020-05*.txt ... that means all files starting with [PubDir]2020-05 and having an extension of .txt

So, [matchingFiles] would contain the two files from May/2020 (separated by a carriage return ([#13]).

See https://winhelp.visualneo.com/Files1.html for the Help info or FileList

If "[matchingFiles]" "=" ""
AlertBox "Sorry" "!no matching files for [countyy]-[countmm]"
Return

If you had chosen (say) June/2020, [matchingFiles] would be null/empty (no matching files)

StrParse "[matchingFiles]" "[#13]" "[matchingFile]" "[matchingFilesCount]"

This turns the string of file names (separated by [#13]) into an array with item variables [matchingFile1], [matchingFile2] etc.

SetVar "[yymmcount]" "0"

This sets up the total count to zero

... now read each file in list and add counts
Loop "1" "[matchingFilesCount]" "[thisLoop]"
   SetVar "[thisMatchingFile]" "[matchingFile[thisLoop]]"
   FileRead "[thisMatchingFile]" "1" "[thisCount]"
   Math "[yymmcount]+[thisCount]" "0" "[yymmcount]"
EndLoop

This loops through the item variables, and for each corresponding file ...

- reads the first line for the count for that day
- adds this count to the total count

AlertBox "total count" "!for [countyy]-[countmm] is [yymmcount]"

This displays the total count.

 

Vadim and proforma.guyot have reacted to this post.
Vadimproforma.guyot

@gaev thanks very much !

Your description was complete .

How to determine the number of products in two dates (from/to date)  ??

Did you do anything about it?

 

 

@yasin

How to determine the number of products in two dates (from/to date) ??

In order to determine the number of products within two dates of the same month (e.g. 2020-03-09 to 2020-03-23), this can be accomplished easily with just a few additional lines of code within the Loop/EndLoop code block.

However, in order to determine number of products across months (e.g. 2019-09-29 to 2020-06-15), it gets to be a bit more complicated ... since a mask can not be applied to filter the required files, names of all files needs to be examined in order to determine if it falls within the specified date range; if this list of files becomes large over time,  servicing the Loop/EndLoop commands on the entire list of files may slow down the process considerably.

It is possible to achieve this by filtering one month at a time, but the logic/code for it becomes very complicated.

Please tell ...

a) whether you need to determine number of products across months
b) if so, how many files (of the type [PubDir][yyyy]-[mm]-[dd]) do you anticipate to have over time e.g. after a year of use, and assuming one file per day, are you going to have 365 (or even 52 * 5 = 260) files on disk ?

 

Vadim has reacted to this post.
Vadim

However, I use the same code
I change it for several intervals in a month
I hope the result will be achieved

...

dear  @gaev ! I really thank you

be safe and happy

 

 

@Yasin

I have attached a new version that allows you to specify a day range (with the same year/month).

Uploaded files:
  • You need to login to have access to uploads.
Vadim and proforma.guyot have reacted to this post.
Vadimproforma.guyot