Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Procedure variables
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
gitoxa




PostPosted: Fri May 02, 2008 10:54 pm   Post subject: Procedure variables

code:
procedure gettext (var String : string)


The problem is when I want to use anything but a full string (string(256)) as my "String" it won't accept it. I'd thought of adding a second parameter for the procedure, but couldn't get it to work either.

Any ideas?
Sponsor
Sponsor
Sponsor
sponsor
Clayton




PostPosted: Fri May 02, 2008 10:57 pm   Post subject: RE:Procedure variables

so then don't limit the amount of characters a string can contain. Unfortunately, this is all you can really do.
Zampano




PostPosted: Fri May 02, 2008 11:01 pm   Post subject: Re: Procedure variables

Remove the "var" keyword. I don't know why that manual creation of a parameter or whatever should cause the procedure to insist that the argument be a full 256 bytes, but it works.
I shall not be satisfied until I know why, though.
Mackie




PostPosted: Fri May 02, 2008 11:06 pm   Post subject: RE:Procedure variables

It seems to work fine for me:

Turing:
var theStuff : string (6) := "Hm?"

proc Foobar (var itWorks : string (6))
    itWorks := "Works!"
    put theStuff
end Foobar

Foobar (theStuff)
gitoxa




PostPosted: Fri May 02, 2008 11:16 pm   Post subject: Re: Procedure variables

I can't remove the 'var' keyword if I want it to work as intended. ie. Use my own variable

And it's set to 256 because that's the default. Same way the default int is an int4, real is real8, etc.

This is the sort of thing I want to do
code:
var Name : string(30)
var Address : string(60)

proc gettext (var String : string)
    ...
end gettext

gettext(Name)
gettext(Address)


What I had in mind was along the lines of
It just tells me StrLen hasn't been declared yet. (Even when I switch the two around, as well)
code:
var Name : string(30)
var Address : string(60)

proc gettext (var String : string(StrLen), var StrLen : nat1)
    ...
end gettext

gettext(Name, 30)
gettext(Address, 60)
Tony




PostPosted: Fri May 02, 2008 11:25 pm   Post subject: RE:Procedure variables

maybe I'm missing something... but why not
Turing:

proc do_whatever( _string : string)
   var String : string(length(_string)) := _string
   ...
end do_whatever


Otherwise you can start representing strings with arrays of characters.
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
Mackie




PostPosted: Fri May 02, 2008 11:29 pm   Post subject: RE:Procedure variables

Tony, that wouldn't solve the problem, he most likely needs it for a procedure similar to Mouse.Where. Where the variables are declared else where and the procedure changes them.
gitoxa




PostPosted: Fri May 02, 2008 11:36 pm   Post subject: RE:Procedure variables

It's basically my own "get" command, with input error checking integrated into it.
I have an empty string variable, and want to fill it.

edit:
After trial and error for the past hour, I discovered using "var String : string(*)" does the trick. It will accept any form of a string variable I throw at it.

That calls forth another question though, is there anyway to find the value of the limit of the variable inside the procedure? I'd rather the code did it itself, then have to specify when having to use the procedure.
Sponsor
Sponsor
Sponsor
sponsor
Mackie




PostPosted: Sat May 03, 2008 12:13 am   Post subject: RE:Procedure variables

Well, if your talking about strings here, which I assume you are, then you could use

code:
upper(stringVar)


Since it's an array this will work nicely.
gitoxa




PostPosted: Sat May 03, 2008 12:21 am   Post subject: Re: Procedure variables

That worked great, thanks. Smile
Clayton




PostPosted: Sat May 03, 2008 9:36 am   Post subject: RE:Procedure variables

I have but one question. Why not use a function for this? Procedures that change your variables in unknown ways are generally not a good thing.
gitoxa




PostPosted: Sat May 03, 2008 4:42 pm   Post subject: RE:Procedure variables

Quote:
It's basically my own "get" command, with input error checking integrated into it.


Because it's not changing my variable in unknown ways. It's preventing the user from inputting stupid data, before it's stored to the variable
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 12 Posts ]
Jump to:   


Style:  
Search: