Numeric entry check in an EditBox control using RegEx [Windows]

Post your FreeBASIC tips and tricks here. Please don’t post your code without including an explanation.
RNBW
Posts: 179
Joined: Apr 11, 2015 11:06
Location: UK

Re: Numeric entry check in an EditBox control using RegEx [Windows]

Postby RNBW » Aug 04, 2018 17:04

UEZ wrote:
RNBW wrote:UEZ
I just wanted to show a different approach (PCRE) for the same "challenge" and that's the reason why I used same GUI and some functions from WinGUI.bi.
I know it is very hard to learn regular expression but it can a mighty tool to have a simpler solution especially with string manipulation.

Counting lines with includes at the top makes not really sense as they are not visible.


My comments were not meant as a criticism. As I said it's good to see alternatives, but I found some of the code a bit difficult to follow. Also, I appreciate that the library I was using was a simplified version, but it's easy to understand and so I coded in that first. When I've got the extended version working properly (Numeric Entry Into A grid Of textboxes), I'll try some of the other libraries. The thing I liked about my code (which was an amalgamation of other people's code) is that it is short and can be used in another program without having too large an overhead.

Thank you again for your code. I've saved it and may come back to it again in the future.
jj2007
Posts: 1111
Joined: Oct 23, 2016 15:28
Location: Roma, Italia
Contact:

Re: Numeric entry check in an EditBox control using RegEx [Windows]

Postby jj2007 » Aug 04, 2018 17:06

UEZ wrote:
jj2007 wrote:Actually, I wanted to post the Exe as Base91 code in the code box, so I tried to make the exe as small as possible using FileOptimizer, but I chose MediaFire. I cannot tell you why there are numerous calls to VirtualQuery and VirtualProtect in the code!
It seems that FileOptimizer uses UPX under the hood. Many AV choke on UPX, but in this case, I had de-upxed the exe, and there was still a flag by Symantec. It could be the Virtual** stuff, which seems a FB feature - if I take away the pcre calls, they are still there.

Usually I'm coding on Win10 x64 and I cannot tell you why Win7 and XP isn't working properly but I will test it in my VMs to reproduce the issues
Your exe works just fine on W7 and XP. My exe didn't - but I found the culprit:

Code: Select all

hGUI = CreateWindowEx(NULL, "#32770", ...

Code: Select all

CreateWindowEx(NULL, wcls.lpszClassName, ...
The latter version works - kind of. I really wonder what FB passes to a WinAPI when you write a "quoted string".

Btw I am not sure if using #32770 is a good idea, I am actually surprised that it works. Your setup is really exotic.

Now the only remaining question is why your exe worked for me, if you built it from the source code that fails for me. FB mysteries.

EDIT: Solved the mystery...

Code: Select all

.lpszClassName  = Strptr("#32770")   ' this is UNICODE
...
CreateWindowEx(NULL, "#32770"    ' this is ANSI
It seems that FB chooses ANSI/UNICODE somewhat arbitrarily; or maybe based on some IDE setting? In any case it's very messy.

My code, while supplying a UNICODE class name to RegisterClassA, managed to create a window because #32770 is a predefined window class (the dialog box, actually). So RegisterClassA succeeded for the class name "#" (the Ansi version of Unicode #32770), and CreateWindowExA succeeded for the dialog box class. And naturally, the .lpfnWndProc = Cast(WNDPROC, @WndProc) was simply ignored, and no messages arrived in that WndProc.
Last edited by jj2007 on Aug 04, 2018 17:20, edited 1 time in total.
UEZ
Posts: 309
Joined: May 05, 2017 19:59
Location: Germany

Re: Numeric entry check in an EditBox control using RegEx [Windows]

Postby UEZ » Aug 04, 2018 17:11

RNBW wrote:
UEZ wrote:
RNBW wrote:UEZ
I just wanted to show a different approach (PCRE) for the same "challenge" and that's the reason why I used same GUI and some functions from WinGUI.bi.
I know it is very hard to learn regular expression but it can a mighty tool to have a simpler solution especially with string manipulation.

Counting lines with includes at the top makes not really sense as they are not visible.


My comments were not meant as a criticism. As I said it's good to see alternatives, but I found some of the code a bit difficult to follow. Also, I appreciate that the library I was using was a simplified version, but it's easy to understand and so I coded in that first. When I've got the extended version working properly (Numeric Entry Into A grid Of textboxes), I'll try some of the other libraries. The thing I liked about my code (which was an amalgamation of other people's code) is that it is short and can be used in another program without having too large an overhead.

Thank you again for your code. I've saved it and may come back to it again in the future.


No, I didn't understand it as a criticism, I just wanted to explain the reason why used regex. Apropos criticism, if the criticism is justified and it is politely communicated, then I am open to criticism at any time because I want to keep evolving.

Thanks for your feedback. :-)
UEZ
Posts: 309
Joined: May 05, 2017 19:59
Location: Germany

Re: Numeric entry check in an EditBox control using RegEx [Windows]

Postby UEZ » Aug 04, 2018 17:17

jj2007 wrote:
UEZ wrote:
jj2007 wrote:Actually, I wanted to post the Exe as Base91 code in the code box, so I tried to make the exe as small as possible using FileOptimizer, but I chose MediaFire. I cannot tell you why there are numerous calls to VirtualQuery and VirtualProtect in the code!
It seems that FileOptimizer uses UPX under the hood. Many AV choke on UPX, but in this case, I had de-upxed the exe, and there was still a flag by Symantec. It could be the Virtual** stuff, which seems a FB feature - if I take away the pcre calls, they are still there.

Usually I'm coding on Win10 x64 and I cannot tell you why Win7 and XP isn't working properly but I will test it in my VMs to reproduce the issues
Your exe works just fine on W7 and XP. My exe didn't - but I found the culprit:

Code: Select all

hGUI = CreateWindowEx(NULL, "#32770", ...

Code: Select all

CreateWindowEx(NULL, wcls.lpszClassName, ...
The latter version works - kind of. I really wonder what FB passes to a WinAPI when you write a "quoted string".

Btw I am not sure if using #32770 is a good idea, I am actually surprised that it works. Your setup is really exotic.

Now the only remaining question is why your exe worked for me, if you built it from the source code that fails for me. FB mysteries.


As I'm a FB rookie the code might look exotic and not fully traceable but I give my best. ^^ I replaced #32770 with wcls.lpszClassName. :-)

I think I fixed the issue with x64 compilation. See #post1. I can compile in both versions properly and it works.
jj2007
Posts: 1111
Joined: Oct 23, 2016 15:28
Location: Roma, Italia
Contact:

Re: Numeric entry check in an EditBox control using RegEx [Windows]

Postby jj2007 » Aug 04, 2018 17:23

UEZ wrote:I replaced #32770 with wcls.lpszClassName. :-)
See my edits above. In any case, #32770 as a class name is a bad idea.
UEZ
Posts: 309
Joined: May 05, 2017 19:59
Location: Germany

Re: Numeric entry check in an EditBox control using RegEx [Windows]

Postby UEZ » Aug 04, 2018 17:59

jj2007 wrote:
UEZ wrote:I replaced #32770 with wcls.lpszClassName. :-)
See my edits above. In any case, #32770 as a class name is a bad idea.


Thx, code updated.

Return to “Tips and Tricks”

Who is online

Users browsing this forum: No registered users and 1 guest