Q re: Random Access Files, data-aware obj...

  • (13 Pages)
  • +
  • 1
  • 2
  • 3
  • Last »

190 Replies - 12351 Views - Last Post: 23 June 2011 - 04:46 PM Rate Topic: -----

#1 chuckjessup  Icon User is offline

  • D.I.C Regular

Reputation: 33
  • View blog
  • Posts: 380
  • Joined: 26-October 09

Q re: Random Access Files, data-aware obj...

Posted 16 February 2011 - 06:35 PM

OK I know that this is probably a silly question, but I am going to ask it anyway...

I am using a series of random access files, to orchestrated a relatively linked flat file database. I hate MSAccess as I have had serious issues with it in the past. However when I am attempting to use say a combo box, I would like the data from the test.rnd file (the one that holds the information that I want loaded in the combo box) but the data X properties wont allow me to use the random acces files to be directly linked to the combo box, and when i try to use a data control object (e.g. Data1) and set it to the "text;" setting for the connection, and the database name "test.rnd" it gives me an error with the Jet connector, "Couldn't Find Installable ISAM", when i attempt to use the ODBC connector, it also gives an error, "Invalid Argument"...

Is there a way to either to get the data control to work with my random access files? Or is there a way to get my random access files to interact with data-aware, and or data-bound controls? With out using some other form of databases...

Most of my random access files only have a no more than 200 records, and thats only one, most have less than 50 records... other db's have too much "overhead" to deal with for what i am doing... which basicly is fill controls with the data from the random access files, based on the selection (which are linked to other relevant RA files to populate them with the needed information... the reason is that i had been working with sequential files, and am now trying to eliminate the extra files that aren't needed a with the random access files because they are set in record sets... For example of what i want to do....

I have a RA file named Speaker.rnd, this contains SpkId, SpkName Fields... Then there is a RA file named Talks.rnd, this contains the fields, TlkId, TlkNumber, TlkCategory, and TlkTheme
when you set the speaker with a set number of talks it creates a new random access file with the following fields... TlkId, TlkPosition; This will open the Talks.rnd and will pull the TlkTheme field and set it to a label when the speaker and the talk number is selected... This is saving a pretty complex explanation, but its what i can say to try to explain the basic idea, since with seq files, i would have at least 6 steps and three more files to deal with...

Any help or suggestions should be appreciated, i haven't really found much on my Google searched on what to use to get what i would like done done...

Jesse Fender

Is This A Good Question/Topic? 0
  • +

Replies To: Q re: Random Access Files, data-aware obj...

#2 BobRodes  Icon User is online

  • Your Friendly Local Curmudgeon
  • member icon

Reputation: 573
  • View blog
  • Posts: 2,989
  • Joined: 19-May 09

Re: Q re: Random Access Files, data-aware obj...

Posted 18 February 2011 - 09:00 AM

You can directly access text files using the ADO data control. You're better off using the ADO Class library, though. Suppose you post your code and let us have a look at it. (Put it in code tags)
Was This Post Helpful? 0
  • +
  • -

#3 chuckjessup  Icon User is offline

  • D.I.C Regular

Reputation: 33
  • View blog
  • Posts: 380
  • Joined: 26-October 09

Re: Q re: Random Access Files, data-aware obj...

Posted 19 February 2011 - 01:40 PM

View PostBobRodes, on 18 February 2011 - 08:00 AM, said:

You can directly access text files using the ADO data control. You're better off using the ADO Class library, though. Suppose you post your code and let us have a look at it. (Put it in code tags)


The problem is that i am still working out the code.... it seems that Random Access Files, are not compatible with the datacontrol. It however has been proving to be much more difficult to deal with than i had hoped it would have been... in my mind, the random access files would provide a simple way for me to store and retreive the information stored in them to be called up and placed with in the programs forms... there are three programs that i want to convert from a severely crippling file system "database" which were bulky and could be edited by opening the files and editing them (Not want i want) because it needs to be used to direct to the right files... in their case directories... the issues wityh this should be obvious.... and the reason that i dont want to go with a full on db software, is that it has given me issues in the past where the database was empty and it freaked out... it was just plain old nightmare... However i can create and use random access files to tuck the information into, and that part works great, the part i am having issues with is the reading them into the form controls... I will work with the code and hopefuly post it later today(or evening) at the latest next saturday...

