Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Sep 11th, 2005, 5:28 PM   #1
brokenhope
Hobbyist Programmer
 
Join Date: Apr 2005
Posts: 126
Rep Power: 4 brokenhope is on a distinguished road
Settings?

Alright on my program I want to somehow make it remember the users settings. Such as default directory to open files from, font face, font size, font type, auto tab, syntax highlighting, practicle things like that, how should I store that? The only thing I can think of is flatfile, but is there a better way with less risk of the user opening the file and messing with it?

The second type of things I need stored is, abbreviations, which is basicly a list of keywords you can type that will be replaced by its replacement, that list can be quite long so im guessing flatfile will work best for that, I dont know, any advice?

Please post your opinions on this... Ive searched google but I didnt find anything at all relevant to this topic.
brokenhope is offline   Reply With Quote
Old Sep 11th, 2005, 5:46 PM   #2
Ooble
I eat cake for breakfast.
 
Ooble's Avatar
 
Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 8 Ooble is on a distinguished road
You can use a flat file or the Windows registry. Personally, I prefer a flat or XML-based file. If a user's messing around, just hope they know what they're doing and add error-handling. :p
__________________
Me :: You :: Them
Ooble is offline   Reply With Quote
Old Sep 11th, 2005, 6:43 PM   #3
brokenhope
Hobbyist Programmer
 
Join Date: Apr 2005
Posts: 126
Rep Power: 4 brokenhope is on a distinguished road
Hmm dont know anything about windows registry. XML does seem like it would be appropriate, but I know nothing about it, so I guess flatfile will have to do. Do you recommend me using .txt as the flatfiles format? or something else?
brokenhope is offline   Reply With Quote
Old Sep 11th, 2005, 8:17 PM   #4
Ooble
I eat cake for breakfast.
 
Ooble's Avatar
 
Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 8 Ooble is on a distinguished road
Use a straight text file, and just change the extension to something confusing. ".dat" (data) is a good one.
__________________
Me :: You :: Them
Ooble is offline   Reply With Quote
Old Sep 12th, 2005, 9:21 PM   #5
brokenhope
Hobbyist Programmer
 
Join Date: Apr 2005
Posts: 126
Rep Power: 4 brokenhope is on a distinguished road
Alright, Ill do that, but anyways I got stumped on this... I know what is wrong, with my code but the fix seems a little bit to complex for VB .NET, its supposed to make things simple, and ive never seen it do anything with one character per array value like in C and C++, where you cant store strings in arrays... which the code hints in the code im using now is telling me one byte per... this is code I altered quite a bit from the example I found on the internet, so I might have screwed something up. But basicly what my code is supposed to do is:

open up the file elementalEditor.dat, if it doesnt exist create it, then check the size of the file, if its 0 (meaning it was just created, atleast I think) then write default values to it).

        ' Load Settings
        Dim oFile As System.IO.File
        Dim oFileStream As System.IO.FileStream
        oFileStream = oFile.Open("elementalEditor.dat", IO.FileMode.OpenOrCreate)
        If oFileStream.Length = 0 Then
            ' Write default settings to form
            oFileStream.Write(, 0, 100000000)
        End If

The values I write to it will be in a simple form, atleast to me, one configuration value per line, so I can read through it one line at a time, take all the text on that line and put it into the shared configuration array.

Anyways know an eaiser way to write code to the file like that without having to do it like VB is telling me, one byte per value in array?
brokenhope is offline   Reply With Quote
Old Sep 13th, 2005, 1:41 PM   #6
Ooble
I eat cake for breakfast.
 
Ooble's Avatar
 
Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 8 Ooble is on a distinguished road
Quote:
Originally Posted by brokenhope
then check the size of the file, if its 0 (meaning it was just created, atleast I think)
Nope. It just tells you how big the file is in bytes. Of course it's going to be zero if you just created it! This is how I do it in C# - I assume it's similar for VB .NET:
try
{
    oFileStream = oFile.Open("elementalEditor.dat", IO.FileMode.OpenOrCreate);
}
catch 
{
    return;
}

