Presentation is loading. Please wait.

Presentation is loading. Please wait.

1/31 5/6/2014 BAZELE PROGRMARII PE OBIECTE PROIECTE IN VISUAL BASIC Conf univ dr Botezatu Cezar INFORMATICĂ MANAGERIALĂ Anul I. STUDII DE LICENŢĂ.

Similar presentations


Presentation on theme: "1/31 5/6/2014 BAZELE PROGRMARII PE OBIECTE PROIECTE IN VISUAL BASIC Conf univ dr Botezatu Cezar INFORMATICĂ MANAGERIALĂ Anul I. STUDII DE LICENŢĂ."— Presentation transcript:

1 1/31 5/6/2014 BAZELE PROGRMARII PE OBIECTE PROIECTE IN VISUAL BASIC Conf univ dr Botezatu Cezar INFORMATICĂ MANAGERIALĂ Anul I. STUDII DE LICENŢĂ

2 EXERCITIUL 1 S ă se proiecteze şi s ă se realizeze o aplicaţie care s ă permit ă analiza unui text introdus de la tastatur ă, afişarea primului cuvânt şi apoi la cerere a urm ă toarelor cuvinte din text. S ă se afişeze deasemenea num ă rul de caractere din text.

3 EXERCITIUL 1 Rezolvare: Definim o form ă

4 EXERCITIUL 1 Public Class Form1 Dim cuv As String Dim lung As Integer Dim i1 As Integer Dim i As Integer Dim a As Integer Dim texta as string

5 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 Text = LTrim(Me.TextBox1.Text) lung = Len(Text) EXERCITIUL 1

6 Me.TextBox3.Text = Len(Text) a = InStr(Text, " ") i = 1 cuv = Mid(Text, i, a) Me.TextBox2.Text = cuv i = i+a Me.Button1.Enable=FALSE End Sub

7 EXERCITIU Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click Text = LTrim(Me.TextBox1.Text) iF I >0 then I1=I Else i1=1 endif a = InStr(Text, " ") If i1< lung - a Then a = InStr(Mid(Text, i1 + 1, lung – i1), " ") cuv = Mid(Text, i1, a) Me.TextBox2.Text = cuv Me.Refresh() i 1= i1 + a Else cuv = Mid(Text, i1, a) Me.TextBox2.Text = cuv Me.Refresh() End If End Sub End Class

8 EXERCITIUL 1 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

9 EXERCITIUL 1 Else cuv = Mid(Text, i, a) Me.TextBox2.Text = cuv Me.Refresh() End If End Sub End Class

10 EXERCITIUL 1 Rezultatul:

11 EXERCITIUL 2. S ă se realizeze un editor de texte, care s ă permit ă introducerea unui text de la tastatur ă şi apoi salvarea lui pe disc prin intermediul unei ferestre de dialog. Editorul trebuie s ă permit ă şi deschiderea unui fişier existent în vederea edit ă rii. Rezolvare: Definim trei forme: Forma de lucru”Editor de texte”; Forma OPEN Forma SAVE

12 EXERCITIUL 2 EDITOR DE TEXTE

13 EXERCITIUL 2 Forma OPEN

14 EXERCITIUL 2 Forma SAVE

15 EXERCITIUL 2 Codul surs ă aferent primei forme: Imports System Imports System.IO Public Class Form1 Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click End End Sub

16 EXERCITIUL 2 Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System. EventArgs) Handles Button3.Click TextBox1.Text = "" End Sub Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System. EventArgs) Handles Button1.Click Form2.Show() Form2.TextBox1.Text = "" Form2.TextBox2.Text = ""

17 EXERCITIUL 2 On Error Resume Next : Me.Hide() End Sub Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System. EventArgs) Handles Button2.Click Form3.Show() Me.Hide() End Sub End Class

18 EXERCITIUL 2 Codul surs ă aferent formei a II-a: Imports System Imports System.IO Public Class Form2 Private Sub DriveListBox1_SelectedIndexChanged(ByV al sender As System.Object, ByVal e As System.EventArgs) Handles DriveListBox1.SelectedIndexChanged Forma OPEN

