Author Topic: Exceeding astatusbar limits using Huge Math  (Read 79 times)

jmburton2001

  • Newbie
  • *
  • Posts: 30
Exceeding astatusbar limits using Huge Math
« on: February 22, 2019, 02:26:12 pm »
I've been pondering this for a few years ever since I exceeded astatusbar's limit of 65,535. It's never been a deal breaker, just an annoyance because I'd never know when processing was going to finish. I'd most likely use the total lines of a text file to populate "TotalItems".

Anyway, I've always figured that it's simple math, I just needed to figure it out. This is what I came up with. I've tested "TotalItems" with values from 10 to 250,000 and it appears to work properly.

Code: Winbatch
AddExtender("wwsop34i.dll")
AddExtender('WWHUG44I.DLL')

TotalItems = "85000"
MaxItems = "65535" ; This can actually be any number less that 65535 because it will maintain the "Result =" ratio
Result = huge_Divide(MaxItems,TotalItems)

Icount = Abs(huge_Multiply (TotalItems, Result))
Count = "0"

astatusbar(0,"Item Analysis","Reading Items",MaxItems,0)

For item = 1 To Icount
  line = "Whatever you want to analyze"
  Count = Count + 1
  item = Abs(huge_Multiply (Count, Result))
  ItemPct = Count * 100 / TotalItems
  PctMsg = StrCat ("Analysis is ",ItemPct,"%% complete...",@CRLF,"Reading item %Count% of %TotalItems%")
  astatusbar(1,"Item Analysis",PctMsg,MaxItems,item)
  ; Perform some work...
Next

astatusbar(2,"Item Analysis","Done",MaxItems,item)
LastMessage = StrCat ("Total items processed = ",Count,@CRLF, "Last line = ",line)
Message ("Done",LastMessage)

Exit
 

I'm really placing this here for my own future reference since I'll probably forget where I put it in a few years or so... Thank you in advance for letting me store this here!

td

  • Tech Support
  • *****
  • Posts: 2770
    • WinBatch
Re: Exceeding astatusbar limits using Huge Math
« Reply #1 on: February 22, 2019, 03:00:43 pm »
Taking the absolute value of an integer with a value greater than that of the maximum 32-bit integer using the Abs function is a little like using a pseudo-random number generator.
"No one who sees a peregrine falcon fly can ever forget the beauty and thrill of that flight."
  - Dr. Tom Cade

jmburton2001

  • Newbie
  • *
  • Posts: 30
Re: Exceeding astatusbar limits using Huge Math
« Reply #2 on: February 22, 2019, 03:33:28 pm »
This reminds me of an incident that happened to me about 35 years ago (or so)...

I was working for a guy that owned a greenhouse and he set me to work on the boiler pipes. He showed me where he wanted the internal greenhouse pipes to mate up (via a union) with the external boiler pipes. These weren't small pipes... they were 4" galvanized steel that had to be cut to size and threaded.

I'd been struggling and wrangling these things for two days and was just getting ready to put the unions together, finish up, and fill the system with water to check for leaks. I saw my boss and another guy standing at the far end of the greenhouse talking. I knew the guy he was talking to because he was a well known plumber in the county and had been in business for well over 30 years. I waved at him and he smiled and waved back.

I finished the plumbing, charged the system and everything worked like a charm. No leaks even at full pressure!

Later that evening at quitting time my boss said "Thank you!"

I said, "What for?"

He said, "You won me $50 today."

I said "How's that?"

He said, "Remember earlier today when John and I were over there talking?"

I said, "Yeah... So?"

He said, "John looked at me and said that you'd NEVER get that to work. I told him I'd bet him $50 that you could and he took the bet."

I said, "How'd you know I could get it done, because even I had doubts?"

He said, "I've known you for a few years and I've watched you work. I knew you were too dumb to know that it wouldn't work and that you'd kill yourself to make it work!"

Moral of the story... I've always been too dumb to know that things don't work.

jmburton2001

  • Newbie
  • *
  • Posts: 30
Re: Exceeding astatusbar limits using Huge Math
« Reply #3 on: February 23, 2019, 06:18:01 am »
Taking the absolute value of an integer with a value greater than that of the maximum 32-bit integer using the Abs function is a little like using a pseudo-random number generator.

I understood some of these words and I agree... It nagged at me that using the absolute value toward the end of the script might make it equal "Icount" before it actually made it to the last line and then prematurely exit the loop.

I changed the formula as follows and it appears to have no detrimental effects. I mistakenly thought that the initial calculation would produce a number less than "one" (because "Result" was less than one) and cause the loop to fail.

Code: Winbatch
For item = 1 To linecount

  line = FileRead(File)
  Count = Count + 1
  item = Count * Result
;  item = Abs(huge_Multiply (Count, Result))
  astatusbar(1,"Item Analysis","Reading item %Count% of %LogLines01%",MaxLines,item)

  ; Perform work
 
Next

On the initial pass through the loop in this scenario, "item" evaluates to 0.820008 (which is less than one), but it didn't fail?

The more I learn, the dumber I feel...