8 Replies - 431 Views - Last Post: 02 February 2013 - 03:33 PM Rate Topic: -----

#1 EmbraceTheNight  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 12
  • Joined: 31-January 13

Autocomplete data source question?

Posted 02 February 2013 - 12:51 PM

For the autocomplete functionality of text boxes. Is it possible to use a file containing records as a data source?

For example could I get suggestions from reading the records from a file named "FileExample.dat"
Is This A Good Question/Topic? 0
  • +

Replies To: Autocomplete data source question?

#2 andrewsw  Icon User is offline

  • Fire giant boob nipple gun!
  • member icon

Reputation: 3460
  • View blog
  • Posts: 11,727
  • Joined: 12-December 12

Re: Autocomplete data source question?

Posted 02 February 2013 - 01:30 PM

Yes, you would change the property AutoCompleteSource to CustomSource and then programmatically set AutoCompleteCustomSource to a StringCollection extracted from your data-file.

I'm not sure if the extension .dat might be an issue but, presumably, it can be read as a text file. (Does it need to be a .dat file?)

MSDN

This post has been edited by andrewsw: 02 February 2013 - 01:31 PM

Was This Post Helpful? 1
  • +
  • -

#3 EmbraceTheNight  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 12
  • Joined: 31-January 13

Re: Autocomplete data source question?

Posted 02 February 2013 - 01:46 PM

View Postandrewsw, on 02 February 2013 - 01:30 PM, said:

Yes, you would change the property AutoCompleteSource to CustomSource and then programmatically set AutoCompleteCustomSource to a StringCollection extracted from your data-file.

I'm not sure if the extension .dat might be an issue but, presumably, it can be read as a text file. (Does it need to be a .dat file?)

MSDN


It does not have to be a .dat file no, I could make up any extension. Do you have any idea how I would extract a string collection? My attempts so far have resulted in errors to do with string being unable to be converted to type integer? In my file structure there's a fixed string item called Username, would I be able to source the string collection from that field from my records?

Sorry if I don't seem very informed, I've never used this functionality before.
Was This Post Helpful? 0
  • +
  • -

#4 andrewsw  Icon User is offline

  • Fire giant boob nipple gun!
  • member icon

Reputation: 3460
  • View blog
  • Posts: 11,727
  • Joined: 12-December 12

Re: Autocomplete data source question?

Posted 02 February 2013 - 01:53 PM

What does your data-file content look like?
You'll need to show some code as well.

BUT You should read the link that I referenced. Have you done that?

This post has been edited by andrewsw: 02 February 2013 - 01:54 PM

Was This Post Helpful? 0
  • +
  • -

#5 EmbraceTheNight  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 12
  • Joined: 31-January 13

Re: Autocomplete data source question?

Posted 02 February 2013 - 02:00 PM

Structure CustomerInformation
        <VBFixedString(11)> Dim CustomerUniqueID As String
        <VBFixedString(15)> Dim CustomerForename As String
        <VBFixedString(15)> Dim CustomerSurname As String
        <VBFixedString(8)> Dim CustomerDOB As String
        <VBFixedString(1)> Dim Gender As Char
        <VBFixedString(20)> Dim AddressLine1 As String
        <VBFixedString(20)> Dim AddressLine2 As String
        <VBFixedString(10)> Dim County As String
        <VBFixedString(30)> Dim Email As String
        <VBFixedString(15)> Dim ContactNumber As String
    End Structure


Above is the record structure of the file I'm trying to use as a source, In the .dat file itself, the record is a long line containing variable for each of the above field.

I did read the link yes,
Dim MySource As New AutoCompleteStringCollection()
    MySource.AddRange(New String() _

The above seemed promising, I was wondering if I could utilize that code somehow.
Was This Post Helpful? 0
  • +
  • -

#6 andrewsw  Icon User is offline

  • Fire giant boob nipple gun!
  • member icon

Reputation: 3460
  • View blog
  • Posts: 11,727
  • Joined: 12-December 12

Re: Autocomplete data source question?

Posted 02 February 2013 - 02:09 PM

Do you have the code that creates/writes to the .dat file? Essentially, you need to reverse that code to feed the data back into an array of structures, and then loop through this array extracting the Username (or forename and surname combination?) into a StringCollection.
Was This Post Helpful? 1
  • +
  • -

#7 EmbraceTheNight  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 12
  • Joined: 31-January 13

Re: Autocomplete data source question?

Posted 02 February 2013 - 02:14 PM

some global variables
Dim Customer As CustomerInformation
    Dim CustomerInfo As String 
    Dim NumberOfRecords As Integer = 0


The writing of records to a file is contained within a button on the form
Private Sub btnAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAdd.Click
        'declare customer record variables 
        Customer.CustomerForename = tbForename.Text
        Customer.CustomerSurname = tbSurname.Text
        Customer.CustomerDOB = tbDOB.Text
        Customer.CustomerUniqueID = tbUsername.Text
        Customer.AddreesLine1 = tbAddressLine1.Text
        Customer.AddressLine2 = tbAddressLine2.Text
        Customer.Email = tbEmail.Text
        Customer.County = tbCounty.Text
        Customer.ContactNumber = tbMobile.Text

        'Open the Customer file
        FileOpen(1, CustomerInfo, OpenMode.Random, , , Len(Customer))
        'Add record to the customer file
        FilePut(1, Customer, NumberOfRecords + 1)
        'Close the Customer file
        FileClose(1)
        'Update the number of customer records
        NumberOfRecords = NumberOfRecords + 1

        'Remove entered information from the data capture items 
        tbForename.Text = ""
        tbSurname.Text = ""
        tbDOB.Text = ""
        tbUsername.Text = ""
        tbAddressLine1.Text = ""
        tbAddressLine2.Text = ""
        tbEmail.Text = ""
        tbCounty.Text = ""
        tbMobile.Text = ""
        cboGender.Text = ""

    End Sub

Was This Post Helpful? 0
  • +
  • -

#8 andrewsw  Icon User is offline

  • Fire giant boob nipple gun!
  • member icon

Reputation: 3460
  • View blog
  • Posts: 11,727
  • Joined: 12-December 12

Re: Autocomplete data source question?

Posted 02 February 2013 - 02:36 PM

Well the FileOpen method is essentially the same, and the opposite to FilePut is FileGet.

You'll probably need to put the FileGet in a loop as you are unlikely to know the length of the file (the number of CustomerInformation structures) and loop until the end of the file is reached.

You would probably add each returned customer into a list:

Dim gotCustomers As List(Of CustomerInformation)

You could eventually do everything in a single loop, but initially break it down to separate steps.

Good luck!

This post has been edited by andrewsw: 02 February 2013 - 02:41 PM

Was This Post Helpful? 0
  • +
  • -

#9 AdamSpeight2008  Icon User is offline

  • MrCupOfT
  • member icon


Reputation: 2262
  • View blog
  • Posts: 9,462
  • Joined: 29-May 08

Re: Autocomplete data source question?

Posted 02 February 2013 - 03:33 PM

A lot of the methods and functions you are using are the old VB6 (crutches), in fact it looks like you've just use the upgrade wizard.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1