How to Work with Templates

Everything else that doesn't fall into one of the other PB categories.
oldefoxx
Enthusiast
Enthusiast
Posts: 532
Joined: Fri Jul 25, 2003 11:24 pm

How to Work with Templates

Post by oldefoxx »

I understand the concept of templates, in that you can use them as
starting points for yet another project or file, and you hold the
basics of what you intend to do or what you want to start with and
just go from there.

I believe I have it down that the PBI extension is used to identify
which files are templates, and that you have several PREFS files
under %APPDATA%\PureBasic\ where settings are stored, first for
PureBasic (PureBasic.prefs), Templates (Templates.prefs) and
Tools (Tools.prefs). However, on my setup, I am missing
Tools.prefs, and the Templates.prefs file only has 17 bytes in it.
If I look at Tools/Templates in the IDE, it is a blank.

How do I move on to the next stage, of having Template files
recognized and show up in the IDE as Template files? I read
that if you call the compiler with /T <template file> on the
command line, that the compiler can treat with this type of
file, but I don't know what it will do it, and from Windows,
you don't usually have command line parameters to pass on
that way (unless you add them under Properties in a desktop
shortcut).

I've tried to research this online and in the forums, but I find
no real discussion or answers related to Templates. Maybe
somebody can fill in some of the blanks here. It would be
appreciated. Oh, as an addition, I did find and download what
is referred to as the PureBasic Standard Template Library. That
you can find online at several places.
has-been wanna-be (You may not agree with what I say, but it will make you think).
User avatar
Josh
Addict
Addict
Posts: 1183
Joined: Sat Feb 13, 2010 3:45 pm

Re: How to Work with Templates

Post by Josh »

And whats the coding question? You are here in PureBasic » Coding Questions !!!
sorry for my bad english
User avatar
luis
Addict
Addict
Posts: 3895
Joined: Wed Aug 31, 2005 11:09 pm
Location: Italy

Re: How to Work with Templates

Post by luis »

.PBI stands for PB include. It has nothing to do with templates. You can store what you like into it, usually the idea it's to use it for constants, var definitions, etc. but you can use it as you like.

It's like the .h for C.

oldefoxx wrote: How do I move on to the next stage, of having Template files
recognized and show up in the IDE as Template files?
You use the template tool in the ide to store snippets of code in a tree-like structure, then you select the one you are interested in and paste it back into the currently open source file.
That data it's stored inside the Templates.prefs file you saw in a simple text based format.
oldefoxx wrote: I read that if you call the compiler with /T <template file> on the
command line
That's not the compiler, it's the IDE.
I suppose that option (never tried it) it's to select a different file instead of the default "Templates.prefs". For example if want more than one set of templates.
"Have you tried turning it off and on again ?"
oldefoxx
Enthusiast
Enthusiast
Posts: 532
Joined: Fri Jul 25, 2003 11:24 pm

Re: How to Work with Templates

Post by oldefoxx »

luis wrote:
oldefoxx wrote: How do I move on to the next stage, of having Template files
recognized and show up in the IDE as Template files?
You use the template tool in the ide to store snippets of code in a tree-like structure, then you select the one you are interested in and paste it back into the currently open source file.
That data it's stored inside the Templates.prefs file you saw in a simple text based format.
oldefoxx wrote: I read that if you call the compiler with /T <template file> on the
command line
That's not the compiler, it's the IDE.
I suppose that option (never tried it) it's to select a different file instead of the default "Templates.prefs". For example if want more than one set of templates.
I read the above, and still felt loss. Compiler or IDE, it's still a command
line argument. The problem with messing with shortcuts and adding any
arguments is that they stick there, and you have to keep editing the
shortcut or create multiple shortcuts that pass different things.

But I decided to take another look at Tools/Templates to see what I was
somehow missing, and tried the little buttons on the bottom of the top
bar where Templates came up on the right side. They are small and so
light in color that I had the mistaken notion that they were grayed out.
Not so. You click on the one on the left, and it opens a dialog box and
wants you to enter the Template name. I didn't have any templates yet,
but I wanted to start one, so I entered "Begin". When I hit Enter, I got
a different dialog box, this with two panes in it. The top, larger pane
asked me to enter Code at that point. I did a copy and paste of the code
wanted to go in there. The bottom was for any comments I wanted to add.
I skipped on that. Then I clicked on Save. Immediately a Begin showed up
as the beginning part of a tree structure on the right.

