Omnimaga

Calculator Community => TI Calculators => Axe => Topic started by: tehalynn on November 28, 2010, 06:33:56 pm

Title: How do you write a string to the basic variable Ans?
Post by: tehalynn on November 28, 2010, 06:33:56 pm
How do you write a string to the basic variable Ans?
Title: Re: How do you write a string to the basic variable Ans?
Post by: Xeda112358 on November 28, 2010, 06:35:18 pm
Whenever you use a string it is stored in Ans. For example:
:"HELLO
:If Ans="HELLO
:Pause Ans
Title: Re: How do you write a string to the basic variable Ans?
Post by: jnesselr on November 28, 2010, 06:39:13 pm
Actually, anything you do is written in ans.  Any function automatically stores it's value into ans.  Which means that it can only be used temporarily, because as soon as you do anything that returns a value, the value of ans will change.
Title: Re: How do you write a string to the basic variable Ans?
Post by: Xeda112358 on November 28, 2010, 06:42:32 pm
Wait a minute... Axe... Oops? I believe a similar question came up before, but I do not remember where. Sorry...
Title: Re: How do you write a string to the basic variable Ans?
Post by: Deep Toaster on November 28, 2010, 06:42:50 pm
I actually don't know how to do it, but just to let you all know, this is in the Axe Parser subforum ;)

EDIT: Ah, ninja'd.
Title: Re: How do you write a string to the basic variable Ans?
Post by: Munchor on November 28, 2010, 06:43:16 pm
I also think it could be moved.

Anyways, here's a screnie
Title: Re: How do you write a string to the basic variable Ans?
Post by: calc84maniac on November 28, 2010, 06:48:42 pm
You should be able to use Data(4,TAns,0) as a name with GetCalc() to create or modify Ans as a string.
Title: Re: How do you write a string to the basic variable Ans?
Post by: AngelFish on November 28, 2010, 06:51:58 pm
You can access it in Assembly through OP1. The code for the TI-OS Ans variable is 72h, followed by two bytes of 0. The variable is used for system storage, though, so it's rather volatile. I'd only recommend using it in something like a sprite editor where the user has to transfer data. If you need to store data within the program for later computation, the Ans variable might take too long to store to.

EDIT: kind of Ninja'd  :P
Title: Re: How do you write a string to the basic variable Ans?
Post by: DJ Omnimaga on November 28, 2010, 06:56:17 pm
I also think it could be moved.

Anyways, here's a screnie
Nah his question was about Axe so it should remain here.

