Sunteți pe pagina 1din 13

1. S se realizeze o aplicaie care s permit afiarea produselor din dou nomenclatoare, fiecare n cte o list.

La apsarea unui buton de comand elementele selectate din prima list s se mute n cea de- a doua list. La apsarea unui alt buton de comand toate elementele din prima list s se mute n cea de - a doua list. Alte dou butoane s permit apoi aceleai operaii din lista2 n lista1. Rezolvare:

n casetele de tip Text de sub cele dou liste dorim s afim, atunci cnd se face un clic mouse n interiorul unei liste, numrul de elemente din lista respectiv. Codul aferent procedurilor scrise se prezint astfel:
Public Class Form1 Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click End End Sub Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click ' Dim b As Integer If ListBox1.Items.Count > 0 Then 'b = ListBox1.SelectedIndex For i = 0 To ListBox1.Items.Count - 1 If ListBox1.GetSelected(i) = True Then Me.ListBox2.Items.Add(Me.ListBox1.Items.Item(i)) End If Next i 'Me.ListBox1.Items.RemoveAt(b) End If End Sub Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click If ListBox1.Items.Count > 0 Then ListBox2.Items.Clear() For i = 0 To ListBox1.Items.Count - 1 Me.ListBox2.Items.Add(Me.ListBox1.Items.Item(i))

Next i End If End Sub Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click 'Dim c As Integer If ListBox2.Items.Count > 0 Then 'c = ListBox2.SelectedIndex For i = 0 To ListBox2.Items.Count - 1 If ListBox2.GetSelected(i) = True Then Me.ListBox1.Items.Add(Me.ListBox2.Items.Item(i)) End If Next i ' Me.ListBox2.Items.RemoveAt(c) End If End Sub Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click If ListBox2.Items.Count > 0 Then ListBox1.Items.Clear() For i = 0 To ListBox2.Items.Count - 1 Me.ListBox1.Items.Add(Me.ListBox2.Items.Item(i)) Next i End If End Sub Private Sub ListBox1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles ListBox1.Click TextBox1.Text = ListBox1.Items.Count End Sub Private Sub ListBox2_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles ListBox2.Click TextBox2.Text = ListBox2.Items.Count End Sub End Class

2. S se realizeze un alt calculator simplu, n care operaiile de calcul s corespund unor butoane de opiuni (butoane radio).

Rezolvare:

Codul surs aferent procedurilor va fi n acest caz:


Public Class Form1 Dim n As Double Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click End End Sub Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click On Error Resume Next If RadioButton1.Checked = True Then TextBox3.Text = Val(TextBox1.Text) + Val(TextBox2.Text) ElseIf RadioButton2.Checked = True Then TextBox3.Text = Val(TextBox1.Text) - Val(TextBox2.Text) ElseIf RadioButton3.Checked = True Then TextBox3.Text = Val(TextBox1.Text) * Val(TextBox2.Text) ElseIf RadioButton4.Checked = True Then If TextBox2.Text = "0" Then MsgBox("Nu se poate imparti la 0", vbCritical, "Eroare") TextBox2.Text = "" Else TextBox3.Text = Val(TextBox1.Text) / Val(TextBox2.Text) End If ElseIf RadioButton5.Checked = True Then TextBox2.Text = "0" TextBox2.Enabled = False If Val(TextBox1.Text) < 0 Then MsgBox("Nu se poate extrage radical de ordin 2 din numere negative", vbCritical, "Eroare") Else n = Val(TextBox1.Text) TextBox3.Text = System.Math.Sqrt(n) End If

End If TextBox2.Enabled = True End Sub Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load TextBox1.Text = "0" TextBox2.Text = "0" TextBox3.Text = "0" End Sub Private Sub RadioButton5_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton5.CheckedChanged TextBox2.Enabled = False End Sub End Class

3. S se proiecteze i s se realizeze o aplicaie care s permit analiza unui text introdus de la tastatur, afiarea primului cuvnt i apoi la cerere a urmtoarelor cuvinte din text. S se afieze deasemenea numrul de caractere din text.

Rezolvare:

Public Class Form1 Dim cuv As String Dim lung As Integer Dim i1 As Integer Dim i As Integer Dim a As Integer Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click End End Sub Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click LTrim(Me.TextBox1.Text) Text = Me.TextBox1.Text lung = Len(Text) Me.TextBox3.Text = Len(Text) a = InStr(Text, " ") i = 1 cuv = Mid(Text, i, a) Me.TextBox2.Text = cuv i = a End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click a = InStr(Text, " ") If i < lung - a Then a = InStr(Mid(Text, i + 1, lung - i), " ") cuv = Mid(Text, i, a) Me.TextBox2.Text = cuv Me.Refresh() i = i + a Else cuv = Mid(Text, i, a) Me.TextBox2.Text = cuv Me.Refresh() End If End Sub End Class