Double-cick on Begin, and the code gets inserted into your source code on
the left. I tried this again, but using More for the file name, and then instead
of Save, I hit Cancel. It appeared on the right in the tree anyway. But I found
that with the right mouse button, I could delete it. You can also use the third
button for this purpose. The second button lets you edit the selected template.

The fourth button lets you select a different directory for your templates.
The fifth button is a mystery to me, as there is no popup note to say what
it does. I tried using it, but didn't see any effect.

The sixth and seventh buttons are for working up and down the Template tree.
Not sure there is any real need for them, because it takes a mouse to make use
of them, and the mouse alone lets you work up and down the tree. May be
different if you have to deal with branches as well.

Oh, as to what I think I will use for my Begin template, I decided to start out with
this: I haven't made use of it yet, so it hasn't been tested, but my thinking tells
me I am on the right track in how rinstr() should work:

Code: Select all

EnableExplicit
Global a.l, b.l, c.l, d.l, e.l, f.l, g.l, h.l, i.l
Global aa.s, bb.s, cc.s, DD.s, ee.s ff.s, gg.s

Procedure.l rinstr(ofs.l, str1.s, str2.s)
  Protected a.l, b.l
  If ofs<1 Or ofs>Len(str1) 
    a=Len(str1)+1
  Else
    a=ofs
  EndIf
  a-Len(str2)
  If a>0
    For b=a To 1 Step -1
      If Mid(str1,b,Len(str2))=str2
        ProcedureReturn b
      EndIf
    Next
  EndIf
  ProcedureReturn 0
EndProcedure
        
Note that I am trying to allow for the full length of str2 as to where to start.
On the technical side, Instr() could also allow for the full length of its 2nd
string as to where to stop its search in the 1st string. It may actually do
that, at least in some implementations, but then again, how do you know?

Some implementations of Instr() also ignore the case of the letters. These
are not as fast as the others, but save you from having to have both strings
set to the same case before the search is conducted.

Since the Tools/Template feature works as it does, you might make good
use of it by creating templates that divide up specific tasks in their own
unique way. You could have a Files template, a TCP/IP template, a UDP
template, a Console template, a generic GUI template, a generic Sort
template, and so on.

So how do templates differ from Include files that you could also use?
Well, the template is going to actually become a part of your source
code, subject to whatever changes and additions you make for its use
here, and Include files are possibly shared between multiple source files
(at least eventually).

So once you have an Include file, you can't do much to change what is in
it, although you might add to it later. And they do not appear as part of
the current program while it is in the Editor. Templates are for this time
use if you select one or more, are actually added to the source code
while it is in the Editor. And if you decide to alter a template, it does
not effect programs that used the same template earlier. Changing an
Include file does not change the compiled versions either, but may have
a big impact if you try to recompile them in the future.

That all said (and I hope it serves to help some others out there that may
not have understood Templates under PureBasic either), I am still unclear
on where the Begin and More files or snippets are placed. I looked in the
%APPDATA%\PureBasic\Templates.prefs file, and there is still nothing in
there except what it started with. Where did Begin and More templates go?
Last edited by oldefoxx on Thu Oct 11, 2012 5:52 pm, edited 1 time in total.
has-been wanna-be (You may not agree with what I say, but it will make you think).
User avatar
Josh
Addict
Addict
Posts: 1183
Joined: Sat Feb 13, 2010 3:45 pm

Re: How to Work with Templates

Post by Josh »

@all Mods

How long will PB offer this old spammer place for his blogs. Nobody needs this confused statements. I don't think, that this board is a place of therapy for people diseased on senile dementia.

On other places oldefoxx wrote, he's starting to write his first pb program. Having a look to his blog above, specially to this absurde code, its clear:

After 386 postings and being member on this board over 9 years, he really never wrote any pb program and after this long period he isn't able to handle the ide for testing his code.