Jesse Fender
Was This Post Helpful? 0
  • +
  • -

#4 chuckjessup  Icon User is offline

  • D.I.C Regular

Reputation: 33
  • View blog
  • Posts: 380
  • Joined: 26-October 09

Re: Q re: Random Access Files, data-aware obj...

Posted 19 February 2011 - 10:34 PM

OK the following is a general information i have compiled so far... now forgive the well simplicity of the code i an just started working with Random Access Files. and well am not quite proficient in the matter of trying to connect ado... dao or any other controls to control and feed information to the program. The idea was to send the data to a dll and have th dll process the information and send it back to the program, this so far has been out of reach. but the code i have so far i will try to add and explain what i am trying to do... But my main need ATM is to get the data control to interface with my random access files, when they can do that i should be able to start implementing the data into the programs ( I have a "test" app. and a RAF named "Test.txt") The program uses a few buttons to manipulate the file directly...

The idea to use ADO data control almost worked, the adodc1 control has been set with the information i know if, but it wont read the information from the file... i cant get it to work...
Settings form properties that have been modified:
CommandType= 1-adCmdText 
ConnectionString=FILE NAME=C:\Program Files\Microsoft Visual Studio\VB98\Test.txt



The rest is all unknown to me, When the form loads it sets the adodc1 disabled so that it cant do anything. likely due to the fact i really dont know how to get it to read the Test.txt file:

General fields of Test.txt:
Position Id(Int): Territory or Talk Number(Int): Name(Str*25): Date Out(Str*12): Date In(Str*12):

The test.txt file has several records in it. And another test program (Mentioned above) works with the file directly using Command Buttons and the file reads writes and updates pretty flawlessly. But that isn't a data control item, and my books i have aren't much help as they tell me to setup a db system that vb uses, and that is not what i want to do...

Needed records: most RAF's will contain less than 20 records. The largest will likely not soon exceed 200 records. How do i connect the ADO Data Control to my RAFiles so that my controls (List and combo boxes...) can have access to the data in the RAFiles...

I have not much more information to present to you guys...

Can it be done? if so what do i need to do to get the things working? If these data controls don't work what db system would have the least overhead and required programming and maintainability and relative ease of implementation of this system for my three and maybe more programs to store their small data loads in the database...

Jesse Fender
Was This Post Helpful? 0
  • +
  • -

#5 BobRodes  Icon User is online

  • Your Friendly Local Curmudgeon
  • member icon

Reputation: 573
  • View blog
  • Posts: 2,989
  • Joined: 19-May 09

Re: Q re: Random Access Files, data-aware obj...

Posted 21 February 2011 - 12:05 AM

Have a look at this: http://www.connectio...gs.com/textfile and see if one of those works for you. This one is the example for a delimited text file:
Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\txtFilesFolder\;Extended Properties="text;HDR=Yes;FMT=Delimited";
Also, you'll probably want to index your recordset.

As for sending data to a dll and having it do the processing, that's the way to do it. Data tier components are commonplace.

So, you're on the right track, except with your insistence on using that horrible Data Control. Data binding in VB6 is considered iffy. :hammer:
Was This Post Helpful? 0
  • +
  • -

#6 chuckjessup  Icon User is offline

  • D.I.C Regular

Reputation: 33
  • View blog
  • Posts: 380
  • Joined: 26-October 09

Re: Q re: Random Access Files, data-aware obj...

Posted 21 February 2011 - 12:15 AM

View PostBobRodes, on 20 February 2011 - 11:05 PM, said:

Have a look at this: http://www.connectio...gs.com/textfile and see if one of those works for you. This one is the example for a delimited text file:
Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\txtFilesFolder\;Extended Properties="text;HDR=Yes;FMT=Delimited";
Also, you'll probably want to index your recordset.

