HP Forums
Inputting a string. - Printable Version

+- HP Forums (https://www.hpmuseum.org/forum)
+-- Forum: HP Calculators (and very old HP Computers) (/forum-3.html)
+--- Forum: HP Prime (/forum-5.html)
+--- Thread: Inputting a string. (/thread-18043.html)



Inputting a string. - matalog - 02-16-2022 09:11 PM

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.


RE: Inputting a string. - toml_12953 - 02-16-2022 09:44 PM

(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.


RE: Inputting a string. - Guenter Schink - 02-16-2022 10:00 PM

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


RE: Inputting a string. - matalog - 02-16-2022 11:35 PM

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?


RE: Inputting a string. - Guenter Schink - 02-16-2022 11:54 PM

(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


RE: Inputting a string. - toml_12953 - 02-17-2022 02:36 AM

(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.



RE: Inputting a string. - Arno K - 02-17-2022 02:45 PM

Not to forget the manual: https://www.hpcalc.org/prime/docs/hpprimeug.zip . It is a bit outdated but still helpful.
Arno