So, please kick this troll finally from the board. It doesn't make sense to show him the yellow card, latest one week later he has forgotten again.
sorry for my bad english
oldefoxx
Enthusiast
Enthusiast
Posts: 532
Joined: Fri Jul 25, 2003 11:24 pm

Re: How to Work with Templates

Post by oldefoxx »

Well Josh, you set out to find out anything about PureBasic and the use of
Templates and see what you turn up. I searched the internet and the help
files, and came up with blanks. Maybe you know all about them to start with.

Then you work out how to explain what you've learned or know so that
others have the benefit of your knowledge or experience. Had you done
that before, or had anyone else done it, I might have found your postings
and that would have saved me both time and effort, plus some mistakes.

Nine years you said? I haven't been counting. I've been involved in a lot of
things in that time, and quite frankly programming was nowhere near the
top of my list, especially having to drop things and focus on a new language
that was quite different from my prior experience.

To me, you are just blowing the same old tune, making no allowances for the
fact that I was steering the subject to a gap in the documentation that
becomes apparent when you look for answers and can't find them. .
has-been wanna-be (You may not agree with what I say, but it will make you think).
rsts
Addict
Addict
Posts: 2736
Joined: Wed Aug 24, 2005 8:39 am
Location: Southwest OH - USA

Re: How to Work with Templates

Post by rsts »

Josh wrote:@all Mods

So, please kick this troll finally from the board. It doesn't make sense to show him the yellow card, latest one week later he has forgotten again.
This is sounding like a personal vendetta.
Use your foes list. Live and let live.
User avatar
Demivec
Addict
Addict
Posts: 4283
Joined: Mon Jul 25, 2005 3:51 pm
Location: Utah, USA

Re: How to Work with Templates

Post by Demivec »

Josh wrote:@all Mods

How long will PB offer this old spammer place for his blogs. Nobody needs this confused statements. I don't think, that this board is a place of therapy for people diseased on senile dementia.

On other places oldefoxx wrote, he's starting to write his first pb program. Having a look to his blog above, specially to this absurde code, its clear:

After 386 postings and being member on this board over 9 years, he really never wrote any pb program and after this long period he isn't able to handle the ide for testing his code.

So, please kick this troll finally from the board. It doesn't make sense to show him the yellow card, latest one week later he has forgotten again.
@Josh: Why are you trolling oldefoxx's threads and spamming them? Why don't you go start a blog and write about all the things you hate in your new blog. Stop filling up the forum with your antagonistic postings.

From your forum membership it seems you've only been around here for maybe 2 years, if you want to look up some confusing posts from a member that still posts here then look up some by Kwaï chang caïne. Those posts will make your head spin. The older the post the more your head will spin. :)


@oldefoxx: Josh is right when he says this is the wrong forum for this topic, I think it belongs in 'The PureBasic Editor' because it doesn't actually relate to coding at all but on using a feature of PureBasic's IDE.
User avatar
skywalk
Addict
Addict
Posts: 4318
Joined: Wed Dec 23, 2009 10:14 pm
Location: Boston, MA

Re: How to Work with Templates

Post by skywalk »

I have to say I look forward to all of Kwaï chang caïne's posts. :D
He is beyond witty and a wizard of GIF's.

Josh, when I come across people who struggle, I think of the saying, "There but for the grace of God, go I."
Humility is the way to go here. :wink:
The nice thing about standards is there are so many to choose from. ~ Andrew Tanenbaum
BorisTheOld
Enthusiast
Enthusiast
Posts: 542
Joined: Tue Apr 24, 2012 5:08 pm
Location: Ontario, Canada

Re: How to Work with Templates

Post by BorisTheOld »

@skywalk

I agree.

These forums are not particularly well organized and there are significant opportunities for anyone to post in the "wrong" forum. But does it really matter?

No one here can claim to know everything. So it saddens me when I read some of the closed-minded and immature rubbish that's posted in these forums. It would be much more helpful to everyone if the arrogant ones among us just kept their opinions to themselves.
For ten years Caesar ruled with an iron hand, then with a wooden foot, and finally with a piece of string.
~ Spike Milligan
User avatar
luis
Addict
Addict
Posts: 3895
Joined: Wed Aug 31, 2005 11:09 pm
Location: Italy

Re: How to Work with Templates

Post by luis »

