此处为VisualFreeBasic编程教程(从零开始学或VB进阶)的子章节部分,全部目录点链接。 高深的,有料的,大多是C语言,但C语言与B语言的语法相差甚远,我们必须基本了解下 就可以无障碍的复制C语言的代码来,自己改B语言使用了。 不过有一点好消息,C语言的数据类型,绝大多少可以直接复制来用,不用修改。 变量声明 - C/C++[/p]int a;
- int a, b, c;
- FreeBASIC
- dim a as integer
- dim as integer a, b, c
复制代码未初始化的变量 - int a;[/p]------------------------------------
- dim a as integer
复制代码零初始化变量 - int a = 0;[/p]-------------------------------
- dim a as integer
复制代码初始化变量 - int a = 123;[/p]-------------------------------------
- dim a as integer = 123
复制代码数组 - int a[4];[/p]a[0] = 1;
- ---------------------------------------
- dim a(0 to 3) as integer
- a(0) = 1
复制代码指针 - int a;[/p]int *p;
- p = &a;
- *p = 123;
- -------------------------------------------
- dim a as integer
- dim p as integer ptr
- p=@a
- *p = 123
复制代码结构,用户定义类型 - struct UDT {[/p]int myfield;
- }
- -------------------------------------
- type UDT
- myfield as integer
- end type
复制代码typedef,别名 - typedef int myint;[/p]------------------------------
- type myint as integer
复制代码结构指针 - struct UDT x;[/p]struct UDT *p;
- p = &x;
- p->myfield = 123;
- -------------------------------------
- dim x as UDT
- dim p as UDT ptr
- p = @x
- p->myfield = 123
复制代码函数声明 - int foo( void );[/p]----------------------------------------
- function foo( ) as integer
复制代码函数体 - int foo( void ) {[/p] return 123;
- }
- ---------------------------------
- function foo( ) as integer
- return 123
- end function
复制代码过程声明 - void foo( void );[/p]------------------------------
- sub foo( )
复制代码过程体 - void foo( void ) {[/p]}
- ----------------------------------
- sub foo( )
- end sub
复制代码Byval参数 - void foo( int param );[/p]foo( a );
- -------------------------------------------
- sub foo( byval param as integer )
- foo( a )
复制代码byref参数 - void foo( int *param );[/p]foo( &a );
-
- void foo( int& param );
- foo( a );
- ---------------------------------
- sub foo( byref param as integer )
- foo( a )
复制代码语句分隔符 - ; 分号[/p]----------------------------------
- : 冒号
复制代码for循环 - for (int i = 0; i < 10; i++) {[/p]...
- }
- -----------------------------------
- for i as integer = 0 to 9 还可以带声明 I 的,省了 DIM i as integer
- ...
- next
复制代码while循环 - while (condition) {[/p]...
- }
- -------------------------------
- while condition
- ...
- wend
复制代码do-while循环 - do {[/p]...
- } while (condition);
- --------------------------------------
- do
- ...
- loop while condition
复制代码IF ELSE - if (condition) {[/p]...
- } else if (condition) {
- ...
- } else {
- ...
- }
- -------------------------------------
- if condition then
- ...
- elseif condition then
- ...
- else
- ...
- end if
复制代码切换,选择 - switch (a) {[/p]case 1:
- ...
- break;
- case 2:
- case 3:
- ...
- break;
- default:
- ...
- break;
- }
- ----------------------------------
- select case a
- case 1
- ...
-
-
- case 2, 3
- ...
-
- case else
- ...
-
- end select
复制代码字符串文字,字符串 - char *s = "Hello!";[/p]char s[] = "Hello!";
- -----------------------------------------------
- dim s as zstring ptr = @"Hello!"
- dim s as zstring * 6+1 = "Hello!"
复制代码调试输出 - #include <stdio.h>[/p]int main() {
- printf("Hello!\n");
- return 0;
- }
- -------------------------------
- print "Hello!"
复制代码注释 - // foo[/p]/* foo */
- ------------------------------------
- ' foo
- /' foo '/
复制代码编译时检查 - #if a [/p]#elif b
- #else
- #endif
- ------------------------------------------
- #if a
- #elseif b
- #else
- #endif
复制代码编译时目标系统检查 - #ifdef _WIN32[/p]--------------------------------------------
- #ifdef __FB_WIN32__
复制代码模块/头文件名 - foo.c, foo.h[/p]---------------------------------------------
- foo.bas, foo.bi
复制代码典型的编译器命令创建可执行文件 - gcc foo.c -o foo[/p]-----------------------------------
- fbc foo.bas
复制代码
|