Post Reply 
Inputting a string.
02-16-2022, 09:11 PM
Post: #1
Inputting a string.
Is there a way to have an INPUT variable recognised as a string?

I was writing a program that required the leading zeros to be retained and thought that if I could input it as a string, then I could manipluate it the way I want earlier.

If I input 07021999 as a number variable, then it becomes 7021999 instantly.

Also, if I just had to input a name for example, obviously it would just be useful to be able to input letters instead of numbers.
Find all posts by this user
Quote this message in a reply
02-16-2022, 09:44 PM
Post: #2
RE: Inputting a string.
(02-16-2022 09:11 PM)matalog Wrote:  Is there a way to have an INPUT variable recognised as a string?

I was writing a program that required the leading zeros to be retained and thought that if I could input it as a string, then I could manipluate it the way I want earlier.

If I input 07021999 as a number variable, then it becomes 7021999 instantly.

Also, if I just had to input a name for example, obviously it would just be useful to be able to input letters instead of numbers.

INPUT({{A1,[2]}})

will expect a string for variable A1. The [2] determines the datatype of string. [-1] means all types are allowed. See the manual for other types.

Tom L
Cui bono?
Find all posts by this user
Quote this message in a reply
02-16-2022, 10:00 PM
Post: #3
RE: Inputting a string.
Yes it is possible, also described if you put INPUT on the command line and press help. But I have to admit, that it is not so easy to be understood.
Code:
Syntax:
INPUT(var,[“title”], [“label”], [“help”], [reset_value], [initial_value])
INPUT({vars},[“titles”], [{“labels”}], [{“helps”}], [{reset_values}], [{initial_values}])
var -> {var_name, real, [{pos}]}
var -> {var_name, [allowed_types_matrix], [{pos}]}
var -> {var_name, {choose_items}, [{pos}]}

For your required input you need the second more complex form. Don't worry it's not overly complicated.
  • First of all you have to create a variable that will receive your INPUT as the standard variables "A" through "Z" don't accept strings.
  • Type 123 or anything else then touch [Sto>] and enter e.G. MyVar, the Prime will ask you "Do you want to create a variable called MyVar" once you press OK, you have what you need to work with.
  • INPUT({{MyVar,[2]}})
The outer braces comprise the list of variables (here is only one). The inner braces identify the Variable with its name, here it is MyVar, the [2] identifies the the allowed types, here we allow only one: 2 is for strings. That's it.

You may of course add some bells and whistles, but start it simple Smile

HTH Günter
Find all posts by this user
Quote this message in a reply
02-16-2022, 11:35 PM
Post: #4
RE: Inputting a string.
That's great thanks guys. I don't realy understand how you got all of that information from the Help entry on the calc.

Where are the various allowed types identifier numbers listed? I can see that -1 will allow all, but where does it state that type 2 will be a definite string?
Find all posts by this user
Quote this message in a reply
02-16-2022, 11:54 PM
Post: #5
RE: Inputting a string.
(02-16-2022 11:35 PM)matalog Wrote:  That's great thanks guys. I don't realy understand how you got all of that information from the Help entry on the calc.

Where are the various allowed types identifier numbers listed? I can see that -1 will allow all, but where does it state that type 2 will be a definite string?

Help is your help Smile ..not always but..

Toolbox ,"Type" help et Voilà

Günter
Find all posts by this user
Quote this message in a reply
02-17-2022, 02:36 AM
Post: #6
RE: Inputting a string.
(02-16-2022 11:35 PM)matalog Wrote:  That's great thanks guys. I don't realy understand how you got all of that information from the Help entry on the calc.

Where are the various allowed types identifier numbers listed? I can see that -1 will allow all, but where does it state that type 2 will be a definite string?

Page 657 of the User Guide has all the types:

Code:
TYPE
Syntax: TYPE(object)
Returns the type of the object:
0: Real
1: Integer
2: String
3: Complex
4: Matrix
5: Error
6: List
8: Function
9: Unit
14.?: cas object. The fractional part is the cas type.

Tom L
Cui bono?
Find all posts by this user
Quote this message in a reply
02-17-2022, 02:45 PM
Post: #7
RE: Inputting a string.
Not to forget the manual: https://www.hpcalc.org/prime/docs/hpprimeug.zip . It is a bit outdated but still helpful.
Arno
Find all posts by this user
Quote this message in a reply
Post Reply 




User(s) browsing this thread: 3 Guest(s)