Welcome to Dream.In.Code
Become a VB Expert!

Join 137,228 VB Programmers for FREE! Get instant access to thousands of VB experts, tutorials, code snippets, and more! There are 1,888 people online right now. Registration is fast and FREE... Join Now!




search module problem

 
Reply to this topicStart new topic

search module problem

danferd
9 Mar, 2007 - 10:24 PM
Post #1

New D.I.C Head
*

Joined: 9 Mar, 2007
Posts: 2


My Contributions
the problem i m facing now is, no matter what customer id i key in, the program still return "not in file" even there is such record in the text file!

thx for helping....




CODE

Structure Details
        Dim custID, lastName, firstName, add1, add2, state, city, email As String
        Dim icNo, zip, mobile, home, office As String
    End Structure
    Dim id(27) As Details
    Private Sub search_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim sr As IO.StreamReader = IO.File.OpenText("d:\data\cust.txt")
        For i As Integer = 0 To 27
            id(i).custID = sr.ReadLine
            id(i).icNo = sr.ReadLine
            id(i).lastName = sr.ReadLine
            id(i).firstName = sr.ReadLine
            id(i).add1 = sr.ReadLine
            id(i).add2 = sr.ReadLine
            id(i).zip = sr.ReadLine
            id(i).state = sr.ReadLine
            id(i).city = sr.ReadLine
            id(i).office = sr.ReadLine
            id(i).mobile = sr.ReadLine
            id(i).home = sr.ReadLine
            id(i).email = sr.ReadLine
        Next
        sr.Close()

    End Sub

    Private Sub btnSearch_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSearch.Click

        Dim searchID As String, result As String
        searchID = txt_searchID.Text.ToUpper
        result = FindID(searchID)
        If result >= 0 Then
            ShowData(result)
        Else
            MsgBox(searchID & " not in file", 0, "Not Found")
        End If

        
    End Sub

    Function FindID(ByVal searchID As String) As Integer
        'Binary search table for customer id
        Dim first, middle, last As Integer
        first = 0
        last = 27
        Do While (first <= last)
            middle = CInt(Int((first + last) / 2))
            Select Case id(middle).custID.ToUpper
                Case searchID
                    Return middle
                Case Is > searchID
                    last = middle - 1
                Case Is < searchID
                    first = middle + 1
            End Select
        Loop
        Return -1
    End Function

    Sub ShowData(ByVal result As Integer)
        txt_custID.Text = id(result).custID
        txt_icNo.Text = id(result).icNo
        txt_lastName.Text = id(result).lastName
        txt_1stName.Text = id(result).firstName
        txt_add1.Text = id(result).add1
        txt_add2.Text = id(result).add2
        txt_zip.Text = id(result).zip
        txt_state.Text = id(result).state
        txt_city.Text = id(result).city
        txt_office.Text = id(result).office
        txt_mobile.Text = id(result).mobile
        txt_home.Text = id(result).home
        txt_email.Text = id(result).email
    End Sub


This post has been edited by danferd: 10 Mar, 2007 - 02:49 AM
User is offlineProfile CardPM
+Quote Post

Jayman
RE: Search Module Problem
9 Mar, 2007 - 11:35 PM
Post #2

Student of Life
Group Icon

Joined: 26 Dec, 2005
Posts: 6,984



Thanked: 44 times
Dream Kudos: 500
Expert In: C#, VB.NET, Java

My Contributions
You have declared your variable result as a String but you are trying to store an Integer in it and use it as an Integer.
CODE
Dim searchID As String, result As String

Declare the variable as type Integer.
CODE

Dim searchID As String, result As Integer

User is offlineProfile CardPM
+Quote Post

danferd
RE: Search Module Problem
10 Mar, 2007 - 08:09 PM
Post #3

New D.I.C Head
*

Joined: 9 Mar, 2007
Posts: 2


My Contributions
QUOTE(jayman9 @ 10 Mar, 2007 - 12:35 AM) *

You have declared your variable result as a String but you are trying to store an Integer in it and use it as an Integer.
CODE
Dim searchID As String, result As String

Declare the variable as type Integer.
CODE

Dim searchID As String, result As Integer




it still can't solve the problem even i declare the variable result as type Integer.

This post has been edited by danferd: 10 Mar, 2007 - 08:11 PM
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 12/4/08 03:10PM

Live VB Help!

VB Tutorials

Reference Sheets

VB Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month