Upconverting project from QB64, having issues...

New to FreeBASIC? Post your questions here.
Post Reply
dustinian
Posts: 14
Joined: Nov 12, 2005 5:02

Upconverting project from QB64, having issues...

Post by dustinian »

I've built a scripting language to help me transform text files, but I built it in QB64.I'm upconverting to FreeBASIC, and I'm running into compiler errors I don't understand. I have a version that compiles correctly in QB64, but I've modified the version I'm posting to deal with the compiler errors that I understood. Now I'm down to the compiler errors that I don't understand...

I'm not asking anyone to do any work for me, but some guidance on the errors would be very helpful. I want to do all the actual coding myself so I learn FreeBASIC.

If it helps, here are the errors (courtesy of fbedit):

Code: Select all

C:\Users\dcamburi\Documents\_Personal\projects\Text Transformation Language\string array.bi(72) error 40: Variable not declared, Remove_Word in 'Remove_Word(Array_of_Strings(), intElement)'
C:\Users\dcamburi\Documents\_Personal\projects\Text Transformation Language\string manipulation.bi(200) error 40: Variable not declared, Replace in 'strSubString = Replace(strSubString, Find, Add)'
C:\Users\dcamburi\Documents\_Personal\projects\Text Transformation Language\text file input output.bi(42) error 40: Variable not declared, FileExists in 'If FileExists(Path) THEN'
FbTemp.bas(66) error 4: Duplicated definition in 'Declare SUB Remove_Blank_Words (Array_of_Strings() As String)'
FbTemp.bas(67) error 4: Duplicated definition in 'Declare Sub Remove_Word(Array_of_Strings() As String, Index As Integer)'
FbTemp.bas(68) error 4: Duplicated definition in 'Declare SUB Seperate_Lines (Array_of_Strings() As String, Text As String, Seperator As String)'
FbTemp.bas(69) error 4: Duplicated definition in 'Declare FUNCTION Replace_From (Text As String, Precedant As String, Antecedant As String, Add As String) As String'
FbTemp.bas(70) error 4: Duplicated definition in 'Declare FUNCTION Replace_Between (Text As String, Precedant As String, Antecedant As String, Add As String) As String'
FbTemp.bas(71) error 4: Duplicated definition in 'Declare FUNCTION Replace_Subsequent (Text As String, Precedant As String, Find As String, Add As String) As String'
FbTemp.bas(72) error 4: Duplicated definition in 'Declare FUNCTION Replace_If_Between (Text As String, Precedant As String, Antecedant As String, Find As String, Add As String) As String'
Note that the errors I don't understand seem to revolve around my custom .BI files...

Thanks in advance for any help anyone can offer, I apologize if there's already an FAQ topic that deals with those errors. I've googled them with no success...
counting_pine
Site Admin
Posts: 6323
Joined: Jul 05, 2005 17:32
Location: Manchester, Lancs

Re: Upconverting project from QB64, having issues...

Post by counting_pine »

You seem to have quite an unconventional organisation of files.
I can see that in the .bi header files you have defined functions (i.e. written their implementations), and then you have declared them in your main module.
Usually the .bi headers are supposed to contain just declarations, and then the implementations appear in separate .bas modules. Then you have to compile them all at once, either on the command line (eg fbc module1.bas module2.bas ...) or FbEdit should be able to do that automatically.

(Note: if you only compile one at a time you may get linker errors, where functions defined in other modules can't be located, but no compiler errors as long as the module is valid.)

Some people unconventionally put implementations in included .bi files, which means only one file needs to be compiled. This can save some headaches but cause others.
This is what you've done, but the problem is, you include these files, then afterwards you declare the functions in them. This is unnecessary because implementing the functions automatically declares them if necessary, so you're declaring them twice.
e.g.

Code: Select all

sub foo()
  ' ...
end sub

'.....

declare sub foo() ' duplicated definition
If you're going to implement functions in .bi files, then don't declare them as well. At least not afterwards, but maybe before if necessary.


There are some functions you do need to declare, and those are the ones in the main module. They need to be declared before they are called, or the file needs to be rearranged so they are implemented before they are called. (The main procedure can go anywhere in the file, and for short programs it's common to try and avoid declarations by writing it at the end of the file.)


To fix most of your errors, you just need to know that "duplicated definition" probably means you're declaring a function after implementing it, and "array not dimensioned" probably means you haven't declared/implemented a function before calling it, and the function looks, syntactically, like it might be an array.

In lang qb, the other thing "array not dimensioned" might mean, is that you're trying to use a string function keyword like chr(), but in lang qb a '$' is always required, e.g. chr$().

Also, in your case, "duplicate definition" might mean that you've previously dimmed an array name as a single variable.
e.g.

Code: Select all

Dim strScriptText As String
'...
ReDim strScriptText(0) As String '' duplicated definition
The solutions to this are to remove the faulty Dim, or if - like me - you cringe at using Redim to declare an array, you can fix the Dim to make it an array declaration by adding '()' after the name. And then you can make it clearer that the Redim is a resize, by removing the type information after it:

Code: Select all

Dim strScriptText() As String
'...
ReDim strScriptText(0 to 0)
(The "0 to" on the Redim is optional, but prevents it looking like a C array declaration, which behaves differently.)
dustinian
Posts: 14
Joined: Nov 12, 2005 5:02

Re: Upconverting project from QB64, having issues...

Post by dustinian »

counting_pine, thank you very much! That's extremely helpful. In QB64, there's no true "module" or "class" concept. A $Include meta-command just adds the code from your "module" to the main file before compilation. So I wasn't 100% clear on ".BI" files in FreeBASIC. Your explanation helps a lot.

And I'll look at the dynamic arrays. I had to do some funny things there to get it to compile in QB64 as well.

Working on it now. Thanks!
petan
Posts: 683
Joined: Feb 16, 2010 15:34
Location: Europe
Contact:

Re: Upconverting project from QB64, having issues...

Post by petan »

Looks like wrong code structure. I had also such ;D
see this topics, maybe you 'll find some advices here
http://www.freebasic.net/forum/viewtopi ... =7&t=12654
http://www.freebasic.net/forum/viewtopi ... =2&t=19861
http://www.freebasic.net/forum/viewtopi ... =3&t=19932

Pete
dustinian
Posts: 14
Joined: Nov 12, 2005 5:02

Re: Upconverting project from QB64, having issues...

Post by dustinian »

HOT DOG! It compiled, and it works! Up-convert complete!

If anyone wants to play with it: https://skydrive.live.com/redir?resid=2 ... ake1RCub58

I added a sample script and a sample input file to the .ZIP file. Just compile the code, then run the .EXE with the following command-line arguments (in a CMD window or something)...

Code: Select all

Text Transformation Language.exe script.ttl, input.txt, output.html
Note: The .EXE must be in the same folder as the script and input files, or you'll have to enter full paths (i.e. C:\script.ttl, C:\input.txt, C:\output.html)

TTL will then create the output.html file by running the script file on the input file.

Thanks again, counting_pine, your post got me marching down the right path!
Post Reply