By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,776 Members | 1,351 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,776 IT Pros & Developers. It's quick & easy.

Unable to compare a string with a Structure

P: 1
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

Expand|Select|Wrap|Line Numbers
  1. Module Code
  2.  
  3. Module Module1
  4.     Structure EmailDataBase
  5.         <VBFixedString(25)> Public name As String
  6.         <VBFixedString(50)> Public email As String
  7.  
  8.     End Structure
  9.  
  10.     Public EmailContact As EmailDataBase
  11.  
  12.     Public Filename = "C:\database\email.dbf"
  13. End Module
  14.  
  15. First Part - Input data into file
  16.  
  17. Public Class Form2
  18.     Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
  19.  
  20.         Dim NextRecord As Integer
  21.         Dim SearchName As String
  22.         Dim RecordLength As Integer
  23.         SearchName = TextBox1.Text
  24.  
  25.         FileClose(1)
  26.  
  27.         RecordLength = Len(EmailContact)
  28.  
  29.         FileOpen(1, Filename, OpenMode.Random, OpenAccess.Default, OpenShare.Default, RecordLength)
  30.  
  31.         If LOF(1) < 1 Then NextRecord = 1 Else NextRecord = LOF(1) / RecordLength + 1
  32.  
  33.         EmailContact.name = TextBox1.Text
  34.         EmailContact.email = TextBox2.Text
  35.  
  36.         FilePut(1, EmailContact, NextRecord)
  37.  
  38.         Me.Close()
  39.         Form1.Close()
  40.  
  41.     End Sub
  42. End Class
  43.  
  44. Second Part - Find the email address by inputting Name
  45.  
  46. Public Class Form4
  47.     Private Sub Form4_Load(sender As Object, e As EventArgs) Handles MyBase.Load
  48.  
  49.     End Sub
  50.  
  51.     Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
  52.  
  53.         Dim SearchName As String
  54.         Dim SearchNameLower As String
  55.         Dim RecordLength As Integer = Len(EmailContact)
  56.         Dim RecordNo As Integer
  57.  
  58.         'following variables store emailcontact variables as ToLower
  59.  
  60.         Dim SearchEmail As String
  61.         Dim EmailName As String
  62.  
  63.         SearchName = TextBox1.Text
  64.         SearchNameLower = SearchName.ToLower
  65.  
  66.         FileClose(1)
  67.  
  68.         FileOpen(1, Filename, OpenMode.Random, OpenAccess.Default, OpenShare.Default, RecordLength)
  69.  
  70.         RecordNo = LOF(1) / Len(EmailContact)
  71.  
  72.         For x = 1 To RecordNo
  73.  
  74.             'If x > 1 Then x = x - 1
  75.  
  76.             FileGet(1, EmailContact, x)
  77.  
  78.             SearchEmail = (EmailContact.email.ToLower)
  79.             EmailName = EmailContact.name.ToLower
  80.  
  81.             If SearchNameLower = EmailName Then
  82.                 MsgBox("Match")
  83.             Else
  84.                 MsgBox("No Match")
  85.             End If
  86.  
  87.         Next x
  88.  
  89.  
  90.  
  91.     End Sub
  92. End Class
  93.  
  94.  
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
Apr 13 '16 #1
Share this question for a faster answer!
Share on Google+

Post your reply

Sign in to post your reply or Sign up for a free account.