X
تبلیغات
رایتل

دانشجویان مواد دانشگاه تجن

گرچه منزل بس خطرناک است و مقصد بس بعید، هیچ راهی نیست که آن را نیست پایان، غم مخور

1390/11/18 ساعت 11:12

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

حاصل جمع دو عدد

Private Sub Command1_Click()

Dim a As Integer

Dim b As Integer

Dim c As Integer

a = Val(Text1.Text)

b = Val(Text2.Text)

c = a + b

Text3.Text = Str(c)

End Sub


تغییر عنوان فرم

Private Sub Text1_Change()

Form1.Caption = Text1.Text

End Sub


مغلوب عدد دو رقمی

Private Sub Command1_Click()

Dim num1 As Integer

num1 = Val(Text1.Text)

Label3.Caption =Str(num1Mod 10)+ Str(num1\ 10(

End Sub


مجموع اعداد چهار رقمی

rivate Sub Command1_Click()

Dim num1 As Integer

Dim sum As Integer

num1 = Val(Text1.Text)

sum = sum + (num1 Mod 10)

num1 = num1 \ 10

sum = sum + (num1 Mod 10)

num1 = num1 \ 10

sum = sum + (num1 Mod 10)

num1 = num1 \ 10

sum = sum + num1

Label1.Caption = Str(sum)

End Sub


ابعاد فرم

Private Sub Command1_Click()

Dim a As Integer

Dim b As Integer

a = Val(Text1.Text)

b = Val(Text2.Text)

Form1.Height = Text1.Text

Form1.Width = Text2.Text

End Sub


رنگ فرم

Private Sub Command1_Click()

Form1.BackColor = vbBlue

End Sub

 

Private Sub Command2_Click()

Form1.BackColor = vbRed

End Sub


نتیجه ی 4 عمل اصلی

Private Sub Command1_Click()

Dim a As Integer

Dim b As Integer

Dim c As Integer

Dim d As Integer

Dim e As Integer

Dim f As Integer

a = Val(Text1.Text)

b = Val(Text2.Text)

c = a + b

d = a - b

e = a * b

f = a / b

Label1.Caption = Str(c)

Label7.Caption = Str(f)

Label3.Caption = Str(e)

Label5.Caption = Str(d)

End Sub


تبدیل دما

Private Sub Command1_Click()

Dim c As Single

Dim f As Single

c = Val(Text1.Text)

f = 1.8 * c + 32

Text2.Text = Str(f)

End Sub

 

Private Sub Command2_Click()

Dim c As Integer

Dim f As Integer

f = Val(Text2.Text)

c = (f - 32) / 1.8

Text1.Text = Str(c)

End Sub


تبدیل به ساعت و دقیقه و ثانیه

Private Sub Command1_Click()

Dim a As Long

Dim h As Long

Dim m As Long

Dim s As Long

a = Val(Text1.Text)

h = a / 3600

m = (a Mod 3600) / 60

s = (a Mod 60) / 1

Text2.Text = Str(h)

Text3.Text = Str(m)

Text4.Text = Str(s)

End Sub


عدد بزرگتر

Private Sub Command1_Click()

Dim a As Integer

Dim b As Integer

a = Val(Text1.Text)

b = Val(Text2.Text)

If (a > b) Then

Text3.Text = Str(a)

Else

Text3.Text = Str(b)

End If

End Sub


 

زوج و فرد بودن

Private Sub Command1_Click()

Dim a As Integer

a = Val(Text1.Text)

If (a Mod 2 = 0) Then

Text2.Text = "zoj ast"

Else

Text2.Text = "fard ast"

End If

End Sub


بخشپذیری بر 2 و 3 و 5

Private Sub Command1_Click()

Dim a As Integer

a = Val(Text1.Text)

If (a Mod 2 = 0) And (a Mod 3 = 0) And (a Mod 5 = 0) Then

Print "bar 2 va 3 va 5 bakhsh pazir ast"

ElseIf (a Mod 2 = 0) And (a Mod 3 = 0) Then

Print "bar 2 va 3 bakhsh pazir ast"

ElseIf (a Mod 2 = 0) And (a Mod 5 = 0) Then

Print "bar 2 va 5 bakhsh pazir ast"

ElseIf (a Mod 3 = 0) And (a Mod 5 = 0) Then

Print "bar 3 va 5 bakhsh pazir ast"

ElseIf (a Mod 2 = 0) Then

Print "bar 2 bakhsh pazir ast"

ElseIf (a Mod 3 = 0) Then

Print "bar 3 bakhsh pazir ast"

ElseIf (a Mod 5 = 0) Then

Print "bar 5 bakhsh pazir ast"

End If

End Sub


نمایش 1 تا 10 عمودی

Private Sub Command1_Click()

For i = 1 To 10 Step 1

Print i

Next i

End Sub


نمایش 1 تا 10 افقی

Private Sub Command1_Click()

For i = 1 To 10 Step 1

Print i;

Next i

End Sub


ضرب از طریق جمع

Private Sub Command1_Click()

Cls

z = 0

Dim a As Integer

Dim b As Integer

a = Val(Text1.Text)

b = Val(Text2.Text)

For i = 1 To b

z = z + a

Next i

Print z

End Sub


 

 

1

12

123

1234

For i = 1 To 4

 For j = 1 To i

 Print j;

 Next j

Print

Next i


1

22

333

4444

For i = 1 To 4

 For j = 1 To i

 Print i;

 Next j

Print

Next i


1

21

321

4321

Private Sub Command1_Click()

For i = 4 To 1 Step -1

 For j = i To 4

  Print 5 - j;

 Next j

Print

Next i

End Sub


1234

123

12

1

Private Sub Command1_Click()

For i = 4 To 1 Step -1

For j = 1 To i

 Print j;

 Next j

Print

Next i

End Sub


4

34

234

1234

Private Sub Command1_Click()

For i = 4 To 1 Step -1

For j = i To 4

 Print j;

 Next j

Print

Next i

End Sub


1  1

1  2

1  3

3  1

3  2

3  3

5  1

5  2

5  3

Private Sub Command1_Click()

For i = 1 To 5 Step 2

 For j = 1 To 3

  Print i, j

 Next j

Print

Next i

End Sub


*

**

***

****

***

**

*

For i = 1 To 4

 For j = 1 To i

 Print "*";

 Next j

Print

Next i

For i = 3 To 1 Step -1

 For j = 1 To i

 Print "*";

 Next j

Print

Next i


4

43

432

4321

For i = 1 To 4

 For j = 1 To i

 Print 5 - j;

 Next j

Print

Next i


معکوس 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

¢/div ساعت ساعت script language= /span ساعت ساعت br ساعت 0 ساعت BlogSky:Post Title / /h3 /h3 _blank/a div class=wgname/div لینک های روزانه/BlogSky:Author Body style= BlogSky:Weblog PostsHRef /h2 class= 0div class=div class= BlogSky:Weblog PostsHRef /h2 class= 0 ساعت رمز عبور: BlogSky:Post HRef /title/ul