Saving a string with more than 3 characters in a dataset

Posted By: VizTra

Saving a string with more than 3 characters in a dataset - 04/16/21 09:31

Hello,

I'd like to know, how to save a string in a dataset that is bigger than 3 characters.

What I've got so far:

Quote
dataNew(1, NumAssetsListed, 3);

string tickerString = dataStr(1, 0, 1);
strcpy(tickerString, "AAPL");

dataSet(1, 0, 2, 0.05);
dataSaveCSV(1, "f0,sss,f2,f3", "AppleMomentum.csv");


What I know so far is, that when importing a .csv you can select the format and in that case you can import the csv with a format contain "sss" to import strings bigger than 3 chars. But what about creating completeley new datasets within Zorro?
I create a dataset with dataNew() and then take the pointer to the string field via dataStr(), without being able to somewhere make sure the string can be bigger than 3 characters.

I'm probably missing something.

Kind regards,
Posted By: jcl

Re: Saving a string with more than 3 characters in a dataset - 04/16/21 14:51

You can store a string as long as you want, but you need to reserve one more field for any 4 more characters. Those fields then hold a part of the string and cannot contain numbers.
Posted By: damasceno

Re: Saving a string with more than 3 characters in a dataset - 06/17/21 19:16

Hi, I'm having a similar difficult.

I can include the string in the dataset but when I export to .csv the first column/row doesn't appear the strings. But if I add the string to another column and row its ok.

Adding to the first column [0]:

Quote

string FormatA = "sss,f,f,f";
function evaluate()
{

dataNew(2, 10, 4);
string statistic = dataStr(2, 0, 0);
strcpy(statistic, "testing");

watch("!i",dataStr(2,0,0));
dataSaveCSV(2,FormatA,"History\\test.csv");



.csv result ->" ,0.00000,0.00000,0.00000,0.00000,0.00000"

changing dataStr to dataStr(2,1,0) -> .csv first line result -> "0.00000,,0.00000,0.00000,0.00000,0.00000"

dataStr(2,1,1) -> .csv second line result -> "0.00000,testing,0.00000,0.00000,0.00000"

Is there a way to add strings to the first column/row, or I'm doing something wrong?

Thanks!
Posted By: Petra

Re: Saving a string with more than 3 characters in a dataset - 06/18/21 06:32

Your dataset has wrong number of fields. For 6 fields its dataNew(...6), not 4.
Posted By: damasceno

Re: Saving a string with more than 3 characters in a dataset - 06/18/21 18:16

Yes, I simulated with dataNew(...6) but copied the code with dataNew(...4) here, but the problem is the same
Posted By: Zheka

Re: Saving a string with more than 3 characters in a dataset - 06/18/21 20:38

"Every record begins with an 8-byte date/time field."

So, column [0] is treated as a double.
Posted By: damasceno

Re: Saving a string with more than 3 characters in a dataset - 06/20/21 03:40

Thanks Zheka!
© 2024 lite-C Forums