As for sending data to a dll and having it do the processing, that's the way to do it. Data tier components are commonplace.

So, you're on the right track, except with your insistence on using that horrible Data Control. Data binding in VB6 is considered iffy. :hammer:


Well Bob, the information you have given me should work i think I will give it a try tuesday, or later tonight Thank you... I will keep that in mind as I work on adding the RAF's to the programs, the data items were just to look an read stuff to the controls...

I have been working on building the dll file to auto index, based on certain needed qualities, and all that goodness, And I can use my created data control made from command buttons to deal with the functions with in the files... I even have a nifty sort function that will sort the index for me :). I will post more code in this thread as I go along.

Many thanks again for the information I will let you know if it works.

Jesse Fender
Was This Post Helpful? 0
  • +
  • -

#7 chuckjessup  Icon User is offline

  • D.I.C Regular

Reputation: 33
  • View blog
  • Posts: 380
  • Joined: 26-October 09

Re: Q re: Random Access Files, data-aware obj...

Posted 21 February 2011 - 01:34 PM

View PostBobRodes, on 20 February 2011 - 11:05 PM, said:

Have a look at this: http://www.connectio...gs.com/textfile and see if one of those works for you. This one is the example for a delimited text file:
Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\txtFilesFolder\;Extended Properties="text;HDR=Yes;FMT=Delimited";
Also, you'll probably want to index your recordset.

As for sending data to a dll and having it do the processing, that's the way to do it. Data tier components are commonplace.

So, you're on the right track, except with your insistence on using that horrible Data Control. Data binding in VB6 is considered iffy. :hammer:



OK heres what is happening... I am not sure of what to do with my ADODC1 control. it is about to have fully pissed me off... I cannot get the information from the RAF to the form controls(e.g. combo boxes, listboxes, and textboxes...) the ADO control is an option, but when i go to set the field param it errors with the "Installable ISAM" couldn't be found... The test program opens and ADODC is disabled.

I tried the ADODC properties, and built the connection string, but this failed to fix the issue.

This is A F@*#$& nightmare!!!!!

Below is a copy of the test.text file so that you may look at the formatting and see if you can get your vb to connect to it... if you get it to do so, then i will try to get mine to work, again... but i am very quickly losing my cool with this...

The other option i have been trying to get to work is....:
If FSO.FileExists("Test.txt") = True Then
    I = 0
    Dim test1 As String, test2 As String, test3 As String, test4 As String, test5 As String, J As Integer
    J = 1
    Open "Test.txt" For Random As #255 Len = 54
        Do Until EOF(255)
            Get #255, J, TerrTest
            test1 = TerrTest.IdKey
            test2 = TerrTest.TerrNum
            test3 = TerrTest.PubName
            test4 = TerrTest.CODate
            test5 = TerrTest.CIDate
                Combo1.AddItem test3, I
        Loop
    Close #255
End If


Which leads to an epic FAIL where my vb locks up...and i have to restart it... if there is a way to get this thing working i can work from there... this is my alternate option to a data contorl, or ADOC.

Jesse Fender

Attached File(s)

  • Attached File  Test.txt (153bytes)
    Number of downloads: 130

Was This Post Helpful? 0
  • +
  • -

#8 chuckjessup  Icon User is offline

  • D.I.C Regular

Reputation: 33
  • View blog
  • Posts: 380
  • Joined: 26-October 09

Re: Q re: Random Access Files, data-aware obj...

Posted 21 February 2011 - 02:16 PM

Well I feel like a giant A$$ as i found why my issues were being caused from my general stupidity... and lack of calmness....

I am sorry Bob is i came off as snapping at you in my last two posts... It wasn't meant that way...

What was the error???

I forgot to increment the J position which was like causing the system to freak, but now it is working... all is good, and I will be asking on more questions... but that will be in another thread... and after i try to find the answer in google.... you will likely hear from me soon


Thanks Bob for your help.

Jesse Fender
Was This Post Helpful? 0
  • +
  • -

