Michael - can I have a listing of SendVoltsToUser ? I've been looking for something like that for years.
Hehehe....
------------------
Announcement
Collapse
No announcement yet.
Elininating Punctuation Marks
Collapse
X
-
This is a trivial problem if you process the information provided
after the input, but requires your own custom routine to handle
input if you want to block certain characters from being entered
from the keyboard,
Let's focus on the trivial way. Say your input is in aa$, and
you only want to allow numeric data. Just do aa$=RETAIN$(aa$,
ANY "0123456789"), and all you have left is the digits. If you
want to allow a dollar sign and decimal place, just add them to
what you will accept: aa$=RETAIN%(aa$,ANY "$.0123456789").
We can determine that capital "A" corresponds to a decimal 65, and
that a capital "Z" corresponds to a decimal 90. At the same time,
a zero ("0") has a code value of 48, and a "9" has the code value
of 57. The small "a" and "z" have the code values of 97 and 123
respectively. We can use this information with a CHR$()
function to create our own custom mask that will only accept and
use upper case letters and digits like this:
Code:REPLACE ANY CHR$(97 TO 123) WITH CHR$(65 TO 90) IN AA$ aa$=RETAIN$(aa$, ANY CHR$(65 TO 90,48 TO 57))
replacing unwanted characters with something innocous like
spaces might be better. This is a great job for REPLACE.
Code:ff$=CHR$(0 TO 255) 'cover every ASCII code ff$=REMOVE$(ff$, ANY CHR$(65 TO 90, 48 TO 57)) 'remove valid chars REPLACE ANT ff$ WITH SPACE$(LEN(ff$)) IN aa$ 'replace the rest with spaces
commands provided with PowerBasic.
Oops! I forgot which board I was writing to at the time. PB/DOS
lacks some of the string commands found in PB/CC and PB/Win. So I
guess this post merely reveals some of the rewards you get when you
decide to move up to a later compiler.
------------------
Old Navy Chief, Systems Engineer, Systems Analyst, now semi-retired
[This message has been edited by Donald Darden (edited March 21, 2007).]
Leave a comment:
-
Mis-posted, removed and re-posted to correct forum
[This message has been edited by Richard Angell (edited March 20, 2007).]
Leave a comment:
-
Hi Keith,
You'll need to put in a line or two of mods in fInput to exclude all
characters out of your range but that shouln't be a big deal.
C'ya,
Don
[email protected]
Code:'------------------------------------------------------------------------ ' fInput% function for FirstBASIC ' coded by: Don Schullian [email protected] ' public domain ' ' Welcome, ' ' This code is offered as an (better?) alternative to INPUT$. It ' allows for cursoring around a field, deletion, insertion, overwrite, ' scrolling, and bail out without saving the/any changes. ' ' Its use is demonstrated below using an array to allow for editing ' a screen full of data in one loop. This code could, very easily be ' placed into it's own function and called several times in a single ' program. ' ' There are a series of CONSTANTS set that are used by the function ' You may, of course, put their values into the function or, in some ' cases, send the values to the function to allow for more control by ' varied other functions. ' ' This offering is just a starting point for those of you who are ' more adventurous. Over the years I've developed 10 different ' variations of this function that control and guide the users' input. ' One of them works only for numerical input and looks & feels like ' a calculator; another allows input of only specific characters; ' while others handle hexadecimal input, masked fields, multiple lines ' and other varied field types. A bit of imagination goes a LONG way! ' ' fGetKey% is my basic keyboard input function and I never leave ' home without it. There is a full discussion on how and why on ' either of my web pages. [url="http://www.basicguru.com/scullian"]www.basicguru.com/scullian[/url] or ' [url="http://www.DASoftVSS.com"]www.DASoftVSS.com[/url] along with some other goodies. ' ' If you have any questions, give me a shout. ' ' Don '---------------------------------------------------------------------- ' fGetKey%(Datum$,Row%,Col%,VisCols%,MaxLen%,ExitKeys$) ' ' PURPOSE: Allow user input in an editable, friendly environment ' PARAMS: Datum$ incoming the data already found in the field ' returning the edited data ' Row%, Col% the left most screen position of the field ' VisCols% the number of visable characters on screen ' MaxLen% the maximum number of characters in the field ' ExitKeys$ the MKI$(keyvalue%) of all the keys OTHER THAN ' <ESC> and <ENTER> that will return from the ' function ' NOTE: If VisCols% =< MaxLen% then the value will be set to match ' that of MaxLen% '-------------------------------------------------------------------------- %EscKey = &h001B ' key codes returned by fGetKey% %EnterKey = &h000D %BkSpcKey = &h0008 %DelKey = &h5300 %UpKey = &h4800 %DownKey = &h5000 %InsKey = &h5200 %LeftKey = &h4B00 %RightKey = &h4D00 %CtrlDel = &h9300 %F10key = &h4400 %HomeKey = &h4700 %EndKey = &h4F00 %Fgrnd = 15 ' editing foreground %Bgrnd = 1 ' editing background '--------------------------------------------------------------- '-------------------- start of test code '--------------------------------------------------------------- COLOR 0, 7 CLS ' ================================================ ' ======= this demonstrates the use for one field ' ================================================ D$ = "Mary had a little lamb, its fleece was white as snow." G% = fInput%(D$, 2, 10, 20, 70, "") LOCATE 2, 1: PRINT D$; ' ================================================== ' ====== the following uses an array for 5 fields ' ================================================== DIM D$(5) DIM F%(2,5) RESTORE TestData FOR X% = 1 TO 5 READ Prompt$ READ D$(X%), F%(0,X%), F%(1,X%), F%(2,X%) Col% = F%(1,X%) - LEN(Prompt$) - 1 COLOR 8, 7 LOCATE F%(0,X%), Col% PRINT Prompt$; COLOR 1, 7 LOCATE F%(0,X%), F%(1,X%) PRINT LEFT$(D$(X%), F%(2,X%)) NEXT LOCATE 25, 1 PRINT "Use Arrows to move - F-10 to save & exit - <ESC> to quit"; ExitKeys$ = MKI$(%F10key) + MKI$(%UpKey) + MKI$(%DownKey) Fld% = 1 DO IF Fld% < 1 THEN Fld% = 5 ELSEIF Fld% > 5 THEN Fld% = 1 END IF G% = fInput%( D$(Fld%), F%(0,Fld%), F%(1,Fld%), 0, F%(2,Fld%), ExitKeys$) SELECT CASE G% CASE %F10key : EXIT LOOP CASE %EscKey : EXIT LOOP CASE %UpKey : DECR Fld% CASE ELSE : INCR Fld% END SELECT LOOP FOR X% = 1 TO 5 LOCATE X% + 10, 1 PRINT D$(X%) NEXT TestData: DATA "Last Name:", "Schullian" , 6, 20, 17 DATA "Frst Name:", "Don" , 7, 20, 17 DATA "Street:" , "My Street 27", 8, 20, 30 DATA "City:" , "Hometown" , 9, 20, 30 DATA "Zip:" , "12345-2433" , 9, 56, 10 FUNCTION fGetKey% LOCAL G$ LOCAL L% DO G$ = INKEY$ L% = LEN(G$) LOOP UNTIL L% > 0 IF L% = 1 THEN fGetKey% = ASC(G$) ELSE fGetKey% = CVI(G$) END IF END FUNCTION ' '------------------------------------------------------------------- ' FUNCTION fInput% ( Datum$, Row%, Col%, VisLen%, MaxLen%, ExitKeys$ ) LOCAL Bgrnd% ' original background color LOCAL Cpos% ' current cursor position within string LOCAL E% ' temp variable LOCAL Exet$ ' string vals of all exit keys LOCAL Fgrnd% ' original foreground color LOCAL Inzert% ' insert state LOCAL KeyVal% ' incoming key-press value LOCAL MaxOff% ' maximum offset position LOCAL Offset% ' 1st character shown in field LOCAL Temp$$ ' working data string MAP Temp$$ * MaxLen% Temp$$ = LTRIM$(Datum$) Inzert% = 31 Exet$ = MKI$(%EscKey) + MKI$(%EnterKey) + ExitKeys$ Bgrnd% = SCREEN(Row%, Col%, 1) Fgrnd% = (Bgrnd% AND 15) Bgrnd% = (Bgrnd% \ 16) Offset% = 1 IF (VisLen% = 0) OR (VisLen% > MaxLen%) THEN VisLen% = MaxLen% MaxOff% = (MaxLen% - VisLen% + 1) GOSUB fInputEOL COLOR %Fgrnd, %Bgrnd LOCATE , , , Inzert%, 31 DO IF Cpos% < 1 THEN Cpos% = 1 ELSEIF Cpos% > MaxLen% THEN Cpos% = MaxLen% END IF IF Cpos% < Offset% THEN Offset% = Cpos% ELSEIF (Cpos% - Offset% + 2) > VisLen% THEN Offset% = (Cpos% - VisLen% + 1) IF Offset% > MaxOff% THEN Offset% = MaxOff% END IF GOSUB fInputPrint LOCATE Row%, (Col% + Cpos% - Offset%), 1 KeyVal% = fGetKey% E% = INSTR(Exet$, MKI$(KeyVal%)) IF (E% AND 1) = 1 THEN EXIT LOOP SELECT CASE KeyVal% CASE 32 TO 255 : IF (Inzert% = 0) OR (Cpos% = MaxLen%) THEN MID$(Temp$$, Cpos%, 1) = CHR$(KeyVal%) ELSE Temp$$ = LEFT$(Temp$$, Cpos% - 1) + _ CHR$(KeyVal%) + _ MID$(Temp$$, Cpos%) END IF INCR Cpos% CASE %BkSpcKey : IF Cpos% > 1 THEN DECR Cpos% GOSUB fInputStrip END IF CASE %DelKey : GOSUB fInputStrip CASE %HomeKey : Cpos% = 1 CASE %EndKey : GOSUB fInputEOL CASE %LeftKey : DECR Cpos% CASE %RightKey : INCR Cpos% CASE %InsKey : Inzert% = ( Inzert% XOR 31 ) LOCATE , , , Inzert%, 31 END SELECT LOOP Offset% = 1 IF KeyVal% <> %EscKey THEN Temp$$ = LTRIM$(Temp$$) Datum$ = RTRIM$(Temp$$) ELSE Temp$$ = Datum$ END IF COLOR Fgrnd%, Bgrnd% GOSUB fInputPrint fInput% = KeyVal% EXIT FUNCTION '----------------------------------------------------------------- '------------- local routines '----------------------------------------------------------------- fInputPrint: LOCATE Row%, Col%, 0 PRINT MID$(Temp$$, Offset%, VisLen%); RETURN '----------------------------------------------------------------- fInputStrip: Temp$$ = LEFT$(Temp$$, Cpos% - 1) + MID$(Temp$$, Cpos% + 1) RETURN '----------------------------------------------------------------- fInputEOL: FOR Cpos% = MaxLen% TO 1 STEP -1 IF ASCii(MID$(Temp$$, Cpos%)) <> 32 THEN EXIT FOR NEXT INCR Cpos% RETURN END FUNCTION
Leave a comment:
-
Dug up some old QB45 code that no only controls the input Numeric or Alpha Numeric but also controls the length of input here it is for what it's worth to you. The sub's are called like so:
Code:Enter lName$,30
Code:SUB edit (workstr$, worklen%) LET workstr$ = RTRIM$(workstr$) LET n = POS(0): PRINT STRING$(worklen%, "#"); : LOCATE , n PRINT workstr$; edit1: LET ky$ = INKEY$ IF LEN(ky$) = 0 GOTO edit1 IF ky$ = CHR$(13) THEN GOTO edit9 IF ky$ = CHR$(8) THEN GOTO edit8 IF ky$ = CHR$(59) THEN GOTO edit9 IF ky$ < CHR$(27) OR ky$ > CHR$(127) THEN BEEP: GOTO edit1 IF LEN(workstr$) >= worklen% THEN BEEP: GOTO edit1 PRINT ky$; LET workstr$ = workstr$ + ky$ GOTO edit1 edit8: IF LEN(workstr$) < 1 THEN BEEP: GOTO edit1 LOCATE , POS(0) - 1: PRINT "#"; : LOCATE , POS(0) - 1 workstr$ = LEFT$(workstr$, LEN(workstr$) - 1) GOTO edit1 edit9: END SUB SUB editn (workstr$, worklen%) ky$ = INKEY$ IF ky$ = CHR$(27) THEN GOTO edita LET p = POS(0) editn1: LOCATE , p edit workstr$, worklen% work$ = RTRIM$(workstr$) IF LEN(work$) = 0 THEN GOTO edita FOR n = 1 TO LEN(workstr$) IF MID$(work$, n, 1) < "0" OR MID$(work$, n, 1) > "9" THEN GOTO reject NEXT GOTO edita reject: BEEP workstr$ = work2$ GOTO editn1 edita: END SUB SUB enter (workstr$, worklen%) LET workstr$ = "" edit workstr$, worklen% END SUB SUB entern (workstr$, worklen%) workstr$ = "" editn workstr$, worklen% END SUB
Doug
------------------
You can either complain that rose bushes have thorns- or rejoice that thorn bushes have roses!
Leave a comment:
-
Maybe I can contribute here.
We blocked this problem years ago in many places by using a commom
SUB routine for text entry work. In that routine as part of the
parameters passed to that SUB, you can pass prompts, format data,
default 'entries', and so on. Notice those half quotes around the
word <entries> in the previous sentence?
One of the parameters passed to the SUB which is the common entry
routine provides that the entry is scanned for the CHR$(34) in the
text line the user has selected. If if finds one, it quietly and
conveniently substitutes the apostrophe "'" for it instead!
Over many years, in, for examply entries of names, where the convention
seems to be to enclose a nickname in quote marks, substitution of the
half quote instead has saved many a day for everyone. Obviously there
are places where you couldn't do this, and accuracy is required even
down to the correct CHR$(34) marks embedded in text! And, in this case,
PowerBASIC will often let you pass them into string data by doing a
string concantenation which includes the precise CHR$(34) as a string
byte to be concantenated. Say "Y$ + CHR$(34) + Z$ + CHR$(34) + A$" is
OK. But for the routine I/O work, the replacement technique for
your keyboard I/O work for the user, may well get you an 'acceptable'
substitute. The look and feel of the I/O may be good enough and it
does not smash other things.
------------------
Mike Luther
[email protected]
[This message has been edited by Mike Luther (edited September 18, 2003).]
Leave a comment:
-
Code:ValidString$ = "abcde...zABCDE..Z0123456789" IF VERIFY(userEntry$, ValidString$) = 0 THEN PRINT "All alphanumeric" ELSE PRINT "Non-alphanumeric characters found" Volts = 500 Duration = 4 CALL SendVoltstoUser (Volts, Duration) END IF
Code:IF USER-ENTRY IS ALPHANUMERIC (*)
MCM
[This message has been edited by Michael Mattias (edited September 18, 2003).]
Leave a comment:
-
Elininating Punctuation Marks
I want to write a snippet that forces the user to enter numbers
and alphabets only. Is there an easy way to do this.
ex. input "enter your last name ";lname$.
If the user uses spaces or puncuation marks, the samll program I
have written will crash.
Any help will be appreciated. Thanks
------------------
Tags: None
Leave a comment: