
-----------------------------------
nin
Mon Dec 11, 2006 8:57 pm

String manipulation
-----------------------------------
The processing is ok but im having difficulties on the errortrap =(... it says that there is an error but i dont noe how to fix it.. so can someone help me..please and thank you =)... 


*************************************************************
%Declaration statement
var name : string


%Title
locate (1, 34)
put "Name Design"

%Introduction
locate (3, 1)
put "This program will type your name in an increasing way"

%User Input and error trap
for x : 0 .. 100
    locate (5, 1)
    put " "
    put " "
    locate (5, 1)
    put "Please enter a name with a minimum of 3 letters"
    put "and a maximum of 24 letters:" ..
    get name

    if name < 3 or name > 24 then
        locate (6, 1)
        put "Please enter a name that is more than 3 characters and less than 24 characters."
        delay (1000)

    else
        exit
    end if
end for


cls

%Pocessing
for x : 1 .. length (name)
    locate (12 + length (name)
        div 2 - x, 40 - length (name) div 2 + x)
    put name (x .. *)
end for

*************************************************************
P.S.
i want to make the user repeat the step again when they put a name that has less than 3 letters and more than 24 letters...

-----------------------------------
xHoly-Divinity
Mon Dec 11, 2006 9:30 pm


-----------------------------------
Well.. the reason ur getting an error is because u are comparing a 'string' variable to an integer value. So u are basically saying

if "dogs" < 3    which doesn't make sense.

U need to determine how many letters are in the word and then compare that to the value u want. I'm not really sure how to do that.. maybe try using char?

-----------------------------------
Clayton
Mon Dec 11, 2006 9:54 pm


-----------------------------------
The solution to your problem lies in your processing section. The function length(), which returns the length of a given string.

-----------------------------------
nin
Mon Dec 11, 2006 10:27 pm


-----------------------------------
The solution to your problem lies in your processing section. The function length(), which returns the length of a given string.

but when the teacher checked it she said it was right... but the thing is the errortrap part. 0.o?... i dont get it?

-----------------------------------
TokenHerbz
Mon Dec 11, 2006 10:37 pm


-----------------------------------
your code:

 if name < 3 or name > 24 then 


As you where told, this is checking a string var to an integer.  This dosn't make sence.  You need to find the length in letters of your word, to compare it to your ints (aka. allowable length).


if length(name) < 3 or length(name) > 24 then


this "length(string)" checked the length of your string var, and returns the number as an int.   This will allow you to check it.

-----------------------------------
nin
Tue Dec 12, 2006 9:28 am


-----------------------------------
thank you people for your help =)
