X
تبلیغات
عصر جدید کامپیوتر

عصر جدید کامپیوتر

SHOBEIR - PAHLEVANI

حل خودآزمایی ویژوال بیسیک (برنامه نویسی 2)

تمرین متن کتاب - فصل دوم


تمرين5-2 صفحه 34

()Private Sub Command1_Click

Dim c As Integer

(c = StrComp(Me.Text1.Text, Me.Text2.Text

Select Case c

Case 0: Me.List1.AddItem Me.Text1.Text + "=" + Me.Text2.Text

Case 1: Me.List1.AddItem Me.Text1.Text + ">" + Me.Text2.Text

Case -1: Me.List1.AddItem Me.Text1.Text + "<" + Me.Text2.Text

End Select

End Sub

تمرين 6-2 صفحه 36

()Private Sub Combo1_Click

Select Case Me.Combo1.Text

                                                                                                                                          " Case "BAHAR       

 Me.List1.Clear

" Me.List1.AddItem "FARVARDIN

" Me.List1.AddItem "ORDIBEHESHT

" Me.List1.AddItem "KHORDAD

" Case "TABESTAN

 Me.List1.Clear

" Me.List1.AddItem "TIR

" Me.List1.AddItem "MORDAD

" Me.List1.AddItem "SHAHRIVAR

 End Select

                                                                                                                                                   EndSub   

تمرين7-2 صفحه 38

()Private Sub Command1_Click

Dim msg As String

msg = "" + Me.List1.Text + vbCr

msg = msg + " MAKAN :" + Me.Combo1.Text + vbCr

msg = msg + "  GHAZA :" + Me.Combo2.Text + vbCr

"MsgBox msg, vbOKOnly + vbInformation, "KHOSH BASHID

End Sub

()Private Sub Form_Load

Me.List1.Clear

"Me.List1.AddItem "SHIRAZ

"Me.List1.AddItem "KERMAN

"Me.List1.AddItem "YAZD

"Me.List1.AddItem "BOSHEHR

Me.List1.ListIndex = 0

 "Me.Combo1.AddItem "AVAL

" Me.Combo1.AddItem "VASAT

" Me.Combo1.AddItem "PANJERE

 Me.Combo1.ListIndex = 0

"Me.Combo2.AddItem "JOJE

" Me.Combo2.AddItem "BARG

" Me.Combo2.AddItem "PITZA

" Me.Combo2.AddItem "SANDEVIJ

 Me.Combo2.ListIndex = 0

 End Sub

تمرين9-2 صفحه 41

()Private Sub Form_Load

( Load Me.Command1(1

 Me.Command1(1).Left = Me.Command1(0).Left

 Me.Command1(1).Top = Me.Command1(0).Top + Me.Command1(0).Height

" Me.Command1(1).Caption = "COMMAND#1

 Me.Command1(1).Visible = True

(Load Me.Command1(2

 Me.Command1(2).Left = Me.Command1(1).Left

Me.Command1(2).Top = Me.Command1(1).Top + Me.Command1(1).Height

"Me.Command1(2).Caption = "COMMAND#2

 Me.Command1(2).Visible = True

End Sub

تمرين 10-2 صفحه 43

Dim cnt As Integer

()Private Sub Command1_Click

Me.Image1(cnt).Visible = False

cnt = cnt + 1

 If cnt > 4 Then cnt = 0

 Me.Image1(cnt).Visible = True

End Sub

()Private Sub Form_Load

Me.Image1(0).Visible = True

Me.Image1(1).Visible = False

Me.Image1(2).Visible = False

Me.Image1(3).Visible = False

Me.Image1(4).Visible = False

Me.Image1(5).Visible = False

cnt = 0

End Sub

تمرين 11-2 صفحه 45

()Private Sub HScroll1_Change

(Me.Text2.Text = CStr(Me.HScroll1.Value

End Sub

()Private Sub VScroll1_Change

(Me.Text1.Text = CStr(Me.VScroll1.Value

End Sub

تمرين 12-2 صفحه 46

()Private Sub Form_Load

HScroll1_Change

End Sub

()Private Sub HScroll1_Change

val1 = Me.HScroll1.Value

val2 = Me.HScroll2.Value

val3 = Me.HScroll3.Value

(Me.Label1.BackColor = RGB(val1, val2, val3

End Sub

()Private Sub HScroll1_Scroll

HScroll1_Change

End Sub

تمرين 14-2 صفحه 51

Option Base 1

 Dim m(10) As Integer

()Private Sub Command1_Click

Randomize

(For i = LBound(m) To UBound(m

 m(i) = 100 * Rnd

(Me.List1.AddItem (m

Next

End Sub

()Private Sub Command2_Click

Dim key As Integer

Dim flag As Integer

""=Me.Label1.Caption

flag = -1

key = Me.Text1.Text

 ( For i = LBound(m) To UBound(m

    If m(i) = key Then

     flag = i

    End If

  Next

 If flag <> -1 Then

  " Me.Label2.Caption = "found

 Else

  " Me.Label2.Caption = "not found

 End If

  End Sub

مرتب سازي حبابي

Option Base 1

 Dim m(10) As Integer

()Private Sub Command1_Click

(For i = LBound(m) To UBound(m

() m(i) = 100 * Rnd

(( Me.List1.AddItem (m(i

Next

End Sub

()Private Sub Command2_Click

For i = 1 To 10

 For j = i To 10

  If m(i) > m(j) Then

 ( temp = m(j

 ( m(j) = m(i

  m(i) = temp

  End If

  Next j, i

  Me.List1.Clear

  For i = 1 To 10

((  Me.List2.AddItem Str(m(i

  Next

End Sub

 

خودآزمایی آخر فصل - فصل دوم


 

خود آزمايي2 صفحه 56

Dim a(1 To 4, 1 To 4) As Integer

()Private Sub Command1_Click

  For i = 1 To 4

   For j = 1 To 4

(":    a(i, j) = Val(InputBox("Enter The Next Number

   Next j

  Next i

End Sub

()Private Sub Command2_Click

For i = 1 To 4

For j = 1 To 4

(Print a(i, j

Next j

Print

Next i

End Sub

()Private Sub Command3_Click

Dim f As Boolean

f = True

i = 1

j = 2

Do While f = True And j <= 4

If a(i, i) = a(j, j) Then

j = j + 1

Else

f = False

Loop

If f = True Then

("MsgBox ("yes

Else

("MsgBox ("no

End If

End If

End Sub

خودآزمايي 3صفحه 56

Dim a(1 To 4, 1 To 4) As Integer

()Private Sub Command1_Click

  For i = 1 To 4

   For j = 1 To 4

(":    a(i, j) = Val(InputBox("Enter The Next Number

   Next j

  Next i

End Sub

()Private Sub Command2_Click

For i = 1 To 4

For j = 1 To 4

(Print a(i, j

Next j

Print

Next i

End Sub

()Private Sub Command3_Click

k = 0

(("q = Val(InputBox("Search This Number

For i = 1 To 4

For j = 1 To 4

If a(i, j) = q Then

k = k + 1

End If

Next

Next

("MsgBox ("The Number Reapit" & Str(k) & "Time

End Sub

خودآزمايي 4 صفحه 56

Dim a(1 To 3, 1 To 3) As Integer

()Private Sub Command1_Click

  For I = 1 To 3

   For j = 1 To 3

((":    a(I, j) = Val(InputBox("Enter The Next Number

   Next j

  Next I

End Sub

()Private Sub Command2_Click

For I = 1 To 3

For j = 1 To 3

(Print a(I, j

Next j

Print

Next I

End Sub

()Private Sub Command3_Click

k = 0

u = 0

 For I = 1 To 3

  For j = 1 To 3

    If (I > j) And (a(I, j)) = 0 Then k = k + 1

     If (I < j) And (a(I, j)) = 0 Then u = u + 1

  Next

 Next

("   If k = 3 Then MsgBox ("Up

("     If u = 3 Then MsgBox ("Down

End Sub

خودآزمايي 5 صفحه 56

Dim nam(1 To 4) As String * 15

Dim num(1 To 4) As Integer

()Private Sub Command1_Click

For i = LBound(num) To UBound(num

(":(" &( nam(i) = InputBox("nam(" & Str(i

((":(" &(     num(i) = Val(InputBox("number(" & Str(i

((     Print nam(i); "="; Str(num(i

 Next

End Sub

()Private Sub Command2_Click

((max1 = num(LBound(num

((max2 = num(UBound(num

(lmax2 = UBound(num

(For i = LBound(num) + 1 To UBound(num

If max1 < num(i) Then

max2 = max1

max1 = num(i)

Else

If max2 < num(i) Then

(max2 = num(i

lmax2 = i

End If

End If

Next

((MsgBox (nam(lmax2) & Str(max2

End Sub

خودآزمایی آخر فصل - فصل سوم


خودآزمايي 1 صفحه 71

()Private Sub mred_Click

ActiveForm.BackColor = vbRed

End Sub

خودآزمايي 2 صفحه 71

()Private Sub Command1_Click

Me.CommonDialog1.ShowFont

Me.Label1.FontName = Me.CommonDialog1.FontName

Me.Label1.FontSize = Me.CommonDialog1.FontSize

Me.Label1.FontBold = Me.CommonDialog1.FontBold

Me.Label1.FontItalic = Me.CommonDialog1.FontItalic

Me.Label1.FontStrikethru = Me.CommonDialog1.FontStrikethru

Me.Label1.FontUnderline = Me.CommonDialog1.FontUnderline

End Sub

()Private Sub Command2_Click

Me.CommonDialog1.ShowColor

Me.Label1.BackColor = Me.CommonDialog1.Color

End Sub

خودآزمايي 3 صفحه 71

()Private Sub Combo1_Click

Me.CommonDialog1.ShowFont

 If Me.Combo1.List(Combo1.ListIndex) = "24" Then

 Me.Label4.FontSize = Me.CommonDialog1.FontSize

 End If

End Sub

()Private Sub Combo2_Click

Me.CommonDialog1.ShowFont

 If Me.Combo2.List(Combo2.ListIndex) = "bold" Then

     Me.Label4.FontBold = Me.CommonDialog1.FontBold

Else

 If Me.Combo2.List(Combo2.ListIndex) = "italic" Then

    Me.Label4.FontItalic = Me.CommonDialog1.FontItalic

Else

  If Me.Combo2.List(Combo2.ListIndex) = "underline" Then

     Me.Label4.FontUnderline = Me.CommonDialog1.FontUnderline

  End If

  End If

  End If

End Sub

تمرینات متن فصل - فصل چهارم


 

تمرين 4-1 صفحه 75

()Private Sub Timer1_Timer

If Me.Label1.Left < Me.Width - Me.Label1.Width Then

 Me.Label1.Left = Me.Label1.Left + 100

Else

 Me.Timer1.Enabled = False

End If

End Sub

تمرين4-2 صفحه 75

Private Sub Command1_Click()

Me.Command1.Caption = CStr(Time)

End Sub

 

()Private Sub Command2_Click

(Me.Command2.Caption = CStr(Date

End Sub

()Private Sub Command3_Click

(Me.Command3.Caption = CStr(Now

End Sub

تمرين 4-3 صفحه 76

()Private Sub Form_Load

Me.Label1.Top = Me.ScaleTop

Me.Label1.Left = Me.ScaleLeft

Me.Label1.Width = Me.ScaleWidth

Me.Label1.Height = Me.ScaleHeight

End Sub

()Private Sub Timer1_Timer

If Me.WindowState = vbNormal Then

( Me.Label1.Caption = CStr(Time

(" Me.Caption = Format(Date, "long date

(" Me.Label2.Caption = Format(Time, "short time

(" Me.Label3.Caption = Format(36000, "0.00

Else

( Me.Caption = CStr(Time

End If

End Sub

تمرين 4-4 صفحه 83

Dim bdate As Date

()Private Sub Command1_Click

If IsDate(Me.Text1.Text) Then

( bdate = CDate(Me.Text1.Text

Else

" MsgBox "jjjj

Me.Text1.SetFocus

 Me.Text1.SelStart = 0

( Me.Text1.SelLength = Len(Me.Text1.Text

 Exit Sub

End If

 Me.Timer1.Enabled = True

 End Sub

()Private Sub Timer1_Timer

Dim sec As Variant

Dim day As Variant

Dim year As Variant

(sec = DateDiff("s", bdate, Now

(day = DateDiff("d", bdate, Now

(year = DateDiff("yyyy", bdate, Now

(Me.Text2.Text = CStr(sec

(Me.Text3.Text = CStr(day

(Me.Text4.Text = CStr(year

End Sub

 

تمرینات متن فصل - فصل پنجم


 

تمرين 10-5 صفحه 103

Dim IntOldX As Integer, IntOldY As Integer, LngColor As Long

()Private Sub CmdClear_Click

    Pic1.Cls

End Sub

()Private Sub CmdDraw_Click

    Dim Intx As Integer, Inty As Integer, IntR As Integer, Intc As Integer

    Randomize Timer

    For i = 1 To 50

       ( Intx = Int(Rnd * Pic1.ScaleWidth

( Inty = Int(Rnd * Pic1.ScaleHeight

(  IntR = Int(Rnd * 40

       ( Intc = Int(Rnd * 16

       ( Pic1.Circle (Intx, Inty), IntR, QBColor(Intc

    Next

End Sub

()Private Sub CmdExit_Click

    Unload Me

End Sub

()Private Sub Form_Load

    Dim IntI As Integer

    Pic1.AutoRedraw = True

( Pic1.BackColor = QBColor(15

    Pic1.ScaleMode = vbPixels

    Pic1.TabStop = False

End Sub

تمرين11-5 صفحه 104

Option Explicit

Private Const d_teta = 3.14159265 / 12

Private teta As Single

Private r1 As Single

Private r2 As Single

Private cx1 As Single

Private cx2 As Single

Private cy1 As Single

Private cy2 As Single

()Private Sub Command1_Click

Me.Timer1.Enabled = Not Timer1.Enabled

 If Timer1.Enabled Then

    " Me.Command1.Caption = "stop

 Else

"  Command1.Caption = "start

 End If

End Sub

()Private Sub Form_Load

Dim dx As Single

Dim dy As Single

  dx = Line1.X2 - Line1.X1

  dy = Line1.Y2 - Line1.Y1

(  r1 = Sqr(dx * dx + dy * dy

  cx1 = Line1.X1

  cy1 = Line1.Y1

  dx = Line2.X2 - Line2.X1

  dy = Line2.Y2 - Line2.Y1

  r2 = Sqr(dx * dx + dy * dy) / 2

  cx2 = (Line2.X1 + Line2.X2) / 2

  cy2 = (Line2.Y1 + Line2.Y2) / 2

End Sub

()Private Sub Timer1_Timer

teta = teta + d_teta

Line1.X2 = cx1 + Cos(teta) * r1

Line1.Y2 = cy1 + Sin(teta) * r1

Line2.X1 = cx2 + Cos(teta) * r2

Line2.Y1 = cy2 + Sin(teta) * r2

Line2.X2 = cx2 - Cos(teta) * r2

Line2.Y2 = cy2 - Sin(teta) * r2

End Sub

تمرين 12-5 صفحه10

()Private Sub Form_Paint
Dim x As Integer
Dim y As Integer
For x = 0 To Me.Width Step Me.Image1.Width
 For y = 0 To Me.Height Step Me.Image1.Height
  PaintPicture Me.Image1, x, y
 Next
Next
End Sub

حل خودآزمایی آخر فصل - فصل پنجم


خود آزمايي 1 صفحه 111

Timer1.Interval = 1

End Sub

()Private Sub Timer1_Timer

Dim X As Integer

Dim Y As Integer

( Me.DrawWidth = Int(Rnd * 5

 For i = 1 To 70

( Y = Int(Rnd * Form1.Height

(  X = Int(Rnd * Form1.Width

(  PSet (X, Y), QBColor(Rnd * 15

 Next i

End Sub

خود آزمايي 2 صفحه 111

()Private Sub Form_Load

Timer1.Interval = 5000

End Sub

()Private Sub Timer1_Timer

Dim X1 As Integer

Dim Y1 As Integer

Dim X2 As Integer

Dim Y2 As Integer

  For i = 1 To 10

( Y1 = Int(Rnd * Form1.Height

( X1 = Int(Rnd * Form1.Width

    ( Y2 = Int(Rnd * Form1.Height

    ( X2 = Int(Rnd * Form1.Width

    ( Me.Line (X1, Y1)-(X2, Y2), QBColor(Rnd * 15

 Next i

End Sub

خودآزمايي 4 صفحه 111

()Private Sub Form_Activate

Me.Picture1.ScaleTop = 200

Me.Picture1.ScaleLeft = -200

Me.Picture1.ScaleWidth = 400

Me.Picture1.ScaleHeight = -400

 For i = -200 To 400 Step 5

  For j = -400 To 200 Step 25

     ( Me.Picture1.PSet (i, j), QBColor(0

     ( Me.Picture1.PSet (j, i), QBColor(0

  Next j

 Next i

End Sub

خودآزمايي 6 صفحه 111

Private Sub Picture1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)

If Button = 1 Then

 Me.Picture1.DrawWidth = 20

( Me.Picture1.PSet (X, Y), QBColor(3

End If

End Sub

Private Sub Picture1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)

If Button = 1 Then

 Me.Picture1.DrawWidth = 5

( Me.Picture1.Line -(X, Y), QBColor(8

End If

End Sub

Private Sub Picture1_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)

If Button = 1 Then

Me.Picture1.DrawWidth = 20

( Me.Picture1.PSet (X, Y), QBColor(3

End If

End Sub

خودآزمايي 7 صفحه 111

()Private Sub Form_Load

"Form1.Caption = "barf

Timer1.Interval = 1

Me.Picture1.Tag = 0

Me.Picture1.Top = 0

Me.Picture1.Left = 0

End Sub

()Private Sub Timer1_Timer

Dim X As Integer

Dim Y As Integer

 For I = 1 To 5000

( Y = Int(Rnd * Me.Picture1.Height

    (X = Int(Rnd * Me.Picture1.Width

( Me.Picture1.DrawWidth = Int(Rnd * 5

( Me.Picture1.PSet (X, Y), QBColor(15

 Next I

Me.Picture1.Tag = Me.Picture1.Tag + 1

 If Me.Picture1.Tag = 10 Then

    Me.Picture1.Cls

    Me.Picture1.Tag = 0

 End If

End Sub


Weblog Themes By shobeir - pahlevani

درباره وبلاگ


سلام من شبیر هستم...به وبلاگ من خیلی خوش اومدین... امیدوارم لحظه های خوبی را در وبلاگم سپری کنین ... راستی ادرس جدید وبلاگم اینه
www.p-shobeir.tk

آمارگیر سایت

ساعت سايت

اشتراک گذاري سايت

موضوعات