1 / 33

BAZELE PROGRMARII PE OBIECTE PROIECTE IN VISUAL BASIC

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

neci
Download Presentation

BAZELE PROGRMARII PE OBIECTE PROIECTE IN VISUAL BASIC

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. BAZELE PROGRMARII PE OBIECTEPROIECTE 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. EXERCITIUL 1 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)

  6. EXERCITIUL 1 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 Forma OPEN Codul sursă aferent formei a II-a: Imports System Imports System.IO   Public Class Form2 Private Sub DriveListBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DriveListBox1.SelectedIndexChanged

  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. EX 2 / OPEN   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

  21. 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

  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

More Related