#include "crt.bi" 'remember that you use .bi files Print "Howdy peeps" + Chr(13) + Chr(10) '\n\r should be \r\n (a DOS ASM programmer could tell you that) printf( " :-P" ) 'no semicolons at the end of statements in BASIC (PRINT is an exception) While( 1 = 1) 'whether it is for comparisons or assignments, only one = sign is required ' do not need braces since you always have some form of STATEMENT...END STATEMENT in BASIC If 1 = 1 Then Print "Howdy"; ElseIf( 1 <> 2 ) printf( "No way!" ) End If Wend 'changed closing brace to Wend The one thing that hasn't changed as far as FB's transformation to C is the old operators. They simply added new operators: &= (some_string &= 2 is equivalent to some_string = some_string + Str(2), idea from VB maybe?) += (some_string += 2 doesn't work, some_string += new_string works, some_numeric += new_numeric works) -= (some_numeric = some_numeric - new_numeric) *= (some_numeric = some_numeric * new_numeric) /= (some numeric = some_numeric / new_numeric; this will perform an arithmetic division operation) \= (some numeric = some_numeric \ new_numeric; this will perform an integer division operation) ^= (some_numeric = some_numeric ^ new_numeric; raise some_numeric to the new_numeric power) MOD= (some_numeric = some_numeric MOD new_numeric) AND=, EQV=, IMP=, OR=, XOR=, SHL= and SHR= function in a similar fashion SHL ("x SHL n" is "x << n" in C) SHR ("x SHR n" is "x >> n" in C) & (some_string = other_string & some_numeric would do some_string = other_string + Str(some_numeric) ) [] (pointer indexing shortcut: "x[i]" is the same as "*(x + i)", string indexing (ASCIIZ, for example) @ (address-of operator, probably implemented for use with pointers originally, returns memory address of its operand) * (pointer dereference operator) . (not comparable to C as far as I can tell, but it reminds me a bit of inheritance in C++) -> (think pointers or structs, classes or something like that...) NEW, DELETE (both function just like in C++ - allocates/deallocates memory and destroys contents of memory when deallocating) ** there are some preprocessor operators too, but i don't know how they work since i've never used them in C ** Anyway, that was fun converting that C program to FB. Let's convert it back... #include <stdio.h> // there is no crt.h afaik int main (void) // explicit main module, unlike BASIC { printf("Howdy peeps\r\n"); // there is no generic "print" function or statement, can't forget semicolons printf( " :-P" ); while( 1 == 1) { if (1 == 1) print "Howdy"; else if( 1 != 2 ) printf( "No way!" ); // no need for braces because there is only one statement within the scope of the if statement } // End while return 0; // program exited without any errors } // End program |
Newbies usually go to www.qbasic.com and click on
The QBasic Forum
Forum regulars have their own ways, which include
The QBasic Community Forums