
-----------------------------------
gitoxa
Fri May 02, 2008 10:54 pm

Procedure variables
-----------------------------------
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?

-----------------------------------
Clayton
Fri May 02, 2008 10:57 pm

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
Fri May 02, 2008 11:01 pm

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
Fri May 02, 2008 11:06 pm

RE:Procedure variables
-----------------------------------
It seems to work fine for me:

var theStuff : string (6) := "Hm?"

proc Foobar (var itWorks : string (6))
    itWorks := "Works!"
    put theStuff
end Foobar

Foobar (theStuff)

-----------------------------------
gitoxa
Fri May 02, 2008 11:16 pm

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
 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)
 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
Fri May 02, 2008 11:25 pm

RE:Procedure variables
-----------------------------------
maybe I'm missing something... but why not

proc do_whatever( _string : string)
   var String : string(length(_string)) := _string
   ...
end do_whatever


Otherwise you can start representing strings with arrays of characters.

-----------------------------------
Mackie
Fri May 02, 2008 11:29 pm

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
Fri May 02, 2008 11:36 pm

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.

-----------------------------------
Mackie
Sat May 03, 2008 12:13 am

RE:Procedure variables
-----------------------------------
Well, if your talking about strings here, which I assume you are, then you could use 

upper(stringVar)

Since it's an array this will work nicely.

-----------------------------------
gitoxa
Sat May 03, 2008 12:21 am

Re: Procedure variables
-----------------------------------
That worked great, thanks. :)

-----------------------------------
Clayton
Sat May 03, 2008 9:36 am

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
Sat May 03, 2008 4:42 pm

RE:Procedure variables
-----------------------------------
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
