FOPEN/READSTRING Oddities
Probably missing something stupid here, but here goes.
Looking through the help file, when pasting the sample code from FOPEN and READSTRING, I either get an access violation on the PC, or on the PPC, it displays it, but several letters at the end get chopped off or otherwise mangled.
Is it also possible to provide no path when opening the file to read or write, and have it look for the file in whatever directory is currently in? I've had no luck with that yet.
I will make a little test program for you tomorrow and I will make sure the readstring works fine. I will give you the code as an example. I don't think the ReadString() function is working properly, PointOfLight mentionned it to me a couple times if I remember correctly. I should have all this fixed with the next pre-release build.
As for looking for a file, do you want the user to select a file to open? Or do you want to scan the directory for files it find inside?
I'm going to be parsing a config file in this format:
[Setup]
SetupVersion = "1.3D"
[Engine Setup]
UsingGapi = 1
Platform_Timer_HZ = 100
LandscapeMode = 0
CacheMemory = 2600
ShowFPS = 1
TickRate = 100
TicksPerFrame = 26
ScanCodeMapping = 1
The way I was thinking about handling it was just for each line, use a regex and set variables with the name of what's to the left, with the value of what's to the right, and then put the values in a form.
$10 says I'm doing it in a horrible messy and overly complex way ;)
You could also do the following:
s$ = loadstr("\\MyDocuments\\config.txt");
lines$ = strtolist(s$, #13#10);
ForEach(lines$)
s$ = lines$;
if (s$[0] == '[')
// do something here
else if (s$ <> "")
f$ = strtolist(s$, "=");
// do something here
end;
end;
That is one way but I think the best way is to use ini file routines.
I will add these routines to a library file tomorrow and incorporate it into the next pre-release, I will give you an example also.
Yet another question (geez at this rate I'll probably have no code on my own by the end of this :P)
How do I use variables as the text in an editbox? In eVB I'd set it just with a form1.editbox.label == varible, do I do something similar in PPL?
In PPL you work with an HWND (int) handle. Every control and windows have their own unique handle. When PPL (Visual Form Builder) creates it's windows or controls it uses the same handle.
The handle variable name is always the same as the name you give your control in the visual form builder + an $ at the end. Ex: If you have a label named MyLabel in the Visual Form Builder you will set it's caption with the following line of code:
SetWindowText(MyLabel$, "Text");
or
SetWindowText(MyLabel$, Variable$);
SetWindowText works for a lot of controls and the window's title bar as well.
Check
http://www.msdn.com for technical reference. PPL uses pretty much the same functions for API as C would.
Heh, answerred my next question too. Didn't think MSDN would be applicable, but then again this is the closest I've gotten to any C-like language. Thanks again!
No problem. Keep them coming. We all started somewhere one day and we all need help at one point or another.
Got that code working somewhat - the full line appears in the textbox, however there's a large lag between launch and when the textboxes fill out. Is this due to the speed of the runtime or just the code?
Sponge, MSDN is your friend. Make MSDN your friend. I used it quite extensively when I was putting together the ListView_lib.ppl and TreeView_lib.ppl libraries (which I believe are both included in the distribution now). Even though the syntax on everything might not always be identical, it is usally pretty close.
Kornalius, I know the INI stuff isn't difficult, but if you don't have time to throw together a demo, I could do that for you. Let me know if you need a hand.
Be my guess. Can you do the library too? Should be a matter of a couple minutes to an hour, depending on the difficulty of the ini files functions.
I'll see what I can do. Sometimes work is a bit slow for me and I can squeeze things in, but I'm not sure today is going to be such a day. I'll keep you posted.
Don't worry about it if you don't have the time, I will do it.
I just looked up some of the INI functions on MSDN, and I can't seem to find any listings for PocketPC versions of said functions. Are you sure these functions are supported on the PocketPC? If not, I could write a library that simulates said functions. Let me know if you've found anything that indicates differently about these functions being available on the PPC.
Yeah, it doesn't look like the GetProfileString() function will work on WCE.
If you want to write a library to simulate the functions for INI files, it would be awesome.
If you want could you add these functions to it:
list$ = OpenINIFile (filename);
WriteINIChanges(filename, list);
ReadString (list, section, key, default)
ReadInteger
ReadFloat
WriteString
WriteInteger
WriteFloat
EraseSection ; erase an entire section
SectionExists ; if a section exists
Sections ; to get a list of all sections
You can probably load the file to a string and then convert it to a list, do all work on the list and then WriteINIChanges would save the list back to the file. Just an idea.
kornalius: Any word on why the same code fails on the desktop with an access violation when trying to open files with both absolute and relative paths?
i will get on the ini file project. It should actually be kind of fun

sponge: How do you open the file? Show me the piece of code your are using.
Hm, the code you have uses loadstr, which seems to work on the PC. FOPEN doesn't work at all though no matter how i tried. I'll try and look into this a bit more
How do call the fopen() function? fopen is a little tricky you know.