Hi,
I'm new to Visual basic. I am currently writing a small program that stores a person's name and email address into a simple database. See code below
The problem I am having issues with is in relation to matching the name to the email address in my small database file. When I try and match the name input from textbox1 against the name in the database, the search function is not displaying correctly whether the match is correct or not. I hope this makes sense.
Ive tried to google the answer, use StrComp, String.Equal and String.Compare with no luck.
Any ideas gratefully received
Thanks in advance
I'm new to Visual basic. I am currently writing a small program that stores a person's name and email address into a simple database. See code below
Code:
Module Code
Module Module1
Structure EmailDataBase
<VBFixedString(25)> Public name As String
<VBFixedString(50)> Public email As String
End Structure
Public EmailContact As EmailDataBase
Public Filename = "C:\database\email.dbf"
End Module
First Part - Input data into file
Public Class Form2
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim NextRecord As Integer
Dim SearchName As String
Dim RecordLength As Integer
SearchName = TextBox1.Text
FileClose(1)
RecordLength = Len(EmailContact)
FileOpen(1, Filename, OpenMode.Random, OpenAccess.Default, OpenShare.Default, RecordLength)
If LOF(1) < 1 Then NextRecord = 1 Else NextRecord = LOF(1) / RecordLength + 1
EmailContact.name = TextBox1.Text
EmailContact.email = TextBox2.Text
FilePut(1, EmailContact, NextRecord)
Me.Close()
Form1.Close()
End Sub
End Class
Second Part - Find the email address by inputting Name
Public Class Form4
Private Sub Form4_Load(sender As Object, e As EventArgs) Handles MyBase.Load
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim SearchName As String
Dim SearchNameLower As String
Dim RecordLength As Integer = Len(EmailContact)
Dim RecordNo As Integer
'following variables store emailcontact variables as ToLower
Dim SearchEmail As String
Dim EmailName As String
SearchName = TextBox1.Text
SearchNameLower = SearchName.ToLower
FileClose(1)
FileOpen(1, Filename, OpenMode.Random, OpenAccess.Default, OpenShare.Default, RecordLength)
RecordNo = LOF(1) / Len(EmailContact)
For x = 1 To RecordNo
'If x > 1 Then x = x - 1
FileGet(1, EmailContact, x)
SearchEmail = (EmailContact.email.ToLower)
EmailName = EmailContact.name.ToLower
If SearchNameLower = EmailName Then
MsgBox("Match")
Else
MsgBox("No Match")
End If
Next x
End Sub
End Class
Ive tried to google the answer, use StrComp, String.Equal and String.Compare with no luck.
Any ideas gratefully received
Thanks in advance