Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Strange results in FB with PRINT USING.
#21
In the next FB release, there's a FORMAT$(num#, mask$) implementation available as soon as you include "vbcompat.bi".

This should be a bit more flexible and supports internationalized numbers, date, times, month- and weekday names.

Regards,
Mark
Reply
#22
Quote:In the next FB release, there's a FORMAT$(num#, mask$) implementation available as soon as you include "vbcompat.bi".
Never used VB (meaning I haven't used the Format function), but it looks like a nice alternative to USING.
974277320612072617420666C61696C21 (Hexadecimal for those who don't know)
Reply
#23
Format$ is great. I used it all the time when I did professional VB work. This will be a great addition to FB.
Reply
#24
I'm not sure why PRINT USING is considered such an antiquated and obsolete command. It is the ONLY way to print formatted text so that it lines up the way you want it in Basic, and it is probably the single most useful and important command in any text game.

Printf and Sprintf are meaningles to me, because I have no idea what crt.bi is or what including it means.

Format$ looks equally unappealing, again because you have to "include" something called vbcompat.bi.

I have no idea what C source code or a runtime library is, since I'm just a QBasic programmer, period. So I have no idea how to "patch" anything.

For me, the beauty of BASIC is how useful and simple it is on its own, without any additional libraries, included files, or patches. FreeBasic's largest appeal will probably be to those migrating directly from QBasic to a version that is more Windows compatible, so personally I think that 100% backward/identical compatibility with the "parent version" is absolutely critical. You can add plenty more features, functions and commands, but all the things that are already there from QBasic should work absolutely identically. Legacy code from QB should be able to be copied and pasted in with two clicks and run flawlessly.

I'd love to be able to be one of the guys helping to contribute to that process, but unfortunately I don't know anything about C, so you really don't want me bumbling around in those source code files.
Reply
#25
BI files are called "header" files, they contain a bunch of function declarations that let you use libraries. You simply do this:

#include "myheader.bi"

and it will load that file, and you can then use all the functions it contains. Pretty simple, huh?

crt.bi contains functions from a library called "libc", or C's runtime library (C Runtime Library, "CRT"). FreeBASIC itself would not be possible without this library. Two functions in the library are "printf" and "sprintf", which are used to print formatted text to a console, or copy formatted text to a string.

PRINT USING is printf's equivalent in QBasic. It's not necessarily antiquated, it's just not well maintained. According to the v1ctor in a separate thread, he just coded it by observation, and didn't spend a whole lot of time on it. But it will probably be improved in the next version, some of the other authors are looking at it.

Printf, however, is exactly the same function as it is in C, it doesn't have to be rewritten or modified to work in FreeBASIC. So by doing this:
Code:
#include "crt.bi"
Dim As Double x = 41014.5352512
PrintF "Output: %.2f", x
Sleep

It will format the number "x" out to two decimal places, printing this: "Output: 41014.54"

There is a formatting reference here:
http://www.cplusplus.com/ref/cstdio/printf.html

It's meant for C++, but the formatting of the string is the same. Of course, if you'd rather use PRINT USING it's still partially implemented, just not completely yet.
Reply
#26
Thanks, I guess including a file is indeed pretty simple after all. Out of curiosity do you have to distribute those files alongside the compiled EXE for it to work, or are they dynamically included in the compilation?

My problem unfortunately, is that I already have a pre-existing, huge QBasic program that I'm migrating (over 400k, which I consider large by QB standards) that has the PRINT USING command peppered all throughout it, and a simple search-and-replace with PRINTF won't work of course since the formatting is unique for each command, as well as the fact that I use different formatting in various places throughout the program.

I guess I'll just have to wait for the next version with the fix to come out.
Reply
#27
That you will. There's an unstable release coming out soon, maybe there will be improvements to PRINT USING in that.

It depends on the library used. FreeBASIC includes "static libraries", like any compiler. These static libraries can either include the library code itself, such as the FreeBASIC runtime library, or it can include code that links to a "dynamic library", contained in a .dll file, such as the Windows API, or SDL.

If you use a library that requires a DLL to be packaged, your program will pop a messagebox up saying that the required file could not be found, and then end.
Reply
#28
Bring on version 0.15 then I say....

I must also say that I object on rational, philosophical, religous, and purely visceral levels to any external files ever needing to be distributed with any EXE Program file. Final and Most Holy Compiled Programs must be completely self-sufficient, self-contained, and self-reliant, so that if the user was stuck on a desert island with nothing but that one EXE file on a floppy disk, an antique abacus, and a 1960's gas generator, he could run the darn thing just fine.

My programs do refer to external files during runtime, but those are just Random files that it checks for and tries to find at startup, and if it doesn't find them, it creates them from scratch. So it can never be accidetnally "stranded" without them, if someone copies the EXE but forgets the extras.
Reply
#29
...Well, in that case I would only use static libraries.
Reply
#30
Let me ask a really basic question. If I have a LIB file, like DSOCKQB.LIB, how do I link that to my program? Do I just use:

'$Include dsockqb.lib

? Or is there adifferent method?
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)