تبلیغات
دانشجویان مواد دانشگاه تجن - ویژوال بیسیک - تمرین ها 2
چهارشنبه 1390/11/5

ویژوال بیسیک - تمرین ها 2

• نوشته شده توسط: ArAm


معکوس 4 رقمی

Private Sub Command1_Click()

Dim a As Integer

Dim b As Integer

a = Val(Text1.Text)

b = a Mod 10

Print b;

a = a \ 10

b = a Mod 10

Print b;

a = a \ 10

b = a Mod 10

Print b;

b = a \ 10

Print b;

End Sub


مجموع فرد 1 تا 100

Private Sub Command1_Click()

b = 0

For i = 1 To 100 Step 2

b = b + i

Next i

Print b

End Sub

OR

Private Sub Command1_Click()

b = 0

For i = 1 To 100

If (i Mod 2 <> 0) Then

c = c + i

End If

Next i

Print c

End Sub


فاکتوریل یک عدد

Private Sub Command1_Click()

Cls

b = 1

Dim a As Integer

a = Val(Text1.Text)

For i = a To 1 Step -1

b = b * i

Next i

Print b

End Sub


1

23

456

Private Sub Command1_Click()

a = 1

b = 1

For i = 1 To 6

Print i;

If ((a + i) Mod b = 0) Then

b = b + 1

Print

a = i

End If

Next i

End Sub


      *

    **

  ***

****

For i = 1 To 4

 For k = (4 - i) To 1 Step -1

 Print " ";

 Next k

 For j = 1 To i

 Print "*";

 Next j

Print

Next i


      *

    **

  ***

****

****

   ***

     **

       *

For i = 1 To 4

 For k = (4 - i) To 1 Step -1

 Print " ";

 Next k

 For j = 1 To i

 Print "*";

 Next j

Print

Next i

For i = 4 To 1 Step -1

 For k = (4 - i) To 1 Step -1

 Print " ";

 Next k

 For j = 1 To i

 Print "*";

 Next j

Print

Next i


    **

    ****

  ******

********

For i = 1 To 4

 For k = (4 - i) To 1 Step -1

 Print " ";

 Next k

 For j = 1 To i

 Print "**";

 Next j

Print

Next i

در دستورالعمل های ستاره می توان از برنامه های زیر نیز استفاده کرد:

1)For i = 1 To 4

 For j = 1 To i

  For k = (i * j) To 3

  Print " ";

  Next k

 Print "**";

 Next j

Print

Next i       

2)For i = 1 To 8 Step 2

  For k = 4 - (i / 2) To 1 Step -1

  Print " ";

  Next k

  For j = 1 To i

 Print "**";

 Next j

Print

Next i

اما از در ساختار ستاره برای تعداد بیشتر در هرم با مشکل مواجه خواهد شد.

این روش ها برای شکل های دیگر نیز به همین صورت مشکل ایجاد می کند.


     **

    ****

  ******

********

********

  ******

    ****

      **

For i = 1 To 4

 For k = (4 - i) To 1 Step -1

 Print " ";

 Next k

 For j = 1 To i

 Print "**";

 Next j

Print

Next i

For i = 4 To 1 Step -1

 For k = (4 - i) To 1 Step -1

 Print " ";

 Next k

 For j = 1 To i

 Print "**";

 Next j

Print

Next i


      **

    ****

  ******

********

       **

   ******

For i = 1 To 4

 For k = (4 - i) To 1 Step -1

 Print " ";

 Next k

 For j = 1 To i

 Print "**";

 Next j

Print

Next i

For i = 1 To 4 Step 2

 For k = (4 - i) To 1 Step -1

 Print " ";

 Next k

 For j = 1 To i

 Print "**";

 Next j

Print

Next i


ماشین حساب

Dim a As Long               

Dim opt As String

 

Private Sub Command1_Click()

Text1.Text = Text1.Text + "1"

End Sub

 

Private Sub Command10_Click()

a = Val(Text1.Text)

Text1.Text = "0"

opt = "/"

End Sub

 

Private Sub Command11_Click()

a = Val(Text1.Text)

Text1.Text = "0"

opt = "*"

End Sub

 

Private Sub Command12_Click()

a = Val(Text1.Text)

Text1.Text = "0"

opt = "-"

End Sub

 

Private Sub Command13_Click()

Text1.Text = Text1.Text + "0"

End Sub

 

Private Sub Command14_Click()

Text1.Text = " "

End Sub

 

Private Sub Command16_Click()

a = Val(Text1.Text)

Text1.Text = "0"

opt = "+"

End Sub

 

Private Sub Command17_Click()

Dim b As Long

b = Val(Text1.Text)

If (opt = "+") Then

Text1.Text = a + b

ElseIf (opt = "-") Then

Text1.Text = a - b

ElseIf (opt = "*") Then

Text1.Text = a * b

ElseIf (opt = "/") Then

Text1.Text = a / b

End If

End Sub

 

Private Sub Command2_Click()

Text1.Text = Text1.Text + "2"

End Sub

 

Private Sub Command3_Click()

Text1.Text = Text1.Text + "3"

End Sub

Private Sub Command4_Click()

Text1.Text = Text1.Text + "4"

End Sub

 

Private Sub Command5_Click()

Text1.Text = Text1.Text + "5"

End Sub

 

Private Sub Command6_Click()

Text1.Text = Text1.Text + "6"

End Sub

 

Private Sub Command7_Click()

Text1.Text = Text1.Text + "7"

End Sub

 

Private Sub Command8_Click()

Text1.Text = Text1.Text + "8"

End Sub

 

Private Sub Command9_Click()

Text1.Text = Text1.Text + "9"

End Sub


 

چراغ راهنمایی رانندگی

Private Sub Timer1_Timer()

If (Shape3.Visible = True) Then

Shape3.Visible = False

Shape4.Visible = True

Shape5.Visible = False

Timer1.Interval = 5000      اختیاری

Label1.Caption = Timer1.Interval

ElseIf (Shape4.Visible = True) Then

Shape3.Visible = False

Shape4.Visible = False

Shape5.Visible = True

Timer1.Interval = 8000     اختیاری

Label1.Caption = Timer1.Interval

ElseIf (Shape5.Visible = True) Then

Shape3.Visible = True

Shape4.Visible = False

Shape5.Visible = False

Timer1.Interval = 2000      اختیاری

Label1.Caption = Timer1.Interval

End If

End Sub


قرمز و زرد هشدار راهنمایی رانندگی

Private Sub Timer1_Timer()

If (Shape3.Visible = True) Then

Shape3.Visible = False

Shape4.Visible = True

Shape5.Visible = False

Timer1.Interval = 2000

ElseIf (Shape4.Visible = True) Then

Shape3.Visible = True

Shape4.Visible = False

Shape5.Visible = True

Timer1.Interval = 3000

ElseIf (Shape5.Visible = True) Then

Shape3.Visible = True

Shape4.Visible = False

Shape5.Visible = True

Timer1.Interval = 3000

End If

End Sub

 


نظرات()