Guest Orion Tatsihama Posted August 30, 2002 Posted August 30, 2002 I'm creating a program and am trying to decide how to store the information entered. I want it to be able to be displayed in a noneditable way (but be able to be edited through another form). I would like to use a text file if possible...if not, I need an offline database. I know nothing about databases (except mySQL) and since this is going to be a distributed program, I don't want the user to need anything extra to use it. What is my best option? I would like the information to be displayed in a grid, but not be editable through the grid itself. I would also like the user to be able to sort the data by any field, such as Title, Lenght, etc. I am really new to all of this...so I'm sorry if I'm not being clear. Ask me if you need more information. I am using Visual Basic .NET Quote
Shurik12 Posted August 30, 2002 Posted August 30, 2002 Hi, displaying information in a grid, making it not editable, etc. has not very much to do with the choice of the database but rather with the the properties you're setting for the control displaying the data (think od DataGrid). More over there are controls which intrinsically not meant for editing data displayed in it but for displaying it only (MSFLEXIGRID,MSHFLEXIGRID, ListView...) For the rest, to give you a more precise answer, I think one needs to know more about your project. About the fact you "don't want the user to need anything extra to use it"... Say, you can create a project with an Access database as a back end and after that distridute it on a PC which doesn't have Access on it. Regards, Shurik12. Quote
Guest Orion Tatsihama Posted August 30, 2002 Posted August 30, 2002 My program is called DVlog. It's a DVD "database" program where you enter information on dvds that you own and it keeps track of them. Right now, I'm just trying to get the Adding and Displaying features working. The fields are: Genre, Title, Rating, Length, (Number of) Disks, Special Edition? (Yes/No), and Year. This is a demo entry in my text file database: Anime\tGTO\tNR\t112\t1\tNo\t2002\tGreat Teacher Onizuka Ep. 1-4 More over there are controls which intrinsically not meant for editing data displayed in it but for displaying it only (MSFLEXIGRID,MSHFLEXIGRID, ListView...)I hear a lot about MSFLEXIGRID and MSHFLEXIGRID but I have no idea what those are. About the fact you "don't want the user to need anything extra to use it"... Say, you can create a project with an Access database as a back end and after that distridute it on a PC which doesn't have Access on it.Yes, that's what I mean. Quote
Shurik12 Posted August 30, 2002 Posted August 30, 2002 There are plenty of sights which might help you, I mean to give a feeling where you have to go further. Have a look at these ones: http://www.gab2001uk.com/ http://www.gab2001uk.com/visualbasic/daovsado/index.htm if you have more questions, don't hesitate to ask Regards, Shurik12. Quote
Guest Orion Tatsihama Posted August 30, 2002 Posted August 30, 2002 Will the fact that I use VB.NET Standart effect the use of the things on that site? I look at them and I don't see anything about DAO, AOD, or MSFlexigrids in my program. :( Quote
Shurik12 Posted August 30, 2002 Posted August 30, 2002 The VB.NET syntaxis itself differs a good deal from that one of VB 6 (5...). But the 'definitions' of ADO, Flexigrid etc. remain the same. Try to have a look in the help files of your VB.Net Standard. Regards, Shurik12. Quote
Guest Orion Tatsihama Posted August 30, 2002 Posted August 30, 2002 Is it possible to use the text file 'database' I setup? Or an access database? I'm sorry...I'm really new when it comes to this stuff. Quote
Shurik12 Posted August 30, 2002 Posted August 30, 2002 First of all you should not feel sorry. That's what forums are for: to ask questions and get answers. If it's all about ONE 'table' you're going to have you can perfectly use your txt file as the 'data container'. If you have more then one, then relational databases such as Access, MS SQL, Oracle, Sybase, mySQL etc. come into play. By the way you mentioned you had some experience with mySQL. All the mentioned databases are relational. So there should be nothing new for you as far as the "idea" of a relational database concerned. Quote
Guest Orion Tatsihama Posted August 30, 2002 Posted August 30, 2002 That's good to know! Now...I guess my only issue is taking the data in the text file and displaying it in a "spreadsheet" or "grid" type display. I also heard that you can't edit/delete a line of a text file, you have to rewrite the entire file omitting that line or replacing it with the edited line...is that true? Quote
Shurik12 Posted August 30, 2002 Posted August 30, 2002 if you don't mind I'm going to have a nap. It's almost 2 a.m in Belgium. Will try to answer tomorrow (or some one else yet) Quote
Guest Orion Tatsihama Posted August 30, 2002 Posted August 30, 2002 No problem :) Thanks for all your help! To anyone who's reading this, feel free to help me out too, please. :) Quote
Shurik12 Posted August 31, 2002 Posted August 31, 2002 Hi again, If you choose a .txt-file as the place to strore the data, have a look at the "Open"-statement, "Input"-function, etc... in the help files. It should give you an idea how to work with the text files. One more thing, if you have an opportunity to do it in Access or even in Excel go for it. Regards, Shurik12 Quote
Guest Orion Tatsihama Posted August 31, 2002 Posted August 31, 2002 The main reason I want to use text files is cause I can use my own file extentions. :) I'll checkout the statements and functions. Thanks. Quote
*Gurus* Derek Stone Posted September 1, 2002 *Gurus* Posted September 1, 2002 One word: XML. Learn it. Use it. Enjoy it. Quote Posting Guidelines
Guest Orion Tatsihama Posted September 1, 2002 Posted September 1, 2002 I have no idea where to start with XML... I looked at some XML resources but I don't get it. Quote
Guest mouseslinger Posted September 6, 2002 Posted September 6, 2002 To use a text file as a data container is simple. Here is an example of how to open and read a text file in visual basic 6. I don't have the .net version of visual basic , but it be similar in practice. '---------------------------- ' Example of how to open a file in visual basic. '---------------------------- Dim importfile As Integer importfile = FreeFile Dim fileinfo as string Open "c:\whatever.txt" For Input As #importfile If Not EOF(1) Then Do Input #importfile, fileinfo ' get some info from the file. Loop Until EOF(1) ' keep looping until its the end of the file. End If Close #importfile '-------------------- This should give you an idea of what your code should look similar to. Check in the help file for information on how to "open" a file. Also look in the help files for examples of how to work with arrays. If you would like, I would be happy to build a simple application using VB 6 which can read and write data to a text file, and post it online for download. Would anyone else like me to build an example application for download? david mouseslinger@hotmail.com Quote
Guest mouseslinger Posted September 6, 2002 Posted September 6, 2002 To use a text file as a data container is simple. Here is an example of how to open and read a text file in visual basic 6. I don't have the .net version of visual basic , but it be similar in practice. '---------------------------- ' Example of how to open a file in visual basic. '---------------------------- Dim importfile As Integer importfile = FreeFile Dim fileinfo as string Open "c:\whatever.txt" For Input As #importfile If Not EOF(1) Then Do Input #importfile, fileinfo ' get some info from the file. Loop Until EOF(1) ' keep looping until its the end of the file. End If Close #importfile '-------------------- This should give you an idea of what your code should look similar to. Check in the help file for information on how to "open" a file. Also look in the help files for examples of how to work with arrays. If you would like, I would be happy to build a simple application using VB 6 which can read and write data to a text file, and post it online for download. Would anyone else like me to build an example application for download? david mouseslinger@hotmail.com Quote
*Gurus* divil Posted September 6, 2002 *Gurus* Posted September 6, 2002 The .net version of that code is almost completely different, mouseslinger :) Quote MVP, Visual Developer - .NET Now you see why evil will always triumph - because good is dumb. My free .NET Windows Forms Controls and Articles
Guest Orion Tatsihama Posted September 10, 2002 Posted September 10, 2002 It is? Well I have no idea about converting it...I have the Standard version so it wouldn't convert it for my either. I found a script that can split the info from a file into an array, is there somewhay I can use that? Quote
Guest gjnave Posted September 12, 2002 Posted September 12, 2002 How to do it The person who said that XML is the way to go is correct.. too bad he didn't say anything else about how to do it. This is what I've done in an application of my own in which I save all my information in a "text" file as you put it (actually an .xml file; but can be read just as a text file in Notepad or whatever). Try this: First of all, on your toolbar click on "Project" and the click on "Add new Item".. from the list, choose "XML Schema". This will add a new .xsd file to your program. In your program window go to that file and create a schema (a graphical representation and hierachal view of the way the data will be held). Press F1 to go to the help menu and read about Elements and Complex Types to create your schema. Basically a schema is the "skeleton" of your database. It will give you something to populate. Once you start populating it you will save the results as a .XML file. First of all put the following in the form that you are going to use to enter data. This is how I coded it (not perfect as I am new at this also) *( ' put this underneath "Inherits System.Windows.Forms.Form") Public ds1 As New DataSet() Dim xmlDoc As New Xml.XmlDataDocument() *(' put this underneath your form load event) * ds1.ReadXml(fileOpen) 'file open equals the name and location of the .xsd file you created... this loads the database structure into the dataset. What you can do from here is tie the ds1 into a datagrid, of course you have to do this from code though. datagrid1.datasource = ds1 Once you have entered whatever data into the datagrid, do this to save the information into a XML file. private Sub saveXMLFile() Dim sDialog As New SaveFileDialog() sDialog.FileName = ("MyXMLFile") & ".xml" sDialog.Filter = "XML files (*.xml)|*.xml" If sDialog.ShowDialog = DialogResult.OK Then Dim wstream As New _ System.IO.StreamWriter(sDialog.FileName) ds1.WriteXml(wstream, XmlWriteMode.WriteSchema) wstream.Close() End If End Sub *note that "MyXMLFile" can be whatever you want The file is now saved as an XML file. Pretty nifty! Next make the form that you want to use to display the data. 'First of all create a datagrid on the view form and set its source to your dataset (you have to do this in code) datagrid1.datasource = ds1 'Next, because you dont want anyone to be able to modify the contents of the database, set the read-only attribute to true. datagrid1.readonly = true Now, this is code to load the XML file: Dim fsReadXml As New System.IO.FileStream _ ("MyXMLFile.xml", System.IO.FileMode.Open) ' Create an XmlTextReader to read the file. Dim myXmlReader As New System.Xml.XmlTextReader(fsReadXml) ' Read the XML document into the DataSet. ds1.ReadXml(myXmlReader) ' Close the XmlTextReader myXmlReader.Close() The datagrid will be populated with the info you entered on your other form. Hope this helped. Let me know if you need clarification. Quote
Guest Orion Tatsihama Posted September 12, 2002 Posted September 12, 2002 Thank you so much! I'll try that the first chance I get...stupid homework. Quote
Guest Eregnon Posted September 12, 2002 Posted September 12, 2002 (edited) If you'd like to just read in a text file, here's a class I put together that will do it. It just reads the file in and stores the result in a string variable, accessed through the filedata property. If there's an error, the errormessage property will be non-blank. Not much in the way of comments, but there's not much code either. By the way, I'm also new at this. Then again, isn't everybody? Public Class OpenForInput Private strFile As String Private intHandle As Integer Private strData As String Private strError As String Public Property FileName() As String Get Return strFile End Get Set(ByVal Value As String) strFile = Value If Dir(strFile) = "" Then strError = "File " & strFile & " not found." Exit Property End If Dim lngLength As Long lngLength = FileLen(strFile) strError = "" strData = "" intHandle = FreeFile() Try FileOpen(intHandle, strFile, OpenMode.Input, OpenAccess.Read, OpenShare.Default, ) strData = InputString(intHandle, lngLength) Catch aru As System.ArgumentException strError = aru.Message Catch ios As System.IO.IOException strError = ios.Message Catch exe As Exception strError = exe.Message Finally FileClose(intHandle) If strError > "" Then ' had an error If strData = "" Then ' means couldn't read file strError = "Couldn't read file. " & Chr(13) & strError Else strError = "Couldn't open file. " & Chr(13) & strError End If End If End Try End Set End Property Public ReadOnly Property ErrorMessage() As String Get Return strError End Get End Property Public ReadOnly Property FileData() As String Get Return strData End Get End Property End Class Edited September 14, 2002 by Derek Stone Quote
Guest Orion Tatsihama Posted September 12, 2002 Posted September 12, 2002 I went this gjnave's code and DVlog (which I replaced ds1 with, just the name) and ViewDVlog (which I replaced datagrid1 with) aren't valid...they have little blue underlines on them. Quote
Guest Orion Tatsihama Posted September 12, 2002 Posted September 12, 2002 (edited) Here's the code (forgot to post it). Public Class Form Inherits System.Windows.Forms.Form Public DVlog As New DataSet() Dim xmlDoc As New Xml.XmlDataDocument() [ Windows Form Designer generated code ] DVlog.ReadXml(fileOpen) Private Sub saveXMLFile() Dim sDialog As New SaveFileDialog() sDialog.FileName = ("DVconfig") & ".xml" sDialog.Filter = "XML files (*.xml)|*.xml" If sDialog.ShowDialog = DialogResult.OK Then Dim wstream As New _ System.IO.StreamWriter(sDialog.FileName) DVlog.WriteXml(wstream, XmlWriteMode.WriteSchema) wstream.Close() End If End Sub ViewDVlog.datasource = ds1 ViewDVlog.readonly = true Dim fsReadXml As New System.IO.FileStream("DVconfig.xml", System.IO.FileMode.Open) ' Create an XmlTextReader to read the file. Dim myXmlReader As New System.Xml.XmlTextReader(fsReadXml) ' Read the XML document into the DataSet. DVblog.ReadXml(myXmlReader) ' Close the XmlTextReader myXmlReader.Close() End ClassI edited out the Windows Form Designer generated code (as you can see) because it made this post too long. Edited September 14, 2002 by Derek Stone Quote
*Gurus* Derek Stone Posted September 12, 2002 *Gurus* Posted September 12, 2002 Eregnon, you might want to read the article below regarding file access. http://www.elitevb.com/content/01,0072,01/01.aspx Quote Posting Guidelines
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.