Author |
Topic: Numerical Input Into A Textbox (Read 718 times) |
|
RNBW
Full Member
member is offline
Gender:
Posts: 106
|
|
Numerical Input Into A Textbox
« Thread started on: Apr 24th, 2016, 5:27pm » |
|
There has recently been several postings on the LB forum about inputting numerical values in a textbox. A solution was proposed which includes remchar$(txt$,Symbols$), which unfortunately LBB does not appear to recognise.
The code below gets over this for LBB.
The code only makes checks for characters "-", "." and "0-9". It does not carry out any checks in regard to the position of the "-" and "." nor does it check that only one instance of the character is present.
An exercise for someone?
The code: Code:'========================================
' NUMERIC INPUT - NUMBERS ONLY
' by cundo Liberty Basic Conforums
' Re: textbox input - numbers only
' Reply #10 on 23 April 2016 at 6:15pm
'========================================
' Modification to Symbols$ removes "-"
' from the exclusion list. This allows
' negative numbers to be included.
'----------------------------------------
' The function num$(d$)has been included
' for LBB which does not recognise
' remchar$. The function num$(d$) is a
' modification of the routine provide in
' Liberty Basic Conforums by GaRPMorE in
' Reply #6 on: Apr 22nd, 2016, 7:23pm
'========================================
nomainwin
textbox #main.textbox, 10, 50, 100, 25
WindowWidth = 350
WindowHeight = 150
open "Filtered Numeric Input" for window as #main
#main.textbox "!contents? txt$"
#main "trapclose [quit]"
[CheckInput]
timer 0
#main.textbox "!contents? txt$"
Symbols$ = "abcdefghijklmnopqrstuvwxyz";_
"ABCDEFGHIJKLMNOPQRSTUVWXYZ<>,:;!@#$%^&*()_=+`~"
oldtxt$=txt$
'txt$ = remchar$( txt$ , Symbols$)
txt$ = num$(txt$) 'replacement for remchar$()
if oldtxt$<> txt$ then
#main.textbox txt$
handle = hWnd(#main.textbox)
pos = len(txt$)
calldll #user32, "SendMessageA", _
handle as ulong, _
_EM_SETSEL as long, _
pos as long, _
pos as long, _
result as void
end if
timer 300, [CheckInput]
wait
function num$(d$)
for i=1 to len(d$)
a=asc(mid$(d$,i,1))
if a = 45 or a = 46 or a>47 and a<58 then num$=num$+chr$(a)
next
end function
[quit]
close #main
end
|
|
Logged
|
|
|
|
Richard Russell
Administrator
member is offline
Posts: 1348
|
|
Re: Numerical Input Into A Textbox
« Reply #1 on: Apr 24th, 2016, 9:01pm » |
|
on Apr 24th, 2016, 5:27pm, RNBW wrote:A solution was proposed which includes remchar$(txt$,Symbols$), which unfortunately LBB does not appear to recognise. |
|
On the contrary, it does! Had you searched the LBB Help documentation for 'remchar$' you would have found this:
"The new LB 4.5.0 functions are made available through the supplied library file lb45func.bas. This file contains BASIC implementations of the after$(), afterlast$(), endswith(), httpget$(), remchar$(), replstr$(), and upto$() functions. If you want to use any of these functions in your program, copy the lb45func.bas file into the same directory as your BASIC program, and add the following line at the very end of your program (it must start in the first column)":
Code: You can find the same information online here:
http://www.lbbooster.com/lbb.html#lb45
Richard.
|
|
|
|
RNBW
Full Member
member is offline
Gender:
Posts: 106
|
|
Re: Numerical Input Into A Textbox
« Reply #2 on: Apr 24th, 2016, 11:23pm » |
|
Hi Richard
I missed that. It does indeed work. Looking at lb45func.bas, it does show how little the update from the previous version of LB actually achieved when you have reproduced the functions in just over a page of code. How long was the wait for the update?!!!?? In the code I posted, I think the solution there is just as good as remchar$() and is probably clearer as to what is actually being done.
That apart, I think the code is quite useful for numeric entry into a textbox and traps unwanted characters very well and I shall see if I can incorporate into my programs.
Thank you though for bringing lb45func.bas to my notice.
|
|
Logged
|
|
|
|
Richard Russell
Administrator
member is offline
Posts: 1348
|
|
Re: Numerical Input Into A Textbox
« Reply #3 on: Apr 25th, 2016, 08:47am » |
|
on Apr 24th, 2016, 11:23pm, RNBW wrote:Looking at lb45func.bas, it does show how little the update from the previous version of LB actually achieved |
|
Yes, I commented on that at the time. With a large number of bugs that needed fixing (including really serious things like not being able to use a SUB handler with TIMER), and many other requested features, Carl decided instead to invest his time and effort in adding trivial functions that could easily be coded in BASIC.
The other problem with adding new native functions is that it unavoidably introduces a potential incompatibility with existing programs. Any program that happens to have used one of the new function names (in any mixture of upper and lower case) either as an array name, or as the name of a user-defined function, will fail in LB 4.5.0! That's the main reason why I chose to support them in LBB as a supplied library rather than natively.
Then of course I'm bound to draw attention to the fact that one of the things added in LB 4.5.0 which should have been genuinely useful - the INPUTCSV statement - is seriously broken: it fails even with the example CSV file shown in the relevant Wikipedia article! This verges on incompetence in my opinion. LBB's INPUTCSV works with all valid CSV files, including ones which use Unix-style line terminations.
Last but not least, the 'headline' change in 4.5.0 of increasing the available memory from 70 Mbytes to 1 Gbyte has backfired catastrophically because now LB won't run at all on any PC with a mildly fragmented user address space!
Evidently Carl realises that LB 4.5.0 isn't acceptable because, to this day, he has still not released the 'Pro' version. This leaves his 'elite' users, who paid extra for advanced capabilities such as a profiler and program comparator (LBB comes with these as standard by the way), unable to use the new features even if they wanted to.
Still, the LB fraternity won't tolerate any criticism of Carl. As far as they are concerned he is a god and I am the devil.
Richard.
|
|
|
|
Alincon
Full Member
member is offline
Posts: 147
|
|
Re: Numerical Input Into A Textbox
« Reply #4 on: Apr 26th, 2016, 12:46am » |
|
I started with LB 1.4 fifteen years ago. Am I part of the LB fraternity? I think one could say that the 'devil' has done something that 'god' has not: produce an actual version 5!
r.m.
|
|
Logged
|
|
|
|
Mystic
Junior Member
member is offline
Gender:
Posts: 53
|
|
Re: Numerical Input Into A Textbox
« Reply #5 on: May 10th, 2016, 11:53pm » |
|
on Apr 26th, 2016, 12:46am, Alincon wrote:I started with LB 1.4 fifteen years ago. Am I part of the LB fraternity? I think one could say that the 'devil' has done something that 'god' has not: produce an actual version 5!
r.m. |
|
Been around for a long time myself. I give your comment two thumbs up!
|
|
Logged
|
- Rick
|
|
|
|