tailieunhanh - Mastering Microsoft Visual Basic 2010 phần 2
Mối quan hệ là cốt lõi của một cơ sở dữ liệu quan hệ, bởi vì chúng liên quan các bảng với nhau. Để tạo ra một mối quan hệ, bạn nhấn đúp chuột lên tên của một bảng trong Server Explorer và sau đó chọn mối quan hệ thiết kế bảng, trong đó hiển thị hộp thoại chính mối quan hệ nước ngoài thể hiện trong hình 21,9. | VARIABLES AS OBJECTS 73 The sqrValue variable is not visible outside the block of the loop. If you attempt to use it before the For statement or after the Next statement the code won t compile. The sqrValue variable maintains its value between iterations. The block-level variable is not initialized at each iteration even though there s a Dim statement in the loop. Finally in some situations the entire application must access a certain variable. In this case the variable must be declared as Public. Public variables have a global scope they are visible from any part of the application. To declare a public variable use a Public statement in place of a Dim statement. Moreover you can t declare public variables in a procedure. If you have multiple forms in your application and you want the code in one form to see a certain variable in another form you can use the Public modifier. So why do we need so many types of scope You ll develop a better understanding of scope and which type of scope to use for each variable as you get involved in larger projects. In general you should try to limit the scope of your variables as much as possible. If all variables were declared within procedures you could use the same name for storing a temporary value in each procedure and be sure that one procedure s variables wouldn t interfere with those of another procedure even if you use the same name. A Variable s Lifetime In addition to type and scope variables have a lifetime which is the period for which they retain their value. Variables declared as Public exist for the lifetime of the application. Local variables declared within procedures with the Dim or Private statement live as long as the procedure. When the procedure finishes the local variables cease to exist and the allocated memory is returned to the system. Of course the same procedure can be called again and then the local variables are re-created and initialized again. If a procedure calls another its local .
đang nạp các trang xem trước