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

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

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

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

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


نظرات()