freeBASIC是去年新出的一个basic编译器,功能蛮强大的,当然还比不上VB,所以我一直在犹豫,在VB版发这样的贴子是否会让人笑话,为此我花了好几个月思考这个问题,哈哈!现在fbc的功能是越来越强大了的,能做很多VB做不了或很难做的事情,给大家看点代码眼谗一下吧。
'' hello.bas
'' hello world example
'' width 80, 25
view print 1 to 8
color 0, 7
cls view print 17 to 25
color , 7
cls locate 25,57
print "press any key to exit...";
view print 9 to 16
color 7, 1
cls
locate 13, 40 - (len( "Welcome to freeBASIC!" ) \ 2)
print "Welcome to ";
color 15
print "freeBASIC";
color 7
print "!"
sleep'' allocate.bas
'' dynamic memory allocation example
''Type sometype
x As Integer
y As Integer
End TypeDeclare Function somefunc() As sometype ptr Dim t as sometype, p as sometype ptr p = somefunc()
t = *p
print "x ="; p->x;
deallocate p
print " x ="; t.x t = *somefunc()
'''''deallocate -- returned pointer will leak here, just testing
print "y ="; t.y
sleep'':::::
Function somefunc() As sometype ptr
dim p as sometype ptr
p = allocate( len( sometype ) )
p->x = 1234
p->y = 5678
somefunc = pend function'' iif.bas
'' IIF test
'' randomize timer
a = rnd * 10
b = rnd * 10
print "a ="; a; "; b ="; b
print "a * 2 > b? ("; iif( a * 2 > b, -1, 0 ); ")"
print "(0=false; -1=true)"
sleep'' inlineasm.bas
'' inline assembly example
''declare function mulintegers( byval x as integer, byval y as integer ) as integer randomize timer
a = rnd * 100
b = rnd * 100 print a; " * "; b; " = "; mulintegers( a, b )
sleep
'':::::
function mulintegers( byval x as integer, byval y as integer ) as integer
dim res as integer
asm
mov eax, [x]
imul eax, [y]
mov [res], eax
end asm
mulintegers = res
end function'' optargs.bas
'' optional arguments test
''declare sub foo( byval arg1 as double = 1, byval arg2 as integer = -2 )declare function bar( byval arg1 as integer = -2 , byval arg2 as integer )declare sub optstr( byval arg1 as string = "abc", arg2 as string = "def" )
foo
a = bar( , 1 )
optstr
sleep
'':::::
sub foo( byval arg1 as double = 1, byval arg2 as integer = -2 ) print arg1 * arg2end sub'':::::
function bar( byval arg1 as integer = -2, byval arg2 as integer ) print arg1 * arg2end function '':::::
sub optstr( byval arg1 as string, arg2 as string ) print arg1 + arg2end sub去下个来玩玩吧!
http://www.freebasic.net
http://sourceforge.net/projects/fbc/
'' hello.bas
'' hello world example
'' width 80, 25
view print 1 to 8
color 0, 7
cls view print 17 to 25
color , 7
cls locate 25,57
print "press any key to exit...";
view print 9 to 16
color 7, 1
cls
locate 13, 40 - (len( "Welcome to freeBASIC!" ) \ 2)
print "Welcome to ";
color 15
print "freeBASIC";
color 7
print "!"
sleep'' allocate.bas
'' dynamic memory allocation example
''Type sometype
x As Integer
y As Integer
End TypeDeclare Function somefunc() As sometype ptr Dim t as sometype, p as sometype ptr p = somefunc()
t = *p
print "x ="; p->x;
deallocate p
print " x ="; t.x t = *somefunc()
'''''deallocate -- returned pointer will leak here, just testing
print "y ="; t.y
sleep'':::::
Function somefunc() As sometype ptr
dim p as sometype ptr
p = allocate( len( sometype ) )
p->x = 1234
p->y = 5678
somefunc = pend function'' iif.bas
'' IIF test
'' randomize timer
a = rnd * 10
b = rnd * 10
print "a ="; a; "; b ="; b
print "a * 2 > b? ("; iif( a * 2 > b, -1, 0 ); ")"
print "(0=false; -1=true)"
sleep'' inlineasm.bas
'' inline assembly example
''declare function mulintegers( byval x as integer, byval y as integer ) as integer randomize timer
a = rnd * 100
b = rnd * 100 print a; " * "; b; " = "; mulintegers( a, b )
sleep
'':::::
function mulintegers( byval x as integer, byval y as integer ) as integer
dim res as integer
asm
mov eax, [x]
imul eax, [y]
mov [res], eax
end asm
mulintegers = res
end function'' optargs.bas
'' optional arguments test
''declare sub foo( byval arg1 as double = 1, byval arg2 as integer = -2 )declare function bar( byval arg1 as integer = -2 , byval arg2 as integer )declare sub optstr( byval arg1 as string = "abc", arg2 as string = "def" )
foo
a = bar( , 1 )
optstr
sleep
'':::::
sub foo( byval arg1 as double = 1, byval arg2 as integer = -2 ) print arg1 * arg2end sub'':::::
function bar( byval arg1 as integer = -2, byval arg2 as integer ) print arg1 * arg2end function '':::::
sub optstr( byval arg1 as string, arg2 as string ) print arg1 + arg2end sub去下个来玩玩吧!
http://www.freebasic.net
http://sourceforge.net/projects/fbc/
原版:
http://219.134.128.59/cgi-bin/dl/02622F20B0471C04E9AF671BEF77BAA6301030FC55104C365FB3140220ED5B412073F69EB5243D6331BDFD35F3DC3FBB74EF/0202PureBasic.rar
汉化版:
http://219.134.128.59/cgi-bin/dl/075646BECC626CCDF36CA4577D04FFF873F5D6FDB2EB78F4F1D4852233E7009B0FF2B0C6068CE77D61E1C0E20A634FEC3C12/PureBasic.rar
下载原版安装后在安装汉化版!
你这个看起来还不错。