intTypePromotion=1
zunia.vn Tuyển sinh 2024 dành cho Gen-Z zunia.vn zunia.vn
ADSENSE

Bài tập ôn Kỹ thuật lập trình

Chia sẻ: Nguyen Thi Thanh Thao | Ngày: | Loại File: DOC | Số trang:24

290
lượt xem
69
download
 
  Download Vui lòng tải xuống để xem tài liệu đầy đủ

Tài liệu về các bài tập kỹ thuật lập trình tin học...

Chủ đề:
Lưu

Nội dung Text: Bài tập ôn Kỹ thuật lập trình

  1. Bài 1. viết chương trình lời chào hello!!! Private Sub cmdCHAO_Click() txtDisplay.Text = "chao ban!!!!!" End Sub Private Sub cmdTHOAT_Click() End End Sub Private Sub cmdXOA_Click() txtDisplay.Text = "" End Sub Bài 2
  2. Option Explicit Private Sub cmdCAPNHAT_Click() Dim GT As String * 5 Dim HOTEN As String * 30 Dim NAMSINH As Integer Dim TUOI As Single Dim NAM As Date 'gán giá tri vào bien HOTEN = txtHOTEN NAMSINH = Val(txtNAMSINH) NAM = Year(Date) TUOI = NAM - txtNAMSINH If chkGT = 1 Then If TUOI 50 Then GT = " ONG " Else GT = " CHU "
  3. End If End If Else If TUOI 50 Then GT = " BA " Else GT = " CO " End If End If End If lblCHAO = "Chaøo" & GT & HOTEN & Chr(13) & "Raát vui ñöôïc ñoùn" & GT & "ñeán vôùi cöûa haøng cuûa chuùng toâi" End Sub Private Sub cmdTHOAT_Click() End End Sub Bài 3 Private Sub CmdASCII_Click() Dim i As Integer For i = 0 To 255 Text2 = Text2 & vbCrLf & i & "-->" & Chr(i) Next i
  4. End Sub Private Sub CmdTHOAT_Click() End End Sub Private Sub CmdTINH_Click() LblKQ = Text1 & "-->" & Chr(Text1) End Sub Private Sub Text1_KeyPress(KeyAscii As Integer) If KeyAscii = 13 Then Text1.SetFocus Text1.SelStart = 0 Text1.SelLength = Len(Text1) LblKQ = "ki tu bieu dien cua ma ASCII" & Text1 & " la: " & Chr(Val(Text1)) End If End Sub Bài 4
  5. Private Sub CMDTHOAT_Click() If MsgBox("Ban That Su Muon Thoat??", 4 + 32, "tb") = 6 Then End End If End Sub Private Sub CMDXEM_Click() Dim I As Byte Dim A As String TXTNHAP.SetFocus If I < 1 And I > 9 Then TXT2.Text = "KHONG CO KET QUA!!!" TXTNHAP.SetFocus TXTNHAP.SelStart = 0 TXTNHAP.SelLength = Len(TXTNHAP) Else For I = 1 To 10 A = TXTNHAP.Text * I TXT2.Text = TXT2 & vbCrLf & TXTNHAP & " X " & I & " = " & A & vbCrLf TXTNHAP.SetFocus TXTNHAP.SelStart = 0 TXTNHAP.SelLength = Len(TXTNHAP) TXT2.SelStart = 0 TXT2.SelLength = Len(TXT2) Next I End If End Sub Bài 5
  6. Private Sub cmdthoat_Click(Index As Integer) End End Sub Private Sub cmdtinh_Click(Index As Integer) Dim N, I, GT, X, f As Integer Dim S, T, S2, S3, S4 As Single N = Val(txt1) S=0 For I = 1 To N S=S+1/I S = Format(S, "##,##.00") txt3 = S Next I GT = 1 T=0 For I = 1 To N GT = GT * I T = T + 1 / GT
  7. T = Format(T, "##,##.00") txt4 = T Next I GT = 1 X = Val(txt2) S2 = 1 For I = 1 To N G=G*I S2 = S2 + X * I / GT txt5 = S2 Next I S4 = 0 For I = 1 To N S4 = S4 + Sin(X) + Sin(X) * I txt7 = S4 Next I End Sub Bài 6
  8. Option Explicit Dim i As Byte Private Sub Form_Load() i=0 End Sub Private Sub Timer1_Timer() If i < 5 Then Me.BackColor = QBColor(Int(Rnd * 16)) Image1.Picture = Image2(i).Picture i=i+1 Else i=0 End If End Sub Bài 7
  9. Private Sub cmd_thoat_Click() End End Sub Private Sub cmd1_Click() Dim X, Y, CANH, CANH2 As Single X = Val(txtX) Y = Val(txtY) CANH = Val(txtCANH) CANH2 = Val(txtCANH2) If (txtCANH2.Visible = True) Then Shape1.Left = X Shape1.Top = Y Shape1.Width = CANH2 Shape1.Height = CANH Else Shape1.Left = X Shape1.Top = Y Shape1.Width = CANH Shape1.Height = CANH End If End Sub Private Sub cmd2_Click() Dim X, Y, CANH As Single X = Val(txtX) Y = Val(txtY) CANH = Val(txtCANH) CANH2 = Val(txtCANH2) If (txtCANH2.Visible = True) Then Shape1.Left = X - CANH / 2 Shape1.Top = Y - CANH2 / 2 Shape1.Width = CANH2 Shape1.Height = CANH Else Shape1.Left = X - CANH / 2 Shape1.Top = Y - CANH / 2 Shape1.Width = CANH Shape1.Height = CANH End If End Sub Private Sub form_load() ScaleMode = 7 Picture1.ScaleMode = 7 End Sub
  10. Private Sub Option2_Click(Index As Integer) Shape1.Shape = Index Select Case Index Case 0, 2 Label4.Visible = True txtCANH2.Visible = True Case 1, 3 Label4.Visible = False txtCANH2.Visible = False End Select End Sub Bài 8 timer : intetval: 500 Private Sub Timer1_Timer() Label1 = Time() End Sub Bài 9
  11. Option Explicit Private Sub cmdTINH_Click() Dim CANH1, CANH2, DT, CV As Single CANH1 = Val(txtCanh1) CANH2 = Val(txtCanh2) CV = (CANH1 + CANH2) * 2 DT = CANH1 * CANH2 lblKQ = "dien tich= " & DT & Chr(13) & "chu vi= " & CV 'chuyen focus ve txtCanh1 txtCanh1.SetFocus 'choïn nguyen chuoi so trong txtCanh1 txtCanh1.SelStart = 0 txtCanh1.SelLength = Len(txtCanh1) End Sub Private Sub txtCanh1_KeyPress(KeyAscii As Integer) If KeyAscii = 13 Then txtCanh2.SetFocus 'choïn nguyen chuoi so trong txtCanh2
  12. txtCanh2.SelStart = 0 txtCanh2.SelLength = Len(txtCanh2) End If End Sub Private Sub txtCanh2_KeyPress(KeyAscii As Integer) If KeyAscii = 13 Then ' goi thuc hien thu tuc cmdTINH-click cmdTINH_Click End If End Sub Bài 10 Private Sub cmdthoat_Click() End End Sub Private Sub txtsodau_KeyPress(KeyAscii As Integer) If KeyAscii = 13 Then txtsosau.SetFocus txtsosau.SelStart = 0 txtsosau.SelLength = Len(txtsosau) End If End Sub Private Sub txtsosau_KeyPress(KeyAscii As Integer) If KeyAscii = 13 Then cmdtinh_Click End If
  13. End Sub Private Sub cmdtinh_Click() Dim sothu1, sothu2, tong, hieu, tich, thuong As Single sothu1 = Val(txtsodau) sothu2 = Val(txtsosau) tong = sothu1 + sothu2 hieu = sothu1 - sothu2 tich = sothu1 * sothu2 thuong = sothu1 / sothu2 lblkq = "tong= " & tong & Chr(13) & "hieu= " & hieu & Chr(13) & "tich= " & tich & Chr(13) & "thuong= " & thuong txtsodau.SetFocus txtsodau.SelStart = 0 txtsodau.SelLength = Len(txtsodau) End Sub Bài 11 Private Sub Command1_Click() lblxuat = txtnhap End Sub Bài 12 USCLN
  14. FORM 1 Option Explicit Dim x As Byte Dim y As Byte Public Function USCLN(ByVal A As Integer, ByVal B As Integer) Dim r As Integer Do While B 0 r = A Mod B A=B B=r Loop USCLN = A End Function Private Sub cmdTINH_Click() Dim soA As Integer Dim soB As Integer soA = Val(txtA) soB = Val(txtB) 'goïi haøm USCLN lblKQ = "uoc so chung lon nhat = " & USCLN(soA, soB) End Sub Private Sub Command1_Click() 'hieän form Form2.Show 'daáu form Me.Hide End Sub FORM 2 Option Explicit
  15. Private Sub Command1_Click() Dim soA As Integer Dim soB As Integer soA = Val(txtA) soB = Val(txtB) lblKQ = "uoc so chung lon nhat = " & Form1.USCLN(soA, soB) End Sub Private Sub Command2_Click() 'giaûi phoùng for khoûi boä nhôù Unload Me 'hieän form Form1.Show End Sub Bài 13.List Option Explicit Private Sub cmdEnd_Click() End End Sub Private Sub cmdSUA_Click() If txtNAME = "" Then
  16. MsgBox "chua nhap" txtNAME.SetFocus Else lstDS.List(lstDS.ListIndex) = txtNAME End If Label3 = lstDS.ListCount End Sub Private Sub cmdThem_Click() If txtNAME = "" Then MsgBox "chua nhap" Else lstDS.AddItem txtNAME End If txtNAME.SelStart = 0 txtNAME.SelLength = Len(txtNAME) txtNAME.SetFocus Label3 = lstDS.ListCount End Sub Private Sub cmdXOA_Click() Dim i As Byte i = lstDS.ListIndex lstDS.RemoveItem lstDS.ListIndex Label3 = lstDS.ListCount If i = 0 And lstDS.ListCount = 0 Then cmdXOA.Enabled = False txtNAME.Text = "" Exit Sub End If If i = lstDS.ListCount Then i = i - 1 lstDS.Selected(i) = True End Sub Private Sub cmdXoaHet_Click() lstDS.Clear Label3 = lstDS.ListCount End Sub Private Sub Form_Load() Label3 = lstDS.ListCount cmdXOA.Enabled = False End Sub Private Sub lstDS_Click() txtNAME.Text = lstDS.Text
  17. cmdXOA.Enabled = True txtNAME.SetFocus End Sub Bài 14. Chạy chữ Option Explicit Private Sub Timer1_Timer() lblTRAI = Right(lblTRAI, Len(lblTRAI) - 1) & Left(lblTRAI, 1) lblTRAI.ForeColor = QBColor(Int(Rnd * 16)) lblPHAI = Right(lblPHAI, 1) & Left(lblPHAI, Len(lblPHAI) - 1) lblPHAI.ForeColor = QBColor(Int(Rnd * 16)) End Sub Private Sub HsbColor_Change(Index As Integer) 'Ñaët maøu toâ cuûa shpSample baèng RGB cuûa ba giaù trò trong ba thanh cuoän shpSample.FillColor = RGB(HsbColor(0).Value, HsbColor(1).Value, HsbColor(2).Value) 'Ñaët noäi dung cuûa TextBox töông öùng baèng giaù trò cuûa thanh cuoän
  18. txtColor(Index).Text = Trim(Str(HsbColor(Index))) End Sub Private Sub txtColor_Change(Index As Integer) 'Ñaët giaù trò cuûa thanh cuoän töông öùng baèng giaù trò cuûa TextBox töông öùng HsbColor(Index).Value = Val(txtColor(Index).Text) 'Ñaët maøu toâ cuûa shpSample baèng RGB cuûa ba giaù trò trong ba thanh cuoän shpSample.FillColor = RGB(HsbColor(0).Value, HsbColor(1).Value, HsbColor(2).Value) End Sub Bài 15. Điều kiện hình vuông và dãy hình vuông Private Sub cmd_cheo_Click() Dim X, Y, CANH As Single X = Val(txtX) Y = Val(txtY)
  19. CANH = Val(txtCANH) Shape1.Left = X Shape1.Top = Y Shape1.Width = CANH Shape1.Height = CANH Picture1.Line (X, Y)-(X + CANH, Y + CANH) Picture1.Line (X + CANH, Y)-(X, Y + CANH) End Sub Private Sub cmd_hinhvuong_Click() Dim X, Y, CANH As Single X = Val(txtX) Y = Val(txtY) CANH = Val(txtCANH) Shape1.Left = X Shape1.Top = Y Shape1.Width = CANH Shape1.Height = CANH End Sub Private Sub cmd_hvuong_n_Click() Dim N, i, a CANH = Val(txtCANH) N = txtN If N > 1 Then 've day le For i = 1 To N Step 2 Picture1.Line (i * CANH, 0)-((i + 1) * CANH, CANH), RGB(Int(Rnd * 255), Int(Rnd * 255), Int(Rnd * 255)), BF Next i 've day chan For i = 2 To N Step 2 Picture1.Line (i * CANH, CANH)-((i + 1) * CANH, 2 * CANH), RGB(Int(Rnd * 255), Int(Rnd * 255), Int(Rnd * 255)), BF Next i End If End Sub Private Sub cmd_ngoai_Click() Dim X, Y, CANH As Single X = Val(txtX) Y = Val(txtY) CANH = Val(txtCANH) Shape1.Left = X
  20. Shape1.Top = Y Shape1.Width = CANH Shape1.Height = CANH Shape3.Left = X Shape3.Top = Y Shape3.Shape = 3 Shape3.Left = X + CANH / 2 - Sqr(CANH * CANH + CANH * CANH) / 2 Shape3.Top = Y + CANH / 2 - Sqr(CANH * CANH + CANH * CANH) / 2 Shape3.Width = Sqr(CANH * CANH + CANH * CANH) Shape3.Height = Sqr(CANH * CANH + CANH * CANH) End Sub Private Sub cmd_noi_Click() Dim X, Y, CANH As Single X = Val(txtX) Y = Val(txtY) CANH = Val(txtCANH) Shape1.Left = X Shape1.Top = Y Shape1.Width = CANH Shape1.Height = CANH Shape2.Left = X Shape2.Top = Y Shape2.Shape = 3 Shape2.Width = CANH Shape2.Height = CANH End Sub Private Sub cmd_thoat_Click() End End Sub Private Sub cmd_vechung_Click() Dim X, Y, CANH As Single X = Val(txtX) Y = Val(txtY) CANH = Val(txtCANH) Shape1.Left = X Shape1.Top = Y Shape1.Width = CANH Shape1.Height = CANH
ADSENSE

CÓ THỂ BẠN MUỐN DOWNLOAD

 

Đồng bộ tài khoản
2=>2