Kamis, 28 Mei 2009

Traffic light



'the following constants are used to give the lights a certain colorConst Off = &H8000000FConst Red = vbRedConst Green = vbGreenConst Orange = &H80C0FF'a simple traffic junction of two perpendicular crossing streets'consists of 4 traffic poles. Each traffic pole has a green, orange'and red light. There is always just one light on per pole.'The traffic lights control on one of those junctions has just 4'statusses. The current status is stored in the variable "Status".Dim Status As Integer'The time a status lasts, is derived from the following constants, which'indicate the time in seconds.Const TimeForStatus1 = 5Const TimeForStatus2 = 3Const TimeForStatus3 = 5Const TimeForStatus4 = 3Private Sub SetStatus(ByVal intStatus As Integer)'Set the status variable to the new statusStatus = intStatus'Turn off all the lightsshpLamp1Groen.FillColor = OffshpLamp1Oranje.FillColor = OffshpLamp1Rood.FillColor = OffshpLamp2Groen.FillColor = OffshpLamp2Oranje.FillColor = OffshpLamp2Rood.FillColor = OffshpLamp3Groen.FillColor = OffshpLamp3Oranje.FillColor = OffshpLamp3Rood.FillColor = OffshpLamp4Groen.FillColor = OffshpLamp4Oranje.FillColor = OffshpLamp4Rood.FillColor = Off'Turn on the appropriate lights with the correct color,'depending on the current statusSelect Case intStatus 'or "Select Case Status", won't make any differenceCase 1shpLamp1Rood.FillColor = RedshpLamp2Groen.FillColor = GreenshpLamp3Rood.FillColor = RedshpLamp4Groen.FillColor = GreenTimer1.Interval = TimeForStatus1 * 1000Case 2shpLamp1Rood.FillColor = RedshpLamp2Oranje.FillColor = OrangeshpLamp3Rood.FillColor = RedshpLamp4Oranje.FillColor = OrangeTimer1.Interval = TimeForStatus2 * 1000Case 3shpLamp1Groen.FillColor = GreenshpLamp2Rood.FillColor = RedshpLamp3Groen.FillColor = GreenshpLamp4Rood.FillColor = RedTimer1.Interval = TimeForStatus3 * 1000Case 4shpLamp1Oranje.FillColor = OrangeshpLamp2Rood.FillColor = RedshpLamp3Oranje.FillColor = OrangeshpLamp4Rood.FillColor = RedTimer1.Interval = TimeForStatus4 * 1000End Select'We need to call the following subroutineRefreshLightsEnd SubPrivate Sub RefreshLights()'This subroutine makes sure that de data on the screen is'displayed correctlyshpLamp1Groen.RefreshshpLamp1Oranje.RefreshshpLamp1Rood.RefreshshpLamp2Groen.RefreshshpLamp2Oranje.RefreshshpLamp2Rood.RefreshshpLamp3Groen.RefreshshpLamp3Oranje.RefreshshpLamp3Rood.RefreshshpLamp4Groen.RefreshshpLamp4Oranje.RefreshshpLamp4Rood.RefreshEnd SubPrivate Sub Form_Load()'When the programs starts, it starts with status 1SetStatus 1'Initializing the timer will start the timer1_timer subroutine after the'set interval has elapsed (in milliseconds)Timer1.Interval = TimeForStatus1 * 1000End SubPrivate Sub Timer1_Timer()'Change to the next statusStatus = Status + 1'If the next status is 5 then we need to change it back to oneIf Status = 5 Then Status = 1SetStatus StatusEnd Sub
UTS MULOK : VISUAL BASIC
1. Skrip yang masih tergolong bahasa pemrograman bahasa level Rendah adalah : 0B38:0100 B402
2. Skrip yang masih tergolong bahasa pemrograman bahasa level menengah adalah : Mov AH,02h
3. Skrip yang masih tergolong bahasa pemrograman bahasa level tinggi adalah : Write(‘A’);
4. Berisi Data atau program adalah bagian definisi dari : file
5. Kumpulan instruksi / perintah yang dirangkaian sehingga membentuk suatu proses dinamakan :program
6. Apa yang dimaksud dengan meng-Compile instruksi program yang dibuat : memeriksa program yang telah disusun
7. Flowchart berfungsi sebagai : alat bantu yang berupa simbol – simbol yang saling dihubungkan sehingga dapat menggambarkan alur pikir sebuah program atau permasalahan yang akan diproses dengan progam komputer.
8. Contoh Bahasa Pemrograman Berbasis Teks, kecuali: Visual basic
9. Bahasa Pemrograman Visual Basic memiliki karakter utama yakni event driven yang bermakna : Program menunggu user menjalankan program
10. Berikut yang bukan termasuk Event adalah : Merubah tampilan window
11. Salah satu contoh Properties yakni : Bentuk tampilan di window dapat anda ubah melalui template(cetakan) yang disediakan.
12. Yang dimaksud dengan methode adalah : susunan perintah yang dikerjakan bila event dijalankan
13. Jelaskan tujuan program berikut : Private Sub Lblnama_DblClick()Lblnama.caption =“ Saya sedang Belajar Visual Basic”End Sub
Jika diklik 2 kali maka akan ditampilkan “Saya sedang Belajar Visual Basic.
14. Apa Perbedaan dari Combo Box dengan List Box :Combo box tampilannya hanya satu sedangkan List box menampilkan beberapa pilihan.
15. Property Alignment pada label berfungsi untuk :Mengatur tata letak teks.16. Tempat dimana kita membuat tampilan (user interface) dari program aplikasi dinamakan :properties17. Dengan melihat tampilan program diatas,komponen yang dibutuhkan adalah :
18. Dengan melihat gambar diatas, komponen yang ditunjuk oleh label A adalah :
19. Dengan melihat gambar diatas, komponen yang ditunjuk oleh label A adalah :
20. Dengan melihat gambar diatas, komponen yang ditunjuk oleh label A adalah :

Chapter 6





Dim NewElement As Integer (membuat variable / elemen baru sebagai integer)Private Sub Form_Click (membuat bentuk klik yang bisa diinput gambar) ()Load Image1(NewElement)Image1(NewElement).Visible = True(menentukan letak gambar)'Image1(NewElement).Top = Image1(NewElement - 1).Top'Image1(NewElement).Left = Image1(NewElement - 1).Left + 495( Menambah komponen dengan berurutan satu persatu)'NewElement = NewElement + 1'==================================================(utk mengatur tmpt ackan dng kode)'For Random Placement use this code:Image1(NewElement).Top = CInt(Form1.Height * Rnd (menentkan ltak ackan))Image1(NewElement).Left = CInt(Form1.Width * Rnd (menentkan ltak ackan))NewElement = NewElement + 1 ( Menambah komponen dengan berurutan satu persatu) '=================================================="End SubPrivate Sub Form_Load (menmplkan pesn sesuai dng properties isi_pesan dan judl_pesn yg di input melalui komponen yg kita buat)()NewElement = 1 (jml komponen yg ditmbahkan secra berurutn)End Sub (mengakhiri)