#9 BobRodes  Icon User is online

  • Your Friendly Local Curmudgeon
  • member icon

Reputation: 573
  • View blog
  • Posts: 2,989
  • Joined: 19-May 09

Re: Q re: Random Access Files, data-aware obj...

Posted 22 February 2011 - 03:29 PM

You're most welcome Jesse, and I never thought you were snapping at me. Rather I thought you were snapping at the ADODC, and you are certainly not the first person to do that! :)

Now, I used your file, and the file was the problem. First, to use a fixed-length file as yours is, you have to reference a schema.ini file that has the schema in it and also references your data file. I changed your file to delimited and added a header:
ID,Name,InDate,OutDate
15,John Brown,1/1/2011,2/1/2011           
14A,Jesse Fender,12/15/2008,1/31/2009          
27,George Lightel,2/15/2011,   

And was able to access it fine using ADO (Which you really oughtta learn... :dontgetit: :hammer:) Check this out. Set a reference to the ActiveX Object Library. Then:
Option Explicit
Dim cn As Connection
Dim rs As Recordset

Private Sub Form_Load()
Set cn = New Connection
Set rs = New Recordset
cn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\temp;Extended Properties='text;HDR=Yes;FMT=Delimited';"
rs.Open "select * from test.txt", cn
End Sub

and that's all you got to do to get the equivalent of an ADO Data Control's Recordset property. So, trouble is with your text file and how you're setting it up. I still can't see how you're getting IDKey, for example, when the string IDKey is nowhere present in the file you attach.
Was This Post Helpful? 0
  • +
  • -

#10 chuckjessup  Icon User is offline

  • D.I.C Regular

Reputation: 33
  • View blog
  • Posts: 380
  • Joined: 26-October 09

Re: Q re: Random Access Files, data-aware obj...

Posted 22 February 2011 - 04:21 PM

Bob, The id was a position indicator, it was so that the program could ref the currpos with the lstrec item in the programs, i wasnt sure that the random access files werent the only flat file system other than what i have in place already.

The reason i have the ID tag was so that the information packed could be referenced like coorrds on a map...

EX:
'The . is a spacer... normally a space '
ID.....WTR.............CHAIR.............HOST............HOSTPHN
1......John Doe........John Doe..........John Doe........555-555-1234
2......Jesse Fender....Jesse Fender......Jesse Fender....555-555-1234
188....Happy Woods.....Happy Woods.......Happy Woods.....555-555-4321


in the Type Declaration:

Private Type SupportInfo
     ID As Integer
     WTR1 As String * 16
     Chair1 As String * 18
     Host1 As String * 16
     HSTPHN As String * 12
End Type



That way when the program opens and reads informantion in the code can pull pos 2 and chair and the chair would be Jesse Fender. it is basicly so that the program can deal with the positions with in the file.

As far as the ADODC i have set that aside for now as i have gotten the loop function work atm, i will move to that at a later date... I have set my focus on leaning about getting sorts to work and help me create index files...

That is another long story... figuring how to load arrays, send them to arrange based on properties (for me a-z sorting...and in the more advanced themename(a-z)Talk number(1-N) all in one big index fest...)

The fun thing about the sorting functions is no one can comment what they are doing the process so i am lost as far as what i need to do to get it to work... makes me want to cry.

any way thanks for the help with this, i will save it so that i have it to refer back to it... if you want to read my woes about sorts, there is a thread lower in the line that discusses a shell sort that i i got off the MSDN and there was little explination of what it was doing...
My Issue with Shell Sorts...

Thanks again...

Jesse Fender
Was This Post Helpful? 0
  • +
  • -

#11 BobRodes  Icon User is online

  • Your Friendly Local Curmudgeon
  • member icon

Reputation: 573
  • View blog
  • Posts: 2,989
  • Joined: 19-May 09

Re: Q re: Random Access Files, data-aware obj...

Posted 22 February 2011 - 06:22 PM

Well, I could tell all that. You're using a fixed-length scheme. See, my point is that the top line wasn't in the text file that you attached.

