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

bluescharp

Client
Регистрация
20.06.2012
Сообщения
35
Благодарностей
1
Баллы
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
Регистрация
09.02.2011
Сообщения
1 216
Благодарностей
683
Баллы
113
Convert.ToInt32(project.Variables["heartbeat"].Value);
 

lokiys

Moderator
Регистрация
01.02.2012
Сообщения
4 771
Благодарностей
1 184
Баллы
113
JavaScript:
string cSharpVariable = project.Variables["heartbeat"].Value;
int numeric = Convert.ToInt32(cSharpVariable);
return numeric;
 
Последнее редактирование:

cherubin

Client
Регистрация
06.06.2016
Сообщения
92
Благодарностей
6
Баллы
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
Регистрация
02.01.2017
Сообщения
524
Благодарностей
112
Баллы
43

cherubin

Client
Регистрация
06.06.2016
Сообщения
92
Благодарностей
6
Баллы
8

lokiys

Moderator
Регистрация
01.02.2012
Сообщения
4 771
Благодарностей
1 184
Баллы
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
Регистрация
06.06.2016
Сообщения
92
Благодарностей
6
Баллы
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 :

Код:
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
Регистрация
06.06.2016
Сообщения
92
Благодарностей
6
Баллы
8
So no idea @lokiys for my issue ?
 

lokiys

Moderator
Регистрация
01.02.2012
Сообщения
4 771
Благодарностей
1 184
Баллы
113

EtaLasquera

Client
Регистрация
02.01.2017
Сообщения
524
Благодарностей
112
Баллы
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
Регистрация
06.06.2016
Сообщения
92
Благодарностей
6
Баллы
8
Hi,

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

EtaLasquera

Client
Регистрация
02.01.2017
Сообщения
524
Благодарностей
112
Баллы
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();
 

Кто просматривает тему: (Всего: 1, Пользователи: 0, Гости: 1)