473,387 Members | 1,535 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Unable to compare a string with a Structure

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
0 3026

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

Similar topics

3
by: Matt | last post by:
if (123 > 33) will return true and if ("123" > 33) will return true So my question is, if the above behaviors are the same?? If string is a number, and compare with another number, it will...
10
by: tvn007 | last post by:
#include <iostream> #include <string> int main (void){ using namespace std; string STR =("TEST"); const std::string::size_type STR_SIZE = STR.size(); int count =0; while ( count <=...
3
by: Leo Nunez | last post by:
Hello! I need copy from structure "A" to "B" that contains "strings" in a one line code. Me problem like this : typedef struct tHeader{ char field1; char field2; char field3;
3
by: Kiran B. | last post by:
Hi, I am new to .net. I have two Data Structure Type ... Sturcture A and Structure B. Structure A Public Fname as String Public LastName as String Public City as String Public Zip as String...
2
Soujiro
by: Soujiro | last post by:
typedef struct { int age; string name; } structure; int functionCall( map< char* , structure* >* map_o ) { map< char* , structure* >* map_op; map_op = map_o;
10
by: lovecreatesbea... | last post by:
Is it correct and safe to compare a string object with "", a pair of quotation marks quoted empty string?If the string object: s = ""; does s contain a single '\'? Is it better to use...
1
by: swapnilladhe | last post by:
Hi, I have a array of string and a variable containing string and i code like as; if(String.compare(DFArray,checkBox.name)==0) { alert("R U HERE?"); f=false; ...
7
pureenhanoi
by: pureenhanoi | last post by:
Hi bro! Can anyone tell me, how to compare two strings like Operating System compare file names. Example: if i have two string "T*.DOC" and "TIET1.DOC". The comparision operator must return TRUE...
4
by: ndoe | last post by:
how to compare string in file i mean compare that string content digit or alphabet,and 1 question more can we count that line if first line variable = 1,if read second line variable = 2 and so on...
6
by: Kilavo | last post by:
I'm developing a system which I want to locate different places. Have the database which contain some Latitude and longitude and want to compare with the one received from the GPS through GSM modem...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.