By the way welcome here tehalynn :) .
Title: Re: How do you write a string to the basic variable Ans?
Post by: calcdude84se on November 28, 2010, 07:04:23 pm
It does need two 0's. (Unless you're ending the line with ->Str0 etc.)
For example, this line does not work: (There needs to be another 0 in the Data( sequence)
Disp GetCalc(Data(4,TAns,0
Also, the data in Ans are a series of tokens, not characters, so be aware of that ;)
Title: Re: How do you write a string to the basic variable Ans?
Post by: calc84maniac on November 28, 2010, 07:22:49 pm
It does need two 0's. (Unless you're ending the line with ->Str0 etc.)
For example, this line does not work: (There needs to be another 0 in the Data( sequence)
Disp GetCalc(Data(4,TAns,0
Also, the data in Ans are a series of tokens, not characters, so be aware of that ;)
Ah yeah. You only need one 0 after a two-byte name, but two 0's after a one-byte name.
Title: Re: How do you write a string to the basic variable Ans?
Post by: tehalynn on November 28, 2010, 08:07:33 pm
Wow, there are lots of helpful people here!  :)

Sorry I wasn't more clear, this was a question about Axe. I just found it recently and I'm impressed. I only really program on-calc so I'd been hoping for a while that somebody would make something like this.

I'm using Ans so that the string can be recalled easily after the program ends.

So let's say I want to put "TEST" into Ans. How exactly do I go about doing that? I don't entirely understand Data, TToken, and how to convert between a string and tokens.
Title: Re: How do you write a string to the basic variable Ans?
Post by: AngelFish on November 28, 2010, 08:13:23 pm
It'd be something like
"TEST"->GetCalc(Data(4,TAns,0

Title: Re: How do you write a string to the basic variable Ans?
Post by: calcdude84se on November 28, 2010, 08:17:05 pm
No, you have to copy data. So more like this:
Code: [Select]
Copy("TEST",GetCalc(Data,4,[sup]T[/sup],0,0),4
Title: Re: How do you write a string to the basic variable Ans?
Post by: AngelFish on November 28, 2010, 08:18:15 pm
That makes more sense. I'd forgotten about the Copy( token.
Title: Re: How do you write a string to the basic variable Ans?
Post by: calc84maniac on November 28, 2010, 08:20:28 pm
No, you have to copy data. So more like this:
Code: [Select]
Copy("TEST",GetCalc(Data,4,[sup]T[/sup],0,0),4
Code tags (and typos) murdered this. Here's what it should look like:
Copy("TEST",GetCalc(Data(4,TAns,0,0),4),4)

It's a bit cluttered, though.
Title: Re: How do you write a string to the basic variable Ans?
Post by: AngelFish on November 28, 2010, 08:22:46 pm
And here comes Quigibo with his four byte alternative...
Title: Re: How do you write a string to the basic variable Ans?
Post by: tehalynn on November 28, 2010, 10:03:53 pm
No, you have to copy data. So more like this:
Code: [Select]
Copy("TEST",GetCalc(Data,4,[sup]T[/sup],0,0),4
Code tags (and typos) murdered this. Here's what it should look like:
Copy("TEST",GetCalc(Data(4,TAns,0,0),4),4)

It's a bit cluttered, though.

I tried that and it didn't seem to change Ans. If I instead do Copy("TEST",GetCalc(Data(4,TAns,0,0)),4) it changes Ans to a decimal number, but not a string. I wish I understood this better.
Title: Re: How do you write a string to the basic variable Ans?
Post by: calc84maniac on November 28, 2010, 10:19:51 pm
Well, for one thing that code is a little different from mine (missing a ,4). But on the other hand, I just tried it now, and there is a bit of a glitch with Axe. This code only works if Ans was previously a string. The reason is that when Axe looks for an existing Ans variable to delete, it's looking for a string (and type matters because it's using chkfindsym). If it searched using findsym, it would work (but would fail for programs and appvars).
Title: Re: How do you write a string to the basic variable Ans?
Post by: Runer112 on November 28, 2010, 11:04:28 pm
Well, for one thing that code is a little different from mine (missing a ,4). But on the other hand, I just tried it now, and there is a bit of a glitch with Axe. This code only works if Ans was previously a string. The reason is that when Axe looks for an existing Ans variable to delete, it's looking for a string (and type matters because it's using chkfindsym). If it searched using findsym, it would work (but would fail for programs and appvars).

A simple fix that should always successfully create Ans as a string:
Code: [Select]
Data(4,ᵀAns,0,0)→Str0AN
DelVar Str0AN
Copy("TEST",GetCalc(Str0AN,4),4)
Title: Re: How do you write a string to the basic variable Ans?
Post by: calc84maniac on November 28, 2010, 11:20:34 pm
Well, for one thing that code is a little different from mine (missing a ,4). But on the other hand, I just tried it now, and there is a bit of a glitch with Axe. This code only works if Ans was previously a string. The reason is that when Axe looks for an existing Ans variable to delete, it's looking for a string (and type matters because it's using chkfindsym). If it searched using findsym, it would work (but would fail for programs and appvars).

A simple fix that should always successfully create Ans as a string:
Code: [Select]
Data(4,ᵀAns,0,0)→Str0AN
DelVar Str0AN
Copy("TEST",GetCalc(Str0AN,4),4)
Odd, I thought that wouldn't work due to the same glitch. It seems to work when I do it though.
Title: Re: How do you write a string to the basic variable Ans?
Post by: tehalynn on November 28, 2010, 11:46:47 pm
Well, for one thing that code is a little different from mine (missing a ,4). But on the other hand, I just tried it now, and there is a bit of a glitch with Axe. This code only works if Ans was previously a string. The reason is that when Axe looks for an existing Ans variable to delete, it's looking for a string (and type matters because it's using chkfindsym). If it searched using findsym, it would work (but would fail for programs and appvars).

A simple fix that should always successfully create Ans as a string:
Code: [Select]
Data(4,ᵀAns,0,0)→Str0AN
DelVar Str0AN
Copy("TEST",GetCalc(Str0AN,4),4)

Well that seemed to work! Thank you! And thank you everyone else who offered help.
Title: Re: How do you write a string to the basic variable Ans?
Post by: Deep Toaster on November 29, 2010, 07:18:54 pm
Well, for one thing that code is a little different from mine (missing a ,4). But on the other hand, I just tried it now, and there is a bit of a glitch with Axe. This code only works if Ans was previously a string. The reason is that when Axe looks for an existing Ans variable to delete, it's looking for a string (and type matters because it's using chkfindsym). If it searched using findsym, it would work (but would fail for programs and appvars).

A simple fix that should always successfully create Ans as a string:
Code: [Select]
Data(4,ᵀAns,0,0)→Str0AN
DelVar Str0AN
Copy("TEST",GetCalc(Str0AN,4),4)

Thanks for the routine! So this'll work with any other type too, right?
Title: Re: How do you write a string to the basic variable Ans?
Post by: Quigibo on November 29, 2010, 08:20:30 pm
By the way, isn't Data(4,TAns,0,0) simply "Ans" in quotes?  That should work, if it doesn't then its a bug I need to fix.
Title: Re: How do you write a string to the basic variable Ans?
Post by: tehalynn on November 30, 2010, 01:26:29 am
By the way, isn't Data(4,TAns,0,0) simply "Ans" in quotes?  That should work, if it doesn't then its a bug I need to fix.

So what's the full code for the method that should also work?
Title: Re: How do you write a string to the basic variable Ans?
Post by: Runer112 on November 30, 2010, 10:42:00 am
By the way, isn't Data(4,TAns,0,0) simply "Ans" in quotes?  That should work, if it doesn't then its a bug I need to fix.

"Ans" is just $72. Store it to a pointer and you'll get $72,$00, but that's still far off from $04,$72,$00,$00.
Title: Re: How do you write a string to the basic variable Ans?
Post by: Quigibo on November 30, 2010, 07:26:49 pm
Did you try that on the calculator though?  It should substitute it for $04,$75,$00 like I do with picture variables, lists, and other OS variables.   Tokens in quotes don't always map to the original token values if they don't have corresponding ascii values.  But I suspect that it isn't working for some reason since no one seems to be using it.  I'll have to fix that next version.
Title: Re: How do you write a string to the basic variable Ans?
Post by: Deep Toaster on November 30, 2010, 07:42:39 pm
Nope, just tried it, and it's just a $72.
Title: Re: How do you write a string to the basic variable Ans?
Post by: calc84maniac on November 30, 2010, 07:44:46 pm
Did you try that on the calculator though?  It should substitute it for $04,$75,$00 like I do with picture variables, lists, and other OS variables.   Tokens in quotes don't always map to the original token values if they don't have corresponding ascii values.  But I suspect that it isn't working for some reason since no one seems to be using it.  I'll have to fix that next version.
But Ans is not tied to a certain data type, so you can't just generate a 4 for it.