Results 1 to 10 of 10

Thread: [RESOLVED] [2008] Trying to use my.resources for a text file

  1. #1

    Thread Starter
    Member
    Join Date
    Nov 2007
    Posts
    62

    Resolved [RESOLVED] [2008] Trying to use my.resources for a text file

    Hi everybody

    I have a .txt file in the same folder as my project that is being loaded into an array. I want to get rid of the .txt file and import it into the .exe. So I used the import resources and put it in the text file section of the project. When I use my.resources.lvlxp it gives me an error that there are illegal characters in the path.

    Here is the code for loading from the .txt in the folder:

    Code:
            Dim tempstr As String
            Dim x As Integer = 1
            Dim firstcomma As Integer
            Dim filenum As Integer = FreeFile()
            FileOpen(filenum, "lvlxp.txt", OpenMode.Input)
            Do While Not EOF(1)
                tempstr = LineInput(filenum)
                firstcomma = tempstr.IndexOf(",")
                lvlarray(x) = tempstr.Substring(0, firstcomma)
                xparray(x) = tempstr.Substring(lvlarray(x).ToString.Length + 1, tempstr.Length - lvlarray(x).ToString.Length - 1)
                x += 1
            Loop
            FileClose(1)
    and the code for loading from my.resources:

    Code:
            Dim tempstr As String
            Dim x As Integer = 1
            Dim firstcomma As Integer
            Dim filenum As Integer = FreeFile()
            FileOpen(filenum, My.resources.lvlxp, OpenMode.Input)
            Do While Not EOF(1)
                tempstr = LineInput(filenum)
                firstcomma = tempstr.IndexOf(",")
                lvlarray(x) = tempstr.Substring(0, firstcomma)
                xparray(x) = tempstr.Substring(lvlarray(x).ToString.Length + 1, tempstr.Length - lvlarray(x).ToString.Length - 1)
                x += 1
            Loop
            FileClose(1)
    This is my first time using my.resources and am still pretty new to VB itself..


    Thanks for any and all help.
    Last edited by rhijaen; Dec 1st, 2007 at 07:59 PM.

  2. #2
    Frenzied Member Icyculyr's Avatar
    Join Date
    Aug 2007
    Location
    Australia
    Posts
    1,934

    Re: [2008] Trying to use my.resources for a text file

    Ok, try this, this should work

    vb.net Code:
    1. Dim TempValue As String = ""
    2. Using sr As New Resources.ResourceReader(My.Resources.lxltxt)
    3.     TempValue = sr.ReadToEnd() '
    4. End Using

    'lvlXP contents is in TempValue now, if you need to store in an array
    Make TempValue an array, and use sr.ReadLine()

  3. #3

    Thread Starter
    Member
    Join Date
    Nov 2007
    Posts
    62

    Re: [2008] Trying to use my.resources for a text file

    With that I get "Error 1 Value of type 'String' cannot be converted to 'System.IO.FileInfo'. C:\Documents and Settings\Chris\My Documents\Visual Studio 2008\Projects\T4C Calculator\T4C Calculator\Form1.vb 15 36 T4C Calculator
    "

    Oops..you edited your post..trying again

  4. #4

    Thread Starter
    Member
    Join Date
    Nov 2007
    Posts
    62

    Re: [2008] Trying to use my.resources for a text file

    I still get "Illegal characters in path." on that first line you posted.

    Edited once again :P..trying again

    I get "Error 1 'ReadToEnd' is not a member of 'System.Resources.ResourceReader'. C:\Documents and Settings\Chris\My Documents\Visual Studio 2008\Projects\T4C Calculator\T4C Calculator\Form1.vb 20 25 T4C Calculator
    "
    Last edited by rhijaen; Dec 1st, 2007 at 06:32 PM.

  5. #5
    Frenzied Member Icyculyr's Avatar
    Join Date
    Aug 2007
    Location
    Australia
    Posts
    1,934

    Re: [2008] Trying to use my.resources for a text file

    Sadly, I actually had to test it, but this works

    Code:
    Dim RecText As String = My.Resources.ResourceManager.GetObject("TestDocument")
    the name is caps sensitive and returns nothing if it is not found...

  6. #6

    Thread Starter
    Member
    Join Date
    Nov 2007
    Posts
    62

    Re: [2008] Trying to use my.resources for a text file

    Thank you, this worked fine.

    Now how would I load it into an array?? I'm stuck there
    Last edited by rhijaen; Dec 1st, 2007 at 06:54 PM.

  7. #7
    Frenzied Member Icyculyr's Avatar
    Join Date
    Aug 2007
    Location
    Australia
    Posts
    1,934

    Re: [2008] Trying to use my.resources for a text file

    Try writing it to a text document, and then re-reading it back, then delete the txt doc

    Try this

    vb.net Code:
    1. Dim MyTempFilePath As String = My.Computer.FileSystem.SpecialDirectories.AllUsersApplication.Data & "\MyApplicationName\lvltxt.txt"
    2.  
    3. Using sw As New StreamWriter(MyTempFilePath)
    4.     sw.Write(My.Resources.ResourceManager.GetObject("filename"))
    5. End Using

    'Then read it again with all your code that you were using before, (give or take some necessary modifications)

    Then at the end
    vb.net Code:
    1. File.Delete(MyTempFilePath)

    Personally I have a class called 'DirectoriesC' which has all my directories \ names for things like this:

    vb.net Code:
    1. Dim ad As String = My.Computer.FileSystem.SpecialDirectories.AllUsersApplicationData
    2. Dim ProgramName As String = "thething"
    3. Dim TempLvlExpName As String = "lvlxp_temp"
    4. Dim TempLvlExpExt As String = ".txt"
    5. Dim TempLvlExpPath As String = ad & "\" & ProgramName & "\" & TempLvlExpName & TempLvlExpExt

    good for organizing things, especially large projects, where the names can change

    Cheers

    (Mark thread as resolved when your done, with little green post icon tick)

  8. #8

    Thread Starter
    Member
    Join Date
    Nov 2007
    Posts
    62

    Re: [2008] Trying to use my.resources for a text file

    Again, thanks so much for your help.

    Everything works fine..except that the .txt in the temp dir is filled with nothing. It gets created, but it is blank.

    I made sure that the resource does in fact have text in it.

    I'm guessing there's a problem with this part?

    Code:
    Using sw As New StreamWriter(My.Computer.FileSystem.SpecialDirectories.AllUsersApplicationData & "\T4C XP Calculator\lvlxp.txt")
    
                sw.Write(My.Resources.ResourceManager.GetObject("lvlxp.txt"))
    
            End Using
    Hopefully this will be my last reply in this thread.

  9. #9
    Frenzied Member Icyculyr's Avatar
    Join Date
    Aug 2007
    Location
    Australia
    Posts
    1,934

    Re: [2008] Trying to use my.resources for a text file

    yes, you've used an extension in the name, which is not correct

    if the file does not exist ("xplvl.txt") it will return nothing..

    just do "xplvl" and the name is capital sensitive (xplvl is not XPlvl)

  10. #10

    Thread Starter
    Member
    Join Date
    Nov 2007
    Posts
    62

    Resolved Re: [2008] Trying to use my.resources for a text file

    oh wow..can't believe I missed that..

    I guess we all make mistakes sometimes

    Thanks a bunch for everything!

    Posted as resolved

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width