Home   Archive   Permalink



Would anybody like to revise my program ?

This is a program I wrote to implement into a POS program which I am writing for a restaurant. It is used to restrict access to certain functions in the POS for different security levels, e.g the dishwasher is not allowed to take orders.
    
R E B O L [
     Title: 'Access Code'
     Note: 'Adapted from Jeff Kreis', Allen Kamp's, and Carl Sassenrath's Calculator'
     Author: 'Andrew'
     License: 'GNU GPL whatever the latest v is'
]
    
trim-last: func ['Removes last value of a string' thing [string!]] [
     remove back tail thing
]
employeeCodes: [
     '1' 'Bob' 'level 1' 'Dishwasher'
     '2' 'George' 'level 2' 'Chef'
     '3' 'George' 'level 3' 'Server'
     '4' 'Fred' 'level 4' 'Manager'
     '5' 'George' 'level 5' 'Owner'
     '6' 'Andrew' '100' 'Programmer'
     '7' 'Nick' 'over 9000 !' 'Rebol Guru'
]
clear-code: does [
     clear head inputCode
     clear head l/text
     show l
]
inputCode: ''
checkCode: false
gui: layout [
     ;all of the weird colors are just for fun while testing
     backdrop effect [gradient sky reblue]
     style b1 button effect [gradient cyan pink] 160x120 bold font-size 36
     style b2 button effect [gradient pink teal] 160x120 bold font-size 36
     style c button effect [gradient 1x1 crimson brick] 160x60 bold font-size 36 [if equal? checkCode false [clear-code]]
     style k button effect [gradient 1x1 wheat rebolor] 160x120 bold font-size 48 [if equal? checkCode false [append inputCode face/text append l/text '*' show l]]
     guide
     l: label 328x50 with [font: [valign: 'top]] bold font-size 76 black center '' return
     c 'Clear' keycode [#'C' #'c']
     across
     k '7' #'7' k '8' #'8' k '9' #'9' return
     k '4' #'4' k '5' #'5' k '6' #'6' return
     k '1' #'1' k '2' #'2' k '3' #'3' return
     b1 'Exit' #'^(ESC)' [
         if equal? checkCode false [unview]
     ]
     k '0' #'0'
     b2 'Submit' #'^M' [
         if equal? checkCode false [
             either find employeeCodes inputCode [
                 checkCode: true
                 alert rejoin ['Welcome, ' select employeeCodes inputCode '. Your security is ' select employeeCodes select employeeCodes inputCode '; ' select employeeCodes select employeeCodes select employeeCodes inputCode]
                 checkCode: false
             ] [
                    
                 if not equal? inputCode '' [checkCode: true alert 'Invalid access code' checkCode: false]
             ]
         clear-code
         ]
     ]
     key keycode [#'^H'] [if equal? checkCode false [trim-last inputCode trim-last l/text show l]]
]
    
view/options center-face gui [no-title no-border]
;is it possible to make the 'alert' funstion display with the same [no-title no-border] options ?

posted by:   Andrew       4-May-2017/21:46:16-7:00



At first look, your code runs great. You can make your own alert function:
    
R E B O L [title: "alrt"]
alrt: func [txt] [
    view/new/options center-face layout [
     backdrop effect [gradient sky reblue]
     at 20x20 text (txt)
     btn "OK" [unview]
    ][no-title no-border]
]
view layout [
    btn "alrt" [alrt "asdf"]
]

posted by:   Nick       5-May-2017/0:42:16-7:00



*gasp* Complimented by Nick ! *faints* (assuming it's Nick Antonaccio)
    
Thanks for the alrt function, Nick. Would you know how to make the window created by alrt keep the focus until it is closed ? What I mean is if you try to click on a button behind the 'alert' window, nothing happens. Even if you minimize the alert window, you can't click on any buttons behind it until it is closed.

posted by:   Andrew       5-May-2017/1:31:51-7:00



Enter 100 as a code?
    
Maybe not a good idea to defeat the focus of the alert. But,one might be able to hide the custom alert on a face click.
    
I cut back the code some, not found a bug yet.
    
inputCode: make string! 4
    
employeeCodes: [
     1     "Bob"     "1"         "Dishwasher"
     2     "George"     "2"         "Chef"
     3     "George"     "3"         "Server"
     4     "Fred"     "4"         "Manager"
     5     "George"     "5"         "Owner"
     6     "Andrew"     "100"         "Programmer"
     7     "Nick"     "over 9000!"     "Rebol Guru"
]
    
clear-code: [
     clear inputCode
     reset-face pin
]
    
gui: layout [
     backdrop effect [gradient sky reblue]
     style key button effect [gradient 1x1 wheat rebolor] 180x120 bold font-size 48 [
            append inputCode to-integer face/text
            append pin/text "*"
            show pin
     ]
     across
     pin: label 328x50 bold font-size 76 black
     key effect [gradient 1x1 crimson brick] "Clear" #"c" [do clear-code] return
     key "7" #"7" key "8" #"8" key "9" #"9" return
     key "4" #"4" key "5" #"5" key "6" #"6" return
     key "1" #"1" key "2" #"2" key "3" #"3" return
     key effect [gradient 1x1 cyan pink] "Exit" #"^(ESC)" [ quit ]
     key "0" #"0"
     key effect [gradient 1x1 cyan pink] "Submit" #"^s" [
             either (find employeeCodes to-integer inputCode) [
    peg: index? find employeeCodes to-integer inputCode
                 alert rejoin [
        "Welcome. "                     employeeCodes/(peg + 1)
                        ", your security level is " employeeCodes/(peg + 2) " "
                                                     employeeCodes/(peg + 3) "."]
             ] [        
    alert "Invalid access code"
             ]
             do clear-code    
     ]
]    
pin/font/valign: pin/font/align: 'center
view/options center-face gui [no-title no-border]


posted by:   JB       5-May-2017/1:51:39-7:00



I think the "inform" function makes a window that must be attended to.

posted by:   Steven White       5-May-2017/8:28:05-7:00



Which REBOL version are you using ?


posted by:   Giuseppe Chillemi       5-May-2017/16:15:01-7:00



The version I use is REBOL/View 2.7.8.3.1 1-Jan-2011, not sure who the question was addressed to.

posted by:   JB       5-May-2017/18:39:47-7:00



Here are some functions I wrote to help align values on thermal printer paper.
    
lol: func ["adds a second zero past the decimal" thing [string!]] [;only works if you to-string a decimal
     reverse thing
     either not equal? third thing #"." [
         reverse thing
         append thing "0"
     ] [
         reverse thing
     ]
]
    
rofl: func ["adds empty space in front of a string until the string is a certain length" thing [string!]] [
     if not equal? length? thing 7 [until [reverse thing append thing "^ " reverse thing equal? length? thing 7]]
]
    
    
A problem I have is that if a value is 1.00, rebol will print it as 1.0. If you have two numbers, 100.00 and 10.0 right aligned and printed on different lines, they won't line up to the decimal. If they are left aligned, then they still won't be aligned to the decimal.
    
I suppose you could just convert the values to money and remove the $....
    
I can't figure out how to right-align some characters and left-align other characters on the same line, so I have to print certain values at the column number which is their length subtracted from the max character length of the line. Putting the blank spaces in front of each value just makes it easier because some values are up to 1000.00 (7) and others are only 0.00 (4).

posted by:   Andrew       11-May-2017/0:08:48-7:00



There are various functions around to PAD and/or JUSTIFY a field to a specific length, left or right aligned.
    
One example from Gregg:
    
http://www.rebol.org/ml-display-message.r?m=rmlCZGQ

posted by:   Sunanda       11-May-2017/8:29:32-7:00



You'll need this at some point too:
    
http://www.rebol.org/view-script.r?script=format-decimal.r

posted by:   Nick       11-May-2017/20:50:53-7:00



To make a modal window which keeps others from processing events:
    
source alert
    
you'll see that 'alert is a shortcut for request/ok/type
    
source request
    
you'll see it uses 'inform
    
source inform
    
you'll see it uses 'show-popup
    
source show-popup
    
All the tricks are in that source.
    
My first inclination would be to just hide any window in which I didn't want activity.

posted by:   Nick       11-May-2017/21:00:21-7:00



Name:


Message:


Type the reverse of this captcha text: "t r e s n i"



Home