1. RE: variable start values
- Posted by Jason Dube <dubetyrant at hotmail.com> Dec 10, 2003
- 503 views
Well ok, Sometimes it works and sometimes it doesn't. I went back and tested it several times without the var initializing and it generated the correct error message. The point is, sometimes it doesn't. I am assuming that I have to initialize every variable, but I have had euphoria for every year and this happens occassionally(like today) Jason Dube wrote: > > > Hi, > Im writing a simple punctuation checker, I get the following message > when I try to execute this: > > "capital1 has not been assigned a value" > > function check_for_punc_1(object x) > boolean capital1 > if x[1][1] < 90 then > position(2,1) > puts(1,"GARBLE: [Sentence is not capitalized...]") > capital1=0 > end if > return capital1 > end function > > Do I have to initialize it first? > Because I have noticed that at other times, with similar things, I dont > have to initialize... > For instance, if I go back to my function and add this line: > > function check_for_punc_1(object x) > boolean capital1 > capital1=1 > if x[1][1] < 90 then > position(2,1) > puts(1,"GARBLE: [Sentence is not capitalized...]") > capital1=0 > end if > return capital1 > end function > > The program will run fine... > Then I can actually go back and DELETE that line, and it will still run > fine. I can save the program and run it as many times as I want > and it will run fine without that initialization. > > Almost like the interpreter remembers when I initialized it... > > Am I making sense? What is going on? I would just as soon NOT initialize > > the variable if my routine is going to set the value later. > But the question is:do I have to or not? >
2. RE: variable start values
- Posted by "Mike Sabal" <Sabal.Mike at notations.com> Dec 10, 2003
- 503 views
Jason, By the time the function hits the return, there needs to be a value assigned to capital1. If x[1][1] is less than 90, that happens. But if not, there is no other place for the value to be assigned, so the program crashes. You have to options to correct this: initialize capital1 or add an else statement to assign a value to capital1. You could also remove the variable altogether and use multiple returns. if x[1][1] < 90 then -- do stuff return 0 else return 1 end if HTH, Mike Sabal >>> dubetyrant at hotmail.com 12/10/2003 11:42:20 AM >>> Jason Dube wrote: > > "capital1 has not been assigned a value" > > function check_for_punc_1(object x) > boolean capital1 > if x[1][1] < 90 then > position(2,1) > puts(1,"GARBLE: [Sentence is not capitalized...]") > capital1=0 > end if > return capital1 > end function
3. RE: variable start values
- Posted by Jason Dube <dubetyrant at hotmail.com> Dec 10, 2003
- 507 views
Hi, Thanks for both replies...I understand clearly now, thank you. Mike Sabal wrote: > > > Jason, > By the time the function hits the return, there needs to be a value > assigned to capital1. If x[1][1] is less than 90, that happens. But if > not, there is no other place for the value to be assigned, so the > program crashes. You have to options to correct this: initialize > capital1 or add an else statement to assign a value to capital1. You > could also remove the variable altogether and use multiple returns. > > if x[1][1] < 90 then > -- do stuff > return 0 > else > return 1 > end if > > HTH, > Mike Sabal > > >>> dubetyrant at hotmail.com 12/10/2003 11:42:20 AM >>> > Jason Dube wrote: > > > > "capital1 has not been assigned a value" > > > > function check_for_punc_1(object x) > > boolean capital1 > > if x[1][1] < 90 then > > position(2,1) > > puts(1,"GARBLE: [Sentence is not capitalized...]") > > capital1=0 > > end if > > return capital1 > > end function > >
4. RE: variable start values
- Posted by Jason Dube <dubetyrant at hotmail.com> Dec 10, 2003
- 488 views
Pete Lomax wrote: > > > On Wed, 10 Dec 2003 16:33:19 +0000, Jason Dube > <dubetyrant at hotmail.com> wrote: > > > if x[1][1] < 90 then > > It took me a moment to figure that out. I suggest you use > "if x[1][1] < 'Z' then" instead, and probably <= as well. > > Regards, > Pete > Well, I had it backwards, it was supposed to tell me if the sentence was not capitalized, which would have been if x[1][1] > 90 anyways...of course this wouldn't help if the user put something lower than 'A', but I'll restrict it more later. :) But using 'Z' is better, more readable,and thorough, thx.
5. RE: variable start values
- Posted by Ron Austin <ronaustin at alltel.net> Dec 10, 2003
- 492 views
Pete Lomax wrote: > > > On Wed, 10 Dec 2003 16:33:19 +0000, Jason Dube > <dubetyrant at hotmail.com> wrote: > > > if x[1][1] < 90 then > > It took me a moment to figure that out. I suggest you use > "if x[1][1] < 'Z' then" instead, and probably <= as well. > > Regards, > Pete > If he wants to trap non capital letters shouldn't it be <65 or > 90 -- > <'A' or >'Z' this would trap lower case plus misc numbers, punctuation , > etc.