Você está na página 1de 4

Problema nr2.

S se realizeze un proiect Visual Basic prin care s se efectueze analiza


unui text preluat de la tastatur, din clipboard sau dintr-un fiier i s
se identifice cu memorare frazele, cuvintele i caracterele folosite n
text. S se contorizeze de cte ori apare fiecare dintre acestea. Accesul
s se fac pe nivele de prelucrare pe baz de parole, cu membri multipli,
actualizabile. Datele de intrare i rezultatele s se trec pe supori de
memorie extern.

Codul sursa este urmatorul:


Imports System.Data.OleDb
Public Class Form1
Dim provider As String
Dim dataFile As String
Dim connString As String
Dim myConnection As OleDbConnection = New OleDbConnection
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
provider = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source ="
'Change the following to your access database location
dataFile = "C:\Users\Carolina\Desktop\baze\Database1.mdb"
connString = provider & dataFile
myConnection.ConnectionString = connString
myConnection.Open()
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
'the query:
Dim cmd As OleDbCommand = New OleDbCommand("SELECT * FROM [users] WHERE
[utilizator] = '" & TextBox1.Text & "' AND [parola] = '" & TextBox2.Text & "'", myConnection)
Dim dr As OleDbDataReader = cmd.ExecuteReader
' the following variable is hold true if user is found, and false if user is not found
Dim userFound As Boolean = False

' the following variables will hold the user first and last name if found.
'if found:
While dr.Read
userFound = True
End While
'checking the result
If userFound = True Then
Form2.Show()
Else
MsgBox("Sorry, username or password not found", MsgBoxStyle.OkOnly, "Invalid Login")
End If
myConnection.Close()
End Sub
End Class

Codul sursa este urmatorul:


Public Class Form2
Dim v As String
Dim n As Integer
Dim i As Integer
Dim j As Integer
Dim nr As Integer
Dim aux As Integer
Dim aux1 As String
Dim ok As Integer
Dim aux3 As String
Private Sub Label1_Click(sender As Object, e As EventArgs) Handles Label1.Click

End Sub
Private Sub TextBox1_TextChanged(sender As Object, e As EventArgs) Handles
TextBox1.TextChanged
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
v = TextBox1.Text
'alocam un numar fisierului
Dim nrF As Integer = FreeFile()
'deschidem fisierul in modul Ouput - pt creare
FileOpen(nrF, "f:\fis1.txt", OpenMode.Output)
'scriem in fisier linie cu linie
'antetul

n = Len(v)
PrintLine(nrF, "Prelucrare text", TAB(20), v.ToString)
PrintLine(nrF, "Cuvant", TAB(20), "Numar de apariti")

Dim strSplit() As String


strSplit = v.Split(CChar(" "))
aux = strSplit.Length
RichTextBox1.AppendText("Textul original este : ' " + v + " ' ")
RichTextBox1.AppendText(Environment.NewLine)
For j = 0 To aux - 1
nr = 1
aux1 = strSplit(j)
ok = 0
For p = 0 To j - 1
If aux1 = strSplit(p) Then
ok = 1
End If
Next
If ok = 0 Then
For i = j + 1 To aux - 1
aux3 = strSplit(Str(i))
If String.Compare(aux1, aux3) = 0 Then
nr = nr + 1
End If
Next
PrintLine(nrF, aux1.ToString, TAB(20), nr.ToString)
RichTextBox1.AppendText("Cuvantul '" + aux1 + "' apare de " + Str(nr) + " ori ")
RichTextBox1.AppendText(Environment.NewLine)

End If
Next

FileClose(nrF)
End Sub
End Class

Você também pode gostar