oldefoxx wrote: I am still unclear on where the Begin and More files or snippets are placed. I looked in the
%APPDATA%\PureBasic\Templates.prefs file, and there is still nothing in
there except what it started with. Where did Begin and More templates go?
In a normal installation the .prefs file should be there (depending on the OS). On my Win7 x64 the file is under

C:\Users\luis\AppData\Roaming\PureBasic\Templates.prefs

If you used some of the optional switch for the IDE to make the installation portable, it can be in the installation directory.

You can simply do a search for Templates.prefs from the root of your disk.
"Have you tried turning it off and on again ?"
oldefoxx
Enthusiast
Enthusiast
Posts: 532
Joined: Fri Jul 25, 2003 11:24 pm

Re: How to Work with Templates

Post by oldefoxx »

my thanks and appreciation to the several that have defended my
right to express myself here. As to which group this thread belongs
in, I began in the PureBasic Editor section and it got moved here by
the Moderator. As stated, the lines between where a thread belogs
becomes blurred when it could actually fit several places, depending
on how many strands are in it.

I did go back and correct my code posting for my Begin code. Turned
out to be harder than expected. When I first wrote it into the thread,
I was trying to put the wraps on a long day, report what I had worked
out for myself, and pose my next question to see if I got answers on
waking up. So I blundered.

Thing is though, is that after making three Templates, they disappear
when I bring up the IDE again. I just tried the same thing, and this is
all that is in the %APPDATA%\PureBasic\Templates.prefs file:
TEMPLATES:1.0

Must be a hole in there. So Templates is not working on my end. What
should I look for or do next?

Oh, and with Templates, you cannot do a Paste with Ctrl+V. You have to
use the right mouse button and select Paste.
has-been wanna-be (You may not agree with what I say, but it will make you think).
User avatar
Primoz128
Enthusiast
Enthusiast
Posts: 212
Joined: Sat Sep 10, 2011 8:25 pm
Location: Slovenia

Re: How to Work with Templates

Post by Primoz128 »

God i hate this SQUARE - BLOCK kind of making sentence making...
oldefoxx
Enthusiast
Enthusiast
Posts: 532
Joined: Fri Jul 25, 2003 11:24 pm

Re: How to Work with Templates

Post by oldefoxx »

Especially when the original square block does not have the same
dimensions as the displayed square block, right? So I purposely try
to stay withing the scope of both, and am willing to error on the
narrow side if it means I do not have to go back and juggle words
to make it all fit, line by line. I just look at it as being a kind of
column typing rather than full width typing. Blame the software,
not the typist. Of course if this was the only place I posted, things
might be different.

However, to prove a point, I will let this line go all the way around. I am spending less time here as I now have two groups on Yahoo that I post to. But enough said on that. I did get one private message asking for the names of the two groups, and I was glad to provide them, but I haven't gotten a reaction yet, so the voting is still out on them.

Oh, to get back on topic, I posted a separate short thread concerning not being able to save my new templates.
I got several replies, one said it worked for him, I tried it again, and now it works. Go figure.
has-been wanna-be (You may not agree with what I say, but it will make you think).
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5709
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Re: How to Work with Templates

Post by Kwai chang caine »

Demivec wrote:if you want to look up some confusing posts from a member that still posts here then look up some by Kwaï chang caïne. Those posts will make your head spin. The older the post the more your head will spin.
SkyWalk wrote:I have to say I look forward to all of Kwaï chang caïne's posts.
He is beyond witty and a wizard of GIF's.
Me ????? special ???? i don't know what you want to say ???? no no...really any idea :mrgreen:

I'm happy to see i have again some MASTERS friends in this forum 8)
The live is too short for never laugh....and it's possible to talk to serious things with humor...so it's my advice :oops:
The humor is the better bridge between two persons...even foreign :D

So thanks a lot at you two, for this kind sentence for KCC 8)
I'm your servant :wink:

It's my dream of someone talk to GIF, even perhaps to UseGIFImageDecoder() ??? :shock:
Image

Sorry FRED a little bit of manifestation, in case or you have forgotten this library for the PB v10.50 :lol:
Image
ImageThe happiness is a road...
Not a destination

PureBasic French Forum
Post Reply