Dealing with positions in the file. You can do all that stuff, or you can use the Recordset's Fields collection. rs.Fields(1) would be WTR, rs.Fields(2) would be Chair.

Getting sorts to work. Of course, you could go to all the trouble you describe. Or you could use the code I shared with you to create an ADO recordset and set its Sort property to a valid SQL WHERE Clause. You could even take the sorted recordset and run through it, writing its records to a text file.

That is, if you wanted to go to the trouble of figuring out the 6 lines of code I shared with you. Of course, your solution is certainly going to teach you more about sorting algorithms and the like. :)

As for the ADODC, I'd set it aside forever, not for now.
Was This Post Helpful? 0
  • +
  • -

#12 chuckjessup  Icon User is offline

  • D.I.C Regular

Reputation: 33
  • View blog
  • Posts: 380
  • Joined: 26-October 09

Re: Q re: Random Access Files, data-aware obj...

Posted 23 February 2011 - 12:37 AM

View PostBobRodes, on 22 February 2011 - 05:22 PM, said:

Well, I could tell all that. You're using a fixed-length scheme. See, my point is that the top line wasn't in the text file that you attached.

Dealing with positions in the file. You can do all that stuff, or you can use the Recordset's Fields collection. rs.Fields(1) would be WTR, rs.Fields(2) would be Chair.

Getting sorts to work. Of course, you could go to all the trouble you describe. Or you could use the code I shared with you to create an ADO recordset and set its Sort property to a valid SQL WHERE Clause. You could even take the sorted recordset and run through it, writing its records to a text file.

That is, if you wanted to go to the trouble of figuring out the 6 lines of code I shared with you. Of course, your solution is certainly going to teach you more about sorting algorithms and the like. :)

As for the ADODC, I'd set it aside forever, not for now.



Well I hate to break it to you Bob, the code snippet is not working for me... lol it is telling me that i am either the file i am trying to open is not valid, OR that im not connected... Ill post me code see if you can see what i am doing incorrectly...
Private Sub Form_Load()
Me.Caption = "Text Delimited DB Program"
 Set NewConn = New Connection
 Set RS = New Recordset
 NewConn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Program Files\Microsoft Visual Studio\VB98\FDFDB.txt;Extended Properties='text;HDR=Yes;FMT=Delimited';"
 RS.Open "FDFDB.PwF", NewConn



the code for creating the initial file...
Private Sub BuildDB_Click(Index As Integer)
'creates the DB file and sets up the LastRecord Listing Then becomes disabled...
LastRecord = 0
FFile = FreeFile
If FSO.FileExists("FDFDB.txt") = False Then
    Open "FDFDB.txt" For Output As #FFile
        Print #FFile, "ID", "TerrNum", "PubName", "CODate", "CIDate"
    Close #FFile
    LastRecord = LastRecord + 1
    Open "FDFDBLR.PwF" For Output As #FFile
        Print #FFile, LastRecord
    Close #FFile
    BuildDB(1).Enabled = False
Else
End If
End Sub



And the code that is supposed to control the record selection... i think...
Private Sub Command1_Click(Index As Integer)
Select Case Index
    Case FristRec:
        RS.MoveFirst
        RS.NextRecordset
    Case NextRec:
        RS.MoveNext
    Case PrevRec:
        RS.MovePrevious
    Case LastRec:
        RS.MoveLast
    Case AddRec:
        RS.AddNew
    Case EditRec:
        RS.Update
    Case DelRec:
        RS.Delete
    End Select
End Sub



general decs code
Private FSO As New FileSystemObject, NewConn As Connection, RS As Recordset
Private Position As Long, LastRecord As Long, FFile As Integer
Private X As Integer, Y As Long, I As Integer, J As Long



I think i am doing something wrong... it really shouldnt be hard.... The file is a comma delimited file... which i cant make due to the program not letting me, even when it was there it wouldnt let me make it...

Any ways... the sort thing is for searching through the fields, and recreating and indexing all the files as they got changes... to make life easier.

