1 / 33

Algoritma & PEMROGRAMAN 2B (Visual basic)

Algoritma & PEMROGRAMAN 2B (Visual basic). Bonang Waspadadi Ligar, S.Si, MMSI. Message box. Message Box / Kotak pesan adalah kotak dialog khusus yang digunakan untuk menampilkan informasi kepada pengguna User tidak bisa mengetik apapun pada message box

priorl
Download Presentation

Algoritma & PEMROGRAMAN 2B (Visual basic)

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Algoritma & PEMROGRAMAN 2B (Visual basic) Bonang Waspadadi Ligar, S.Si, MMSI

  2. Message box • Message Box / Kotak pesan adalah kotak dialog khusus yang digunakan untuk menampilkan informasi kepada pengguna • User tidak bisa mengetik apapun pada message box • MsgBox adalah perintah yang digunakan untuk menampilkan message box.

  3. syntax • Syntax: • MsgBox “prompt” [, buttons, “title”] • Prompt.Required. Pesan yang ditampilkan di kotak dialog. Panjang maksimum prompt kira-kira 1024 karakter, tergantung lebar karakter yang digunakan. • Buttons.Optional. Ekspresi numerik yang menentukan jenis tombol, icon, dll. • Title.Optional. Judul dialog box, jika tidak ditentukan maka nama program yang akan ditampilkan.

  4. The buttons argument • The buttons argument is formed by five groups of values. • The first group of values (0–5) describes the number and type of buttons displayed in the dialog box; • The second group (16, 32, 48, 64) describes the icon style; • The third group (0, 256, 512, 768) determines which button is the default;

  5. First group Determines which buttons to display

  6. second group Determines which icon to display

  7. third group Determines which button is default

  8. fourth group Special buttons

  9. Message box • There are 2basic ways to use MsgBox: • If you do NOT need to test which button the user clicked • if you DO need to test which button the user clicked

  10. Message box • If you do NOT need to test which button the user clicked (only an OK button), then you can use MsgBox as if you were calling a Sub. You can use the following syntax: • Msgbox arguments • -or- • Call MsgBox(arguments)

  11. Example • The statement • MsgBox "Hello there!" • causes the following box to be displayed:

  12. Example • The statement • MsgBox "The Last Name field must not be blank.", vbExclamation, "Last Name“ • causes the following box to be displayed:

  13. Example • vbExclamation + vbOKOnly • making the full statement read: • MsgBox "The Last Name field must not be blank.", • vbExclamation + vbOKOnly, • "Last Name"

  14. Example • Remember, for the buttons argument, you can add one value from each of the four groups. • An alternative (not recommended) is to use the hard-coded number for the buttons argument, as in: • MsgBox "The Last Name field must not be blank.", 48, "Last Name"

  15. Example • MsgBox "A bad database error has occurred.", vbCritical, • "UpdateCustomerTable" • Result:

  16. Message box • If you DO need to test which button the user clicked (i.e., message box with more than one button), then you must use MsgBox as a function, using the following syntax:  • IntegerVariable = Msgbox (arguments)

  17. Meesage box

  18. Example • Dim intResponse As Integer • intResponse = MsgBox("Are you sure you want to quit?", vbYesNo + vbQuestion, "Quit") • If intResponse = vbYes Then • End • End If • Result: • After the user clicks a button, you would test the return variable (intResponse) for a value of vbYes or vbNo (6 or 7).

  19. Example • Note that the use of the built-in constants makes the code more readable. The statement • intResponse = MsgBox("Are you sure you want to quit?", vbYesNo + vbQuestion, "Quit") • is more readable than • intResponse = MsgBox("Are you sure you want to quit?", 36, "Quit")

  20. Example • Note that the use of the built-in constants makes the code more readable. The statement • If intResponse = vbYes Then • is more readable than • If intResponse = 6 Then

  21. Example • You could use the MsgBox function directly in an if statement without using a separate variable to hold the result ("intResponse" in this case). For example, the above example could have been coded as: • If MsgBox("Are you sure you want to quit?", vbYesNo + vbQuestion, "Quit")= vbYes Then • End • End If

  22. Example • Following is an example using the vbDefaultButton2 constant: • Dim intResponse As Integer • intResponse = MsgBox("Are you sure you want to delete all of the rows " & "in the Customer table?", vbYesNo + vbQuestion + vbDefaultButton2, "Delete") • If intResponse = vbYes Then • ' delete the rows ... • End If • The message box displayed by this example would look like this:

  23. input box • Input Box adalah kotak dialog yang dirancang khusus yang memungkinkan pemrogram meminta sebuah nilai dari pengguna dan menggunakan nilai itu seperlunya. • Terdiri dari judul, pesan untuk menunjukkan nilai yang diminta, text box, dan 2 tombol: OK and Cancel. • InputBox adalah perintah yang digunakan untuk menampilkan message box.

  24. syntax • Syntax: • stringvariable = InputBox (“prompt” , “title” [, default] [, xpos] [, ypos]) • Prompt.Required. Pesan yang ditampilkan di input box. Panjang maksimum prompt kira-kira 1024 karakter, tergantung lebar karakter yang digunakan. • Title.Optional. Judul input box, jika tidak ditentukan maka nama program yang akan ditampilkan. • Default.Optional. Ekspresi numerik yang akan tampil pertama kali saat kotak inputbox tampil. • xpos and ypos. Optional. koordinat untuk menentukan posisi kotak masukan (ukuran pixel)

  25. Example • The statement • Dim strName As String • strName = InputBox("Enter your name:", "Input Test") • causes the following box to be displayed:

  26. Example • The statement • strAcctID = InputBox("Enter account ID:", "Input Test", "ABC-123") • causes the following box to be displayed:

  27. Example • Private Sub Commandl_Click( ) • Dim destination As String • Do destination = InputBox("Enter destination", "Vacation destinations", _ "Hawaii", 100,300) • If destination <> “” Then MsgBox "You have chosen" & destination • Loop Until destination <> “ “ • End Sub • causes the following box to be displayed:

More Related