|
-
Dec 1st, 2007, 06:03 PM
#1
Thread Starter
Member
[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.
-
Dec 1st, 2007, 06:24 PM
#2
Frenzied Member
Re: [2008] Trying to use my.resources for a text file
Ok, try this, this should work
vb.net Code:
Dim TempValue As String = ""
Using sr As New Resources.ResourceReader(My.Resources.lxltxt)
TempValue = sr.ReadToEnd() '
End Using
'lvlXP contents is in TempValue now, if you need to store in an array
Make TempValue an array, and use sr.ReadLine()
-
Dec 1st, 2007, 06:26 PM
#3
Thread Starter
Member
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
-
Dec 1st, 2007, 06:28 PM
#4
Thread Starter
Member
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.
-
Dec 1st, 2007, 06:42 PM
#5
Frenzied Member
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...
-
Dec 1st, 2007, 06:48 PM
#6
Thread Starter
Member
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.
-
Dec 1st, 2007, 07:04 PM
#7
Frenzied Member
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:
Dim MyTempFilePath As String = My.Computer.FileSystem.SpecialDirectories.AllUsersApplication.Data & "\MyApplicationName\lvltxt.txt"
Using sw As New StreamWriter(MyTempFilePath)
sw.Write(My.Resources.ResourceManager.GetObject("filename"))
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:
File.Delete(MyTempFilePath)
Personally I have a class called 'DirectoriesC' which has all my directories \ names for things like this:
vb.net Code:
Dim ad As String = My.Computer.FileSystem.SpecialDirectories.AllUsersApplicationData
Dim ProgramName As String = "thething"
Dim TempLvlExpName As String = "lvlxp_temp"
Dim TempLvlExpExt As String = ".txt"
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)
-
Dec 1st, 2007, 07:45 PM
#8
Thread Starter
Member
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.
-
Dec 1st, 2007, 07:55 PM
#9
Frenzied Member
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)
-
Dec 1st, 2007, 07:58 PM
#10
Thread Starter
Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|