Programming Visual Basic 2008 phần 2

Tham khảo tài liệu 'programming visual basic 2008 phần 2', công nghệ thông tin, kỹ thuật lập trình phục vụ nhu cầu học tập, nghiên cứu và làm việc hiệu quả | Subroutines Subroutines begin with a Sub declaration statement and end with an End Sub statement. All of your subroutine s logic appears in between these two mighty jaws. 01 Sub ShowIngredients ByVal gender As Char 02 Dim theMessage As String Unknown. 03 If gender M c Then 04 theMessage Snips and snails and puppy dog tails. 05 ElseIf gender F c Then 06 theMessage Sugar and spice and everything nice. 07 End If 08 MsgBox theMessage 09 End Sub Line 01 shows the subroutine s declaration line in its simplest form throughout the book you will find that there are additional keywords that decorate procedure declarations to change their behavior. The statement begins with the Sub keyword for subroutine followed by the name of the procedure ShowIngredients. The parentheses following this name contain the subroutine s parameters. Parameters allow another block of code that will use this procedure to pass data into the procedure and optionally receive data back. You can include any number of parameters in the subroutine definition simply separate them by commas. Each parameter specifies the name as it will be used in the procedure gender in the sample and its data type Char . The arguments are treated as declared variables within the procedure as is done with gender on lines 03 and 05. The values supplied by the calling code are known as arguments. All arguments are passed by value or by reference. In the sample code the argument passed into gender will be passed by value as specified through the ByVal keyword. The related ByRef keyword indicates an argument to be passed by reference. If you don t include either keyword ByVal is assumed. This passing method impacts whether changes made to the argument within the local procedure are propagated back to the calling code. However the ability to update the original data is also influenced by whether the data is a value type or a reference type. Table 2-3 indicates the behavior for each combination of passing method and data type. .

Không thể tạo bản xem trước, hãy bấm tải xuống
TÀI LIỆU MỚI ĐĂNG
Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.