4.S se realizeze un program care s calculeze maximul i minimul pentru liniile i coloanele unei matrici ce se va introduce de la tastatur.

Se cere de la tastatur numrul de linii i apoi, n mod asemntor, numrul de coloane. Prin intermediul unei ferestre de dialog urmeaz precizarea valorii tuturor elementelor matricei noastre. La sfrit se calculeaz i se afieaz rezultatele obinute.

Codul surs aferent se prezint astfel:


Public Class Form1 Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click End End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim a(0 To 100, 0 To 100) Dim i, j, n, m As Integer Dim maxL(0 To 100), maxC(0 To 100) As Integer Dim maxLi, maxCi As Integer Dim minL(0 To 100), minC(0 To 100) As Integer Dim minLi, minCi As Integer Dim pauza As String pauza = Chr(13) & Chr(10) Label1.Text = "" Label2.Text = "" n = InputBox("Introduceti numarul liniilor", "N=") m = InputBox("introduceti numarul coloanelor", "M=") For i = 1 To n For j = 1 To m a(i, j) = InputBox("A (" & i & "," & j & ") =") Label3.Text = Label3.Text & a(i, j) & " " Next j Label3.Text = Label3.Text & pauza Next i For i = 1 To n maxLi = a(i, 1) For j = 2 To m If maxLi < a(i, j) Then maxLi = a(i, j) End If Next j maxL(i) = maxLi Next i For j = 1 To m maxCi = a(1, j) For i = 2 To n If maxCi < a(i, j) Then maxCi = a(i, j) End If Next i maxC(j) = maxCi Next j For i = 1 To n minLi = a(i, 1) For j = 2 To m If minLi > a(i, j) Then minLi = a(i, j) End If Next j minL(i) = minLi Next i For j = 1 To m minCi = a(1, j) For i = 2 To n If minCi > a(i, j) Then minCi = a(i, j) End If Next i minC(j) = minCi Next j

&

"

&

"

Label3.Text = Label3.Text & pauza For i = 1 To n Label3.Text = Label3.Text & "Maximul maxL(i) & pauza Next i Label3.Text = Label3.Text & pauza For j = 1 To m Label3.Text = Label3.Text & "Maximul & maxC(j) & pauza Next j Label3.Text = Label3.Text & pauza For i = 1 To n Label3.Text = Label3.Text & "Minimul minL(i) & pauza Next i Label3.Text = Label3.Text & pauza For j = 1 To m Label3.Text = Label3.Text & "Minimul & minC(j) & pauza Next j End Sub

de pe Linia " & i & " este "

de pe Coloana " & j & " este

de pe Linia " & i & " este "

de pe Coloana " & j & " este

End Class

5. S se realizeze o mic aplicaie care s analizeze, ntr -un text dat, tipul caracterelor: majuscule sau caractere mici. Rezolvare: Textul se va introduce n caseta de text i rezultatul se va afia chiar pe formular. Am realizat dou proceduri de tip funcie, care stabilesc, pentru fiecare liter n parte, dac este majuscul sau nu, testnd codul ASCII al acestora. Se tie c pentru majuscule codul Ascii are valori cuprinse ntre 65 i 90, iar pentru literele mici ntre 97 i 122. Executnd aplicaia noastr se obine:

Codul surs se prezint astfel:


Public Class Form1 Public Function IsUpper(ByVal CheckLetter As String) As Boolean IsUpper = True If Asc(CheckLetter) < 65 Or Asc(CheckLetter) > 90 Then IsUpper = False End If End Function Public Function IsLower(ByVal CheckLetter As String) As Boolean IsLower = True If Asc(CheckLetter) < 97 Or Asc(CheckLetter) > 122 Then IsLower = False End If End Function Public Sub Main() Console.WriteLine(IsUpper("A")) Console.WriteLine(IsUpper("a")) Console.WriteLine(IsLower("A")) Console.WriteLine(IsLower("a"))

Console.ReadLine() End Sub Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim x As String Dim y As Integer Dim g As Boolean Dim enter As String x = TextBox1.Text y = Len(x) enter = Chr(13) & Chr(10) For i = 1 To y g = IsUpper(Mid(x, i, 1)) If g = "True" Then Label2.Text = Label2.Text & "Caracterul " & i & " este MAJUSCULA" & enter Else Label2.Text = Label2.Text & "Caracterul " & i & " este litera mica " & enter End If Next i End Sub End Class

S-ar putea să vă placă și