project.Variables are all string, how to declare it as int?

bluescharp

Client
Joined
Jun 20, 2012
Messages
35
Reaction score
1
Points
8
em... I have a variable in project, and I want to change it with some C# code, then use it in project.
but I can't set project.Variables["heartbeat"].Value = -1;
because project.Variables["heartbeat"] is a string. how to declare it as int?
 

bigcajones

Client
Joined
Feb 9, 2011
Messages
1,216
Reaction score
683
Points
113
Convert.ToInt32(project.Variables["heartbeat"].Value);
 

lokiys

Moderator
Joined
Feb 1, 2012
Messages
4,771
Reaction score
1,184
Points
113
JavaScript:
string cSharpVariable = project.Variables["heartbeat"].Value;
int numeric = Convert.ToInt32(cSharpVariable);
return numeric;
 
Last edited:

cherubin

Client
Joined
Jun 6, 2016
Messages
92
Reaction score
6
Points
8
Hi, and could we convert the string to int in "classic zenno" and not for a C# template ? In order to record integer in a table for example
 

EtaLasquera

Client
Joined
Jan 2, 2017
Messages
524
Reaction score
112
Points
43

cherubin

Client
Joined
Jun 6, 2016
Messages
92
Reaction score
6
Points
8

lokiys

Moderator
Joined
Feb 1, 2012
Messages
4,771
Reaction score
1,184
Points
113
Hi, and could we convert the string to int in "classic zenno" and not for a C# template ? In order to record integer in a table for example
Numbers are automatically int. In classic way, you do not handle variable types. It's all var
You record number in the table and thats number.
What issues do you have?
 

cherubin

Client
Joined
Jun 6, 2016
Messages
92
Reaction score
6
Points
8
I parse a bad formated json file ( i posted here about it https://zennolab.com/discussion/threads/how-to-save-ugly-no-properties-json-to-table.63292/#post-451880 ) However i succeed to deal with but the data parsed are some time like this :

Code:
0.50031072108822885E1
0,45786
3.45784
So i replace some text in order to have only one format which is : (int)(comma)(int)(int)(int) like 0,457
Then i record in a table which saves in a xlsx file.

So everything work great, but when i oopenb the xlsx file it's text in cell instead of number/integer.

upload_2019-8-30_18-53-17.png
 

cherubin

Client
Joined
Jun 6, 2016
Messages
92
Reaction score
6
Points
8
So no idea @lokiys for my issue ?
 

lokiys

Moderator
Joined
Feb 1, 2012
Messages
4,771
Reaction score
1,184
Points
113

EtaLasquera

Client
Joined
Jan 2, 2017
Messages
524
Reaction score
112
Points
43
To work with excel an turn it in numbers you must use excel interop with c# code to convert that columns from text to numbers.
 

cherubin

Client
Joined
Jun 6, 2016
Messages
92
Reaction score
6
Points
8
Hi,

So how to do that ? I never use C# module/code.
I just need to put the following code :
Code:
Convert.ToInt32(project.Variables["{-Var.Name-}"].Value);
in c# and then record in excel ?
 

EtaLasquera

Client
Joined
Jan 2, 2017
Messages
524
Reaction score
112
Points
43
int i = int.Parse(project.Variables["vari"].value;
int j = int.Parse(project.Variables["varj"].value;
int k = i * j;
project.Variables["vark"].Value = k.ToString();
 

Users Who Are Viewing This Thread (Total: 1, Members: 0, Guests: 1)