Jesse Fender
Was This Post Helpful? 0
  • +
  • -

#13 BobRodes  Icon User is online

  • Your Friendly Local Curmudgeon
  • member icon

Reputation: 573
  • View blog
  • Posts: 2,989
  • Joined: 19-May 09

Re: Q re: Random Access Files, data-aware obj...

Posted 24 February 2011 - 04:34 PM

All right. It would sure help if you would not make a secret of the actual error you have encountered. But I'll see if I can guess anyway. First problem is that in your connectionstring you need to put the PATH, not the FILE. So remove "FDFDB.TXT" from the string. (Keep the \ in front of it.) Next, make sure you open the right file (the TXT or the PWF file) and that it's in the path you specify in the connectionstring.

Next, your select case syntax is all wrong. In VB, Index is the value of the Index property in your control array, and will be 0,1,2,3,4,5,6 and so on. Also, you don't use : at the end of each case statement in VB.

Suppose that you first get so you can move around easily, and then we will work on updating and deleting and the like. Step one is to be able to open a recordset and move around in it.
Was This Post Helpful? 0
  • +
  • -

#14 chuckjessup  Icon User is offline

  • D.I.C Regular

Reputation: 33
  • View blog
  • Posts: 380
  • Joined: 26-October 09

Re: Q re: Random Access Files, data-aware obj...

Posted 25 February 2011 - 07:05 PM

View PostBobRodes, on 24 February 2011 - 03:34 PM, said:

All right. It would sure help if you would not make a secret of the actual error you have encountered. But I'll see if I can guess anyway. First problem is that in your connectionstring you need to put the PATH, not the FILE. So remove "FDFDB.TXT" from the string. (Keep the \ in front of it.) Next, make sure you open the right file (the TXT or the PWF file) and that it's in the path you specify in the connectionstring.

Next, your select case syntax is all wrong. In VB, Index is the value of the Index property in your control array, and will be 0,1,2,3,4,5,6 and so on. Also, you don't use : at the end of each case statement in VB.

Suppose that you first get so you can move around easily, and then we will work on updating and deleting and the like. Step one is to be able to open a recordset and move around in it.


well in time i want to just use one file that holds many fields and what not, To start however i am working with the basic system... if i get the program to index files and deal with all that... the adoconnection is something i will start back on when i get back home... the text file will be renamed as a *.db file, and that way it will distinguish the database file and index files and record files (record files are seq files with a list of "last Records" for each db file.) I will work with that a bit too...

As far as the :
i will remove them as soon as i can...
The value of the index is the value of the control array that has been decl in an enum so they should be ok... if not i will look into that again...

Exactly, the purpose of this is to learn more about handeling files and records... With out datacontrols provided by MS...

A question Bob, did you use write or print for the delimeted file... i tryied both, but only one really looked like teh example you put in the last reply before this one. write packed close but had the "", print added tabs and no commas or "" not really sure if it matters.

Thanks for your replies...

Jesse Fender
Was This Post Helpful? 0
  • +
  • -

#15 BobRodes  Icon User is online

  • Your Friendly Local Curmudgeon
  • member icon

Reputation: 573
  • View blog
  • Posts: 2,989
  • Joined: 19-May 09

Re: Q re: Random Access Files, data-aware obj...

Posted 25 February 2011 - 07:40 PM

Ok. I understand about not using Microsoft Controls. There's a distinction to be made between controls and class libraries. The latter can be quite useful, and bring some of the more old-fashioned aspects of VB (such as file manipulation statements that go back 50 years) into a more OO paradigm. So, I would by all means learn the old-fashioned file manipulations, but don't get the idea that they are inherently more efficient than, say, using the FileSystemObject stuff. Also, ADO recordsets can be most efficient and very easy to use as a means of reading through a bunch of non-relational data. That's basically why I'm "banging on" about it here.

As for what I used for the delimited file, well, I used my favorite text editor and put the commas in by hand. :)
Was This Post Helpful? 0
  • +
  • -

  • (13 Pages)
  • +
  • 1
  • 2
  • 3
  • Last »