19 EX 2 / OPEN Try DirListBox1.Path=DriveListBox1.Drive Catch End Try TextBox1.Text = DirListBox1.Text End Sub Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System. EventArgs) Handles Button2.Click Form1.Show() Me.Hide() End Sub

20 PrivateSubDirListBox1_SelectedIndex Changed(ByVal sender As System. Object, ByVal e As System.EventArgs) Handles DirListBox1.SelectedIndex Changed Try FileListBox1.Path =DirListBox1.Path Catch End Try TextBox1.Text = DirListBox1.Text End Sub EX 2 / OPEN

21 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Me.TextBox1.Text =Me.TextBox1.Text & Me.TextBox2.Text & Me.FileListBox1. SelectedItem Try Using fisier As StreamReader = New StreamReader(Me.TextBox1.Text) Dim linie As String

22 EX 2 / OPEN Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Me.TextBox1.Text = Me.TextBox1.Text & Me.TextBox2.Text & Me.FileListBox1.SelectedItem Try Using fisier As StreamReader = New StreamReader(Me.TextBox1.Text) Dim linie As String Do linie = fisier.ReadLine() Form1.TextBox1.Text = Form1.TextBox1.Text & linie Loop Until linie Is Nothing fisier.Close() End Using Catch End Try Form1.Show() Me.Hide() End Sub Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load TextBox2.Text = "" TextBox1.Text = "" Me.DirListBox1.Refresh() Me.FileListBox1.Refresh() Me.DriveListBox1.Refresh() End Sub Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged FileListBox1.Pattern = Me.ComboBox1.Text End Sub End Class

23 EX 2 / OPEN linie = fisier.ReadLine() Form1.TextBox1.Text = Form1.TextBox1. Text & linie Loop Until linie Is Nothing fisier.Close() End Using Catch End Try Form1.Show() Me.Hide() End Sub

24 EX 2 / OPEN Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load TextBox2.Text = "" TextBox1.Text = "" Me.DirListBox1.Refresh() Me.FileListBox1.Refresh() Me.DriveListBox1.Refresh() End Sub

25 EX 2 / OPEN Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged FileListBox1.Pattern = Me.ComboBox1.Text End Sub End Class

26 EX 2 / SAVE Codul aferent formei a treia se prezint ă astfel: Imports System Imports System.IO Public Class Form3 Private Sub DriveListBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DriveListBox1.SelectedIndexChanged

27 EX 2 / SAVE Try DirListBox1.Path = DriveListBox1.Drive Catch End Try TextBox2.Text = DirListBox1.Text End Sub Private Sub DirListBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DirListBox1.SelectedIndexChanged

28 EX 2 / SAVE Try FileListBox1.Path = DirListBox1.Path Catch End Try TextBox3.Text = Me.TextBox3.Text & Me.DirListBox1.SelectedItem & "\" End Sub Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles

29 EX 2 / SAVE ComboBox1.SelectedIndexChanged FileListBox1.Pattern = Me.ComboBox1. Text End Sub Private Sub Form3_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load TextBox1.Text = "" TextBox2.Text = "" TextBox3.Text = "" End Sub

30 EX 2 / SAVE Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System. EventArgs) Handles Button2.Click Form1.Show() Me.Hide() End Sub Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click TextBox1.Focus()

31 EX 2 / SAVE If TextBox1.Text = "" Then MessageBox.Show("Nu ati introdus numele fisierului!!!", "Atentie", Message BoxButtons.OK, MessageBoxIcon.Warning) Else TextBox4.Text = Me.TextBox2.Text & TextBox3.Text & TextBox1.Text Using fisier As StreamWriter = New StreamWriter(TextBox4.Text) fisier.WriteLine(Form1.TextBox1.Text) fisier.WriteLine(DateTime.Now)

32 EX 2 / SAVE fisier.Close() MessageBox.Show("Fisierul a fost salvat in " & Me.TextBox4.Text, "Save", Message BoxButtons.OK,MessageBoxIcon.Question) End Using End If End Sub End Class

33 END


Download ppt "1/31 5/6/2014 BAZELE PROGRMARII PE OBIECTE PROIECTE IN VISUAL BASIC Conf univ dr Botezatu Cezar INFORMATICĂ MANAGERIALĂ Anul I. STUDII DE LICENŢĂ."

Similar presentations


Ads by Google