Gamestudio Links
Zorro Links
Newest Posts
Instrument Price Zorro Chart
by felixfx. 10/19/19 20:48
Today real live account blown - my experience
by Clifford_B. 10/19/19 17:09
Building Diversified Portfolios - New Paper
by SnoopySniff. 10/18/19 16:23
Indices & metals easier to trade than FX???
by SnoopySniff. 10/18/19 10:08
What are you working on?
by txesmi. 10/17/19 07:00
Ducascopy exporter
by line7. 10/17/19 06:21
AUM Magazine
Latest Screens
The Space Between
Pogostuck: Rage With Your Friends
Worst Case Z
AckCon'18 - Lotter vs the World 2 - Preview Release
Who's Online Now
5 registered members (AndrewAMD, felixfx, Dalla, painkiller, ugofx), 658 guests, and 0 spiders.
Key: Admin, Global Mod, Mod
Newest Members
VillageTalkies, line7, Shutch, Clifford_B, Paulius
18310 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
putstr, getstr (similar to putvar, getvar) #477718
07/24/19 18:36
07/24/19 18:36
Joined: Feb 2017
Posts: 772
Chicago
AndrewAMD Online OP
User
AndrewAMD  Online OP
User

Joined: Feb 2017
Posts: 772
Chicago
jcl,

Currently, Zorro has putvar and getvar, to get and set vars.

In the same vein, perhaps a similar pair of functions can be used to get and set strings. Maybe call them putstr and getstr.

Thanks,
Andrew

Re: putstr, getstr (similar to putvar, getvar) [Re: AndrewAMD] #477737
07/25/19 17:48
07/25/19 17:48
Joined: May 2018
Posts: 68
S
SBGuy Offline
Junior Member
SBGuy  Offline
Junior Member
S

Joined: May 2018
Posts: 68
I agree. putvar and getvar and poorly implemented, supposedly for speed. I can't even store a 8 digit int YYYYMMDD using putvar because the printf used to write it to text file has limited float resolution.

Now it goes into the Windows registry? - Oy vey! Who's bright idea that? All we need is more junk in the Windows registry.

Better to store as string and use a faster computer :-)

I had to write my own getstr and putstr. For what it's worth, here it is

Code

string mygetstr(string fName, string itemName)
{
	string content = file_content(fName);
	if (!content) return 0;
	
	string myitem = strtext(content,strf("%s,",itemName),"0");
	if (!myitem) return 0;
	
	return myitem;
	
}

int myputstr(string fName, string itemName, string newval)
{
	string content = file_content(fName);
	if (!content) return 0;

	if (strstr(content,strf("%s,",itemName)))	{
		string myitem = strtext(content,strf("%s,",itemName),"0");
		if (!myitem) return 0;
			
		string old2 = strf("%s,%s",itemName,myitem);
		string newval = strf("%s,%s",itemName,newval);
		
		content = strx(content,old2,newval);
		file_write(fName,content,0);
	}
	else			
		file_append(fName,strf("%s,%s\n",itemName,newval));
}

var mygetvar(string fName, string itemName){
	return (atof(mygetstr(fName, itemName)));
}

function myputvar(string fName, string itemName, var val) {
	myputstr(fName, itemName,strf("%.3f",val));
}


Re: putstr, getstr (similar to putvar, getvar) [Re: AndrewAMD] #478088
09/05/19 23:29
09/05/19 23:29
Joined: Jan 2019
Posts: 71
berlin
L
laz Offline
Junior Member
laz  Offline
Junior Member
L

Joined: Jan 2019
Posts: 71
berlin
Isn't it a problem, to use so many temporary strings?

Or to return 0 for return type string?

Re: putstr, getstr (similar to putvar, getvar) [Re: AndrewAMD] #478122
09/10/19 15:32
09/10/19 15:32
Joined: May 2018
Posts: 68
S
SBGuy Offline
Junior Member
SBGuy  Offline
Junior Member
S

Joined: May 2018
Posts: 68
Hi Iaz,

Thanks for the code review. I swore that a few Zorro versions again, I read that temp strings lose their content after something like 10 other temp string calls. But the latest manual in 2.18.1b says temp strings loose value immediately after another temp string call. Yikes! I better fix my code :-)

As for return 0 for string time, isn't that the same as a NULL string pointer?

Re: putstr, getstr (similar to putvar, getvar) [Re: AndrewAMD] #478172
09/17/19 13:29
09/17/19 13:29
Joined: Jul 2000
Posts: 27,029
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 27,029
Frankfurt
I can at least confirm that temp strings are recycled after 10 calls, not immediately. 0 is the same as NULL.


Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1