Rebol Talk Forum  |  Getting Started  |  Newbie Help  |  Topic: how to convert the value to integer?
Pages: [1] Print
Author Topic: how to convert the value to integer?  (Read 272 times)
cheryl
Guest


Email
how to convert the value to integer?
« on: April 01, 2004, 12:41:33 AM »

REBOl[]

list-names: func[] [db-select * person]
;names: [[1 "martin"] [2 "stella"] [3 "joe"]]
form-style: stylize[
new: txt with [size: 150x50 font: [align: 'right]]
inp:   field with [size: 240x24]

 

]  

 do %db.r
add: layout [
    styles form-style    
    backdrop effect [gradient 1x1 0.0.0 0.0.180]
             
     new "Please enter a new ID" Red  id: inp 165x24    
     new "Please enter a new name" Red na: inp 165x24
   
      button black "test" [save-data]    
                     
         
     ;button black "Add"  [db compose/deep[insert into person values [ 20 (na/text) ]]]
     ;button black "Cancel" [quit]
]
     save-data: does[
     data: reduce [id/text]
     change: to-integer data
             
        print change
                 
    ]
             
     
         

     view layout [

    button "new info" [inform add]
    ;button "delete"
]



I not sure whether the code was correct as I having the error and not sure how to convert the value to integer.. Thank you
 
Logged
CarlRead
Full Member
***
Offline Offline

Posts: 105


View Profile
how to convert the value to integer?
« Reply #1 on: April 01, 2004, 02:59:02 AM »

TO-INTEGER is the right word to use.  Your problem lies in the use of REDUCE.  REDUCE returns a block so if id/text is "123", DATA will reference ["123"] and not "123".  Two solutions, depending on what you expect id/text to contain:
Code:
data: copy id/text  ; The COPY may not be needed

data: first reduce [id/text]
Note also you've used ADD and CHANGE as global words.  REBOL already uses these and so you may eventually hit a conflict.  ie, require the REBOL versions later as your script developes.  It's perfectly OK to redefine REBOL's default words, but is obviously best only when you really want to.  If you want to prevent this happening accidently, add PROTECT-SYSTEM to your %user.r script and you'll get an error if a script attempts to redefine a system function.
Logged

- Carl Read
Pages: [1] Print 
Rebol Talk Forum  |  Getting Started  |  Newbie Help  |  Topic: how to convert the value to integer?
Jump to:  

  
Quick Search...

Advanced search
  
Welcome, Guest. Please login or register.
Did you miss your activation email?
September 05, 2008, 11:36:42 PM
Username: Password: Session Length:
  

News: 01-09-08

Alpha version of REBOL 3 has been released!


  
2233 Posts in 581 Topics by 1854 Members
Latest Member: Vqxykkpz

  Rebol Talk Forum | Powered by SMF 1.0.9.
© 2001-2005, Lewis Media. All Rights Reserved.

RT design by Defiant Pc