oFileStream.Write(...);
__________________
Me :: You :: Them
Ooble is offline   Reply With Quote
Old Sep 13th, 2005, 2:24 PM   #7
Infinite Recursion
Programming Guru
 
Infinite Recursion's Avatar
 
Join Date: Jul 2004
Location: United States
Posts: 3,453
Rep Power: 7 Infinite Recursion is on a distinguished road
Send a message via MSN to Infinite Recursion Send a message via Yahoo to Infinite Recursion
Here's a logging method I wrote in VB .Net a while back, maybe it will help:

    Public Function LOG(ByRef info As String) As Object
        On Error Resume Next
        If Err.Number = 0 Then
            FileOpen(1, LOGFILE, OpenMode.Append)
            PrintLine(1, TimeOfDay & "-> " & info)
            FileClose(1)
        End If
    End Function
__________________
http://jasonpowers.net

"There are a thousand hacking at the branches of evil to one who is striking at the root."
Infinite Recursion is offline   Reply With Quote
Old Sep 14th, 2005, 8:06 PM   #8
brokenhope
Hobbyist Programmer
 
Join Date: Apr 2005
Posts: 126
Rep Power: 4 brokenhope is on a distinguished road
Thanks for all your help, I have it semi working now. Theres just one kink in the updateing of certain settings.

First I will start off and say how im updateing specific lines, just in case theres a better way, Im looping through every line and adding it to a string, while doing it theres a counter counting each time through the loop when it reaches the line number, instead of inserting the files text on that line, it uses the new text, then when its done with the loop it writes the new text. The problem is, I cant get it to overwrite over whats already in the file, it just adds onto it. I want to completely get rid of every character in the file before writing the new multi line string to it...

heres my code:

            Dim oFileStream As New System.IO.FileStream("elementalEditor.dat", IO.FileMode.Open)
            Dim oStreamWriter As New System.IO.StreamWriter(oFileStream)
            Dim oStreamReader As New System.IO.StreamReader(oFileStream)
            Dim iCount As Integer = 0
            Dim strEditFileText As String
            oStreamReader.BaseStream.Seek(0, IO.SeekOrigin.Begin)

            While oStreamReader.Peek <> -1
                ' Line 1 is the default open directory. 
                If iCount = 0 Then
                    strEditFileText = strEditFileText & txtOpenFileDirectory.Text & vbNewLine
                    oStreamReader.ReadLine()
                Else
                    strEditFileText = strEditFileText & oStreamReader.ReadLine() & vbNewLine
                End If
                iCount = iCount + 1
            End While

            ' Change Position of stream writer to start of file
            oStreamWriter.BaseStream.Seek(0, IO.SeekOrigin.Begin)
            oStreamWriter.Write(strEditFileText)

            oStreamWriter.Flush()
            oStreamWriter.Close()
            oStreamReader.Close()
            oFileStream.Close()

Is there something I can specify that does that or do I have to delete and recreate the file or something like that?
brokenhope is offline   Reply With Quote
Old Sep 14th, 2005, 8:11 PM   #9
Dameon
Troll
 
Dameon's Avatar
 
Join Date: Apr 2005
Location: Texas
Posts: 730
Rep Power: 4 Dameon is on a distinguished road
Perhaps you should try Nini
__________________
MD5(sig) = bcef75433db02e9ad9bf81d6f7c5c270
Dameon is offline   Reply With Quote
Old Sep 14th, 2005, 8:43 PM   #10
brokenhope
Hobbyist Programmer
 
Join Date: Apr 2005
Posts: 126
Rep Power: 4 brokenhope is on a distinguished road
Yea that would make things simpler, but I dont know much about .NET and dont know how or what to do with it to make it work. I really want to create this program all by myself so I can figure out how to write things, like write code to a file correctly, before I start taking shortcuts, just so I have the knowledge.
brokenhope is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 4:09 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC