cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Browse apps to extend the software in the new JMP Marketplace
Choose Language Hide Translation Bar
shilpa
Level II

How to multiply user input by a constant number?

All,

 

I'm trying to multiply user input number by a constant. I need to use the final number (hoursBack) as a part of a web address. 

 

local(	
{Name= "ABCD", daysBack = "7", formError = 1, rv},
			While( formError > 0,
				formError = 0;
				rv = Dialog(
					Title( "Select Extract criteria" ),
					VList(
						HList( "Name:", Name= EditText( Name) ),
						HList( "Days Back", daysBack = EditText( daysBack ) ),
						HList( Button( "OK" ), Button( "Cancel" ) )
					)
				);
				If( rv["button"] < 0,
					Throw( "Bye!" )
				);
				Name= rv["Name"];
				If( Name== "",
					formError
					++);
				daysBack = rv["daysBack"];
				If( daysBack == "",
					formError
					++);
				If( formError > 0,
					Dialog( "Missing required form input values" )
				);
			);
			Write( "Name=" || Name);
			hoursBack = daysBack*24;			//Getting an error here
			Status Msg( "Extracting data for " || Name);
			dt = queryData( "Newtable", hoursBack, Name); //Query data function is defined in a different part of the code
		);

Getting the below error - 

 

Cannot convert argument to a number [or matrix] in access or evaluation of 'Multiply' , daysBack * /*###*/24 /*###*/

1 ACCEPTED SOLUTION

Accepted Solutions
shilpa
Level II

Re: How to multiply user input by a constant number?

I realized that it was because I was concatenating daysBack in the link. And I cannot concatenate numbers. I used temporary variables to convert daysback to number first and the resultant multiplied by 24, back to character. This resolved the issue. Thanks!!

View solution in original post

5 REPLIES 5
Craige_Hales
Super User

Re: How to multiply user input by a constant number?

num(daysback)*24

will get you past the problem where daysback holds a string.

Craige
txnelson
Super User

Re: How to multiply user input by a constant number?

The issue is that you are inputting your daysBack from an EditText() field, which returns a character string, not a numeric value.  Therefore it needs to be converted.  See my code below

local(	
{Name= "ABCD", daysBack = "7", formError = 1, rv},
			While( formError > 0,
				formError = 0;
				rv = Dialog(
					Title( "Select Extract criteria" ),
					VList(
						HList( "Name:", Name= EditText( Name) ),
						HList( "Days Back", daysBack = EditText( daysBack ) ),
						HList( Button( "OK" ), Button( "Cancel" ) )
					)
				);
				If( rv["button"] < 0,
					Throw( "Bye!" )
				);
				Name= rv["Name"];
				If( Name== "",
					formError
					++);
				daysBack = num(rv["daysBack"]);show(daysback);
				If( daysBack == "",
					formError
					++);
				If( formError > 0,
					Dialog( "Missing required form input values" )
				);
			);
			Write( "Name=" || Name);
			hoursBack = daysBack*24;
			show("xx",hoursback)	;		//Getting an error here
			Status Msg( "Extracting data for " || char(Name));
			dt = queryData( "Newtable", hoursBack, Name); //Query data function is defined in a different part of the code
		);
Jim
shilpa
Level II

Re: How to multiply user input by a constant number?

@txnelson Thank you. I tried what you suggested but am getting an error. I have attached the snapshot of the error

 

 
 

 

shilpa
Level II

Re: How to multiply user input by a constant number?

I realized that it was because I was concatenating daysBack in the link. And I cannot concatenate numbers. I used temporary variables to convert daysback to number first and the resultant multiplied by 24, back to character. This resolved the issue. Thanks!!

txnelson
Super User

Re: How to multiply user input by a constant number?

The errors in your attached png file are referring to issues with variables called p1 & p2.  Those variables do not appear in the JSL that was previously examined, so I am only guessing as to the issue.  It is my assumption that p1 and p2 are numeric variables, or at least JMP thinks they are.  Numeric values cannot be directly used in a concatenation.  My suggestion is that you enclose each of the references of p1 and p2 in a Char() function. (i.e.  char(p1) )

Jim