Question

CobiHopkins on Mon, 16 Jan 2017 17:12:38


Ok, to rephrase my question so everybody knows exactly what I'm trying to do here.

I have an application which I am designing for a college assignment. The purpose of this application is to purchase items (e.g. weapons, armor, etc.) for a character in a game. 

My application, specifically, allows users to purchase items from several tree views. Each tree view offers a different type of weapon (e.g. Treeview1 will store weapons; Treeview2 will store Armor; Treeview3 will store vehicles, and so on). Currently, this function works. However, it only works on the machine I used to create the application. This is because I am using a StreamReader to retrieve information from a text file. It has been made clear to me that StreamReaders are not needed in this case because the file already exists within the application. However, it is currently reading data from a text file stored on my computer's C: drive. For this to work on another machine, it would have to have the exact same location as my computer. Of course, this is never going to be the case, so I need a way to retrieve the data from a text file no matter which computer in the world is being used while retaining the current level of functionality my existing code offers and then some.

So, how do I adapt the following code to work on ANY machine while retaining the desired function? My current code is as follows:

 Dim userCoins As Single = 0.00 ' Store the amount of coins the user has.
    Dim userExperience As Long = 0 'Store the users experience points.
    Dim userLevel As Integer = 1 'Store the users level - increases based on experience.
    Dim userDefenceLevel As Single = 100 'Store user defence level (protection level) - default protection level is 100.
    Dim userOffenceLevel As Single = 100 'Store user offence level - default offence level is 100.
    Dim userMagicalLevel As Single = 100 'Store user magical level - default magical level is 100.

    'Variables for storing treeview selection.
    Dim addItemPrice As Single = 0 'Store coin value of selected item (treeview).
    Dim addDefenceLevel As Single = 0 'Store defence level value of selected item (treeview).
    Dim addOffenceLevel As Single = 0 'Store offence level value of selected item (treeview).
    Dim addMagicalLevel As Single = 0 'Store magical level value of selected item (treeview).
    Dim itemChoice As String 'Store text value of selected item (treeview)

  Sub Main()
        'Retreive information from itemvalues.txt and return information for the selected node.
        'cLine equals the value of stream.ReadLine() - stream.ReadLine() reads line from a text file.
        'Print cLine to console.
        'while cLine stores the value of selected node: enable purchase button; store cLine in itemChoice; read next line;
        'Store cLine in addItemChoice; read new line; store cLine in addDefenceLevel; read new line; store cLine in addOffenceLevel;
        'Read new line; store cLine in addMagicalLevel; Clear listbox; add variable values to listbox; end while loop.
        'close stream when cLine has no value; return message when an exception is found.

        Try

            Dim stream As StreamReader = New StreamReader("C:\Users\cobihopkins\documents\visual studio 2015\Projects\characterGame\characterGame\Resources\itemvalues.txt")
            Dim cLine As String = ""

            Do
                cLine = stream.ReadLine()
                Console.WriteLine(cLine)

                While cLine = trvArmour.SelectedNode.Text
                    btnPurchase.Enabled = True
                    itemChoice = cLine
                    cLine = stream.ReadLine()
                    addItemPrice = cLine
                    cLine = stream.ReadLine()
                    addDefenceLevel = cLine
                    cLine = stream.ReadLine()
                    addOffenceLevel = cLine
                    cLine = stream.ReadLine()
                    addMagicalLevel = cLine

                    lstShopItemSpec.Items.Clear()
                    lstShopItemSpec.Items.Add("Item Name: " & itemChoice)
                    lstShopItemSpec.Items.Add("Price: " & addItemPrice & " Coins.")
                    lstShopItemSpec.Items.Add("Defence Level: +" & addDefenceLevel)
                    lstShopItemSpec.Items.Add("Offence Level: +" & addOffenceLevel)
                    lstShopItemSpec.Items.Add("Magic Level: +" & addMagicalLevel)
                End While

            Loop Until cLine Is Nothing
            stream.Close()
        Catch E As Exception
            Console.WriteLine("The file could Not be read")
            Console.WriteLine(E.Message)
        End Try

    End Sub

The code displayed above does the following:

The data in my text file named "itemvalues.txt" is streamed to the application and it is read by the variable called "stream". Next, I store the line that is currently being read by the StreamReader in a variable called "cLine". Next, the user will select a child node in one of my tree views. In this case, it's set to one of the nodes in "trvArmour". 

Once this node has been selected, cLine will store the text value of the selected node (e.g. "Helmet1"). While cLine is storing this text value, the control "btnPurchase" will be enabled. This will also set the variable itemChoice to be set to the string value of cLine (e.g. "Helmet1"). itemChoice is a variable that I have created to store the name of the item in permanently until the item has been purchased. Once the item has been purchased, itemChoice is reset to nothing. The reason for this is because cLine isn't a constant variable. It changes almost instantly. So I need a method for storing the name of the item until I choose otherwise.

So, after storing the text value of cLine in itemChoice, the next line in the text file is read. This value, again, will be stored in cLine (see how it has changed already). The value that is now being stored in cLine will then be stored (permanently as we previously did with itemChoice) in addItemPrice. This is because the next line in the file is always going to be the price of the item (as seen in the picture below). This code will then do the same for the offense and magic levels for the player.

So, my question to you people is this....

How can I read text from a text file stored in my applications resources before utilizing that text in the same way that I have done in my previous code?



Sponsored



Replies

Frank L. Smith on Mon, 16 Jan 2017 17:29:25


Cobi,

Explain more about what "doesn't work". What does your program do and what does it do (or not do) on the other computer?

Usually your description points to one or more missing assemblies (like third-party dll's, etc.), but so far that's speculative.

Is an exception thrown? If so, what's the exception?


"One who has no vices also has no virtues..."


CobiHopkins on Mon, 16 Jan 2017 17:39:17


Cobi,

Explain more about what "doesn't work". What does your program do and what does it do (or not do) on the other computer?

Usually your description points to one or more missing assemblies (like third-party dll's, etc.), but so far that's speculative.

Is an exception thrown? If so, what's the exception?


"One who has no vices also has no virtues..."


Sorry, I just noticed I was a bit vague on my explanation.

My application allows users to purchase items for their character. Items can be purchased by selecting items in tree views which are displayed throughout tabs in the application. I expect the user to be able to select a child node which will then activate a purchase button. The problem I am having is that the purchase button does not get activated when the user selects the child node.

Note: This works on the system where I created the application. It doesn't, however, work on any other system that I try testing it on. I feel like the application isn't reading from the text file as it should be, but I'm not entirely sure. I think this because the action I stated previously is performed when the variable "cLine" holds the same value as the text property of the selected node.

I hope this explains it well enough for you. I will attempt to offer an image to show how I expect it to work.

I noticed I was being given an error after using the code "My.resources.itemvalues" so it appears to me that I have written something wrong there. However, the application won't be able to read the information from an exact location on MY computer if the application is on somebody else's system, so how do I tell it to read from a resource text file?


C.Hopkins



Frank L. Smith on Mon, 16 Jan 2017 17:44:10


...I feel like the application isn't reading from the text file as it should be...

I was going to comment on that but I won't. I'll instead suggest this:

If your resources has a text file in it, then read it like a string:

Dim s As String = My.Resources.MyTextFile

(whatever it's called in your actual one).

Try that in your development one please? In yours, you're leaving a stream open but you shouldn't need a StreamReader anyway.

Cor Ligthert on Mon, 16 Jan 2017 17:57:37


Cobi,

The resources are not a files, it is a feature in .Net program languages with which you can put data likewise objects, strings and images fixed in the assembly (exe). 

To get it is this enough.

  Dim cline = My.Resources.itemvalues

You cannot stream it using a streamreader because it is already there. 

(If you are programming it is one of the files used by the program builder to build the assembly)

CobiHopkins on Mon, 16 Jan 2017 17:58:31


...I feel like the application isn't reading from the text file as it should be...

I was going to comment on that but I won't. I'll instead suggest this:

If your resources has a text file in it, then read it like a string:

Dim s As String = My.Resources.MyTextFile

(whatever it's called in your actual one).

Try that in your development one please? In yours, you're leaving a stream open but you shouldn't need a StreamReader anyway.


"One who has no vices also has no virtues..."

I'm confused by what I'm to do with that piece of code, so could you copy my function from the initial post and implement it as you would expect me to, please? All I can think of is the following but it doesn't work and it also doesn't seem like that's what is expected anyway:

From what you said, I assume you are saying to remove the StreamReader but I'm not 100% sure. I'm still new to VB and everything I work with has comments alongside the code so I can understand the purpose.

Thanks.

Frank L. Smith on Mon, 16 Jan 2017 18:01:00


Cobi,

Confirm please that you put a text file in the resources. If so, can you show an excerpt (a few lines) from that text file?

(By the way, XML in the resources would work really well here).

CobiHopkins on Mon, 16 Jan 2017 18:08:23


Cobi,

Confirm please that you put a text file in the resources. If so, can you show an excerpt (a few lines) from that text file?

(By the way, XML in the resources would work really well here).


"One who has no vices also has no virtues..."

Correct. I have my text file in the resources. 

The following is the layout of my text file. I understand the way in which my elements are set out may be outside of the norm but this seemed like the easier way for me to go about reading elements from the file.

Please note that Line 1, Line 6, and Line 11 are the names of the items (exactly the same as the text property within the child nodes of my tree views). Lines 2, 7, and 12 are the item prices. 3, 8, and 13 are the item Defence Levels; 4, 9, and 14 are offense levels; and 5, 10, 15 are magic levels - all of these are added to the player's character upon purchasing the items as can be seen in the previous post images in the top right corner.

Edit: I have attempted XML previously as you have offered me some code to implement that, however, it appeared to be too complex for my limited ability at this time. As I stated previously, I only have 2 - 3 weeks experience working with VB and that is not working on it every day.


C.Hopkins



Frank L. Smith on Mon, 16 Jan 2017 18:11:47


Cobi,

I'll show you what I mean. I typed out a little text file and put it on my desktop then I added that file into the resources.

The file's contents are shown below:

The quick
brown fox
jumps over
the lazy dog

Yes I know, how unique of me. ;-)

The resource's name is "ExampleTextFile" and I tested it following:

Option Strict On Option Explicit On Option Infer Off Public Class Form1 Private Sub Form1_Load(sender As System.Object, _ e As System.EventArgs) _ Handles MyBase.Load Dim s As String = My.Resources.ExampleTextFile Stop Dim lines() As String = _ My.Resources.ExampleTextFile.Split(New String() {vbCrLf}, _ StringSplitOptions.RemoveEmptyEntries) Stop End Sub End Class


The first one ("s") just reads it like it's a string because it is. If you have a need to read the lines into an array though, the second one should work.

See what I mean?


"One who has no vices also has no virtues..."


CobiHopkins on Mon, 16 Jan 2017 18:40:09


Cobi,

I'll show you what I mean. I typed out a little text file and put it on my desktop then I added that file into the resources.

The file's contents are shown below:

The quick
brown fox
jumps over
the lazy dog

Yes I know, how unique of me. ;-)

The resource's name is "ExampleTextFile" and I tested it following:

Option Strict On Option Explicit On Option Infer Off Public Class Form1 Private Sub Form1_Load(sender As System.Object, _ e As System.EventArgs) _ Handles MyBase.Load Dim s As String = My.Resources.ExampleTextFile Stop Dim lines() As String = _ My.Resources.ExampleTextFile.Split(New String() {vbCrLf}, _ StringSplitOptions.RemoveEmptyEntries) Stop End Sub End Class


The first one ("s") just reads it like it's a string because it is. If you have a need to read the lines into an array though, the second one should work.

See what I mean?


"One who has no vices also has no virtues..."


So using this, how would I achieve my desired outcome? I ask this because I see it reading everything from the file and storing in the variable "s", but I don't know how to then utilize that? I assume I would use the "lines()" version instead but I still don't understand how to make what I previously had happen, when a node is selected, actually happen.

Desired Outcome:

When the player selects a node in one of my tree views, it finds the line in the text file which has the exact text value of  TreeView1.selectednode.Text and then stores that text value in a new variable called itemChoice before picking up the information about that item, such as the defense level, offense level, magic level, price, etc?

To show you what I mean, I'll once again offer the previous code which allowed that to happen.

Sub Main()
        'Retreive information from itemvalues.txt and return information for the selected node.
        'cLine equals the value of stream.ReadLine() - stream.ReadLine() reads line from a text file.
        'Print cLine to console.
        'while cLine stores the value of selected node: enable purchase button; store cLine in itemChoice; read next line;
        'Store cLine in addItemChoice; read new line; store cLine in addDefenceLevel; read new line; store cLine in addOffenceLevel;
        'Read new line; store cLine in addMagicalLevel; Clear listbox; add variable values to listbox; end while loop.
        'close stream when cLine has no value; return message when an exception is found.

        Try

            Dim stream As StreamReader = New StreamReader("C:\Users\cobihopkins\documents\visual studio 2015\Projects\characterGame\characterGame\Resources\itemvalues.txt")
            Dim cLine As String = ""

            Do
                cLine = stream.ReadLine()
                Console.WriteLine(cLine)

                While cLine = trvArmour.SelectedNode.Text
                    btnPurchase.Enabled = True
                    itemChoice = cLine
                    cLine = stream.ReadLine()
                    addItemPrice = cLine
                    cLine = stream.ReadLine()
                    addDefenceLevel = cLine
                    cLine = stream.ReadLine()
                    addOffenceLevel = cLine
                    cLine = stream.ReadLine()
                    addMagicalLevel = cLine

                    lstShopItemSpec.Items.Clear()
                    lstShopItemSpec.Items.Add("Item Name: " & itemChoice)
                    lstShopItemSpec.Items.Add("Price: " & addItemPrice & " Coins.")
                    lstShopItemSpec.Items.Add("Defence Level: +" & addDefenceLevel)
                    lstShopItemSpec.Items.Add("Offence Level: +" & addOffenceLevel)
                    lstShopItemSpec.Items.Add("Magic Level: +" & addMagicalLevel)
                End While

            Loop Until cLine Is Nothing
            stream.Close()
        Catch E As Exception
            Console.WriteLine("The file could Not be read")
            Console.WriteLine(E.Message)
        End Try

    End Sub

Sorry for so many questions. I know it can be annoying when someone can't exactly grasp what probably seems like such a simple concept to people with more experience and knowledge of the subject.

Frank L. Smith on Mon, 16 Jan 2017 18:44:44


So using this, how would I achieve my desired outcome?

That's beyond the scope of your question which was about it not working on another machine.

Did you try it?

Frank L. Smith on Mon, 16 Jan 2017 19:03:29


Cobi,

I'll add this also: I'll be amazed if it has *anything* to do with reading a string in the resources - no matter how it's done (but if you use a StreamReader, close/dispose it after use each time).

I mean no offense but I think the issue exists on your development machine also - at least if it hits the right combination of things.

I don't fully understand what you have or want, but I suspect that a redesign might be in order here...

CobiHopkins on Mon, 16 Jan 2017 19:05:05


So using this, how would I achieve my desired outcome?

That's beyond the scope of your question which was about it not working on another machine.

Did you try it?


"One who has no vices also has no virtues..."

Yes, it reads from the text file. But that wasn't my question. That was a suspicion of mine which turns out to be true. But I still haven't got a step closer to resolving my issue because the functionality remains the same.

Frank L. Smith on Mon, 16 Jan 2017 19:07:12



Yes, it reads from the text file. But that wasn't my question. That was a suspicion of mine which turns out to be true. But I still haven't got a step closer to resolving my issue because the functionality remains the same.


C.Hopkins

I agree - it helps to be safer reading the text, but that's not the problem and never was.

Honestly, you're in the best position to work out what's going on. Step through each line of code and think it through.

Mr. Monkeyboy on Mon, 16 Jan 2017 19:26:10


Cobi,

Explain more about what "doesn't work". What does your program do and what does it do (or not do) on the other computer?

Usually your description points to one or more missing assemblies (like third-party dll's, etc.), but so far that's speculative.

Is an exception thrown? If so, what's the exception?


"One who has no vices also has no virtues..."


Sorry, I just noticed I was a bit vague on my explanation.

My application allows users to purchase items for their character. Items can be purchased by selecting items in tree views which are displayed throughout tabs in the application. I expect the user to be able to select a child node which will then activate a purchase button. The problem I am having is that the purchase button does not get activated when the user selects the child node.

Note: This works on the system where I created the application. It doesn't, however, work on any other system that I try testing it on. I feel like the application isn't reading from the text file as it should be, but I'm not entirely sure. I think this because the action I stated previously is performed when the variable "cLine" holds the same value as the text property of the selected node.

I hope this explains it well enough for you. I will attempt to offer an image to show how I expect it to work.

I noticed I was being given an error after using the code "My.resources.itemvalues" so it appears to me that I have written something wrong there. However, the application won't be able to read the information from an exact location on MY computer if the application is on somebody else's system, so how do I tell it to read from a resource text file?


C.Hopkins



Well I believe My.Resources.itemvalues would be an expectation for an embedded resource rather than a text file called "itemvalues" located in a resources folder.

Perhaps you should place the files you want to use in the same location the .Exe created for the Console App will be in (the bin\debug or bin\release folder of your Console app on your VM development system).

I have zero idea what you do when you place files on a different system. However if you place the executable of the Console app in some folder on a different system and also place all files your Console app needs to access in the same location as the executable then you can probably use code to get the executables path when the Console app launches in order to know the path where your files reside.

Reed Kimble on Mon, 16 Jan 2017 19:26:34


I think the most important question is:  how did you "copy the files to another computer"?

Have you tried doing a Publish of the application and running the installation package on the other computer?  You could probably go back to your original code (with a small change to the file path you access) and just add that text file on your C drive to the project and set it to copy to output = always.  Your code can then access the file using IO.Path.Combine(My.Application.Info.DirectoryPath, "the file name.txt") and this will resolve to the location of the file on both your development PC and the end user's PC after installation.

Frank L. Smith on Mon, 16 Jan 2017 19:41:41


I think the most important question is:  how did you "copy the files to another

Reed,

Normally I'd fully agree but if I'm right (a guess), his program isn't that complex.

I suspect that it may be no more complex than his .exe that's produced as a result of him building the \Release version and then copying that one file to the other computer.

*****

Cobi - that is what you did, correct?

Cor Ligthert on Mon, 16 Jan 2017 19:45:24


I think the most important question is:  how did you "copy the files to another computer"?

Have you tried doing a Publish of the application and running the installation package on the other computer?  You could probably go back to your original code (with a small change to the file path you access) and just add that text file on your C drive to the project and set it to copy to output = always.  Your code can then access the file using IO.Path.Combine(My.Application.Info.DirectoryPath, "the file name.txt") and this will resolve to the location of the file on both your development PC and the end user's PC after installation.


Reed Kimble - "When you do things right, people won't be sure you've done anything at all"

Reed,

Then I'm very curious how you get that code running even on your own computer. I assume she first has simply taken the RESX path from the development folder and is that forgotten. 

However, the My.Recourses is never in a folder. It is in the Resources.RESX in the a development forum depending of the version of Visual Studio.

 I see currently moderators give additions to every reply. 

Those moderator replies are 

  1. Sometimes good, the same as other contributors
  2. Sometimes completely out of context but it seems they think they must add something to a thread
  3. Sometimes hopeless outdated (I'm not particularly pointing to you)

We should avoid that, a community is not build around moderators.

In this case we should wait what Cobi was replying but she does not even get the change likewise in that other thread of her.

In fact have Frank and I given the answer already so you can simply propose them.  


Success
Cor


Mr. Monkeyboy on Mon, 16 Jan 2017 19:50:29


Yes, it reads from the text file. But that wasn't my question. That was a suspicion of mine which turns out to be true. But I still haven't got a step closer to resolving my issue because the functionality remains the same.


C.Hopkins

This code may assist you if you place the files your app will read from in the location of the .exe. It is probably not the recommended method. But for test purposes may get you by.

However the real issues are that you haven't learned about how to correctly install an app on another system using an installer creator to creat an installer for doing so. Or by manually performing that. Such that the app has access to everything it uses on the development system in development once it is actuall installed.

How to make certain the resources folder is provided with the app and where in relation to the app it should be placed in whatever the appropriate folder paths should be perhaps.

How to not hard code a path to the resources folder that files will be in you want to use.

I never use the resources folder as far as placing files in it for my apps to use although I suppose that may be what peeps do.

There are even recommended folders by Microsoft for placing files in to be used by an app that is installed on a system even if it is installed onto the development system for test purposes to make sure the installer that the installer creator created works correctly and then that the app works correctly.

So being naive to much necessary information will lead a programmer astray as they have no grasp on the concepts necessary from development to installation of an app.

There are numerous threads about apps not working on other systems. Most seem to be due to app creator not having knowledge about what an app requires when installed on even the development system much less another system using an installer creator to create an installer for the app much less manually providing an app to the development system much less another system.

Option Strict On

Imports System.Windows.Forms ' Add ref, Assemblies, Framework, System.Windows.Forms

Module Module1

    Sub Main()
        Dim s As String = Application.StartupPath
        Console.WriteLine(s)
        For Each Item In IO.Directory.GetFiles(s, "*.Txt")
            Console.WriteLine(Item)
        Next
        Console.WriteLine()
        Using SR As New IO.StreamReader(IO.Path.Combine(s, "Test Commands.Txt"))
            Console.WriteLine(IO.Path.Combine(s, "Test Commands.Txt"))
            Do Until SR.EndOfStream
                Console.WriteLine(SR.ReadLine)
            Loop
        End Using
        Console.ReadLine()
    End Sub

End Module


La vida loca

Reed Kimble on Mon, 16 Jan 2017 20:07:29


I think the most important question is:  how did you "copy the files to another

Reed,

Normally I'd fully agree but if I'm right (a guess), his program isn't that complex.

I suspect that it may be no more complex than his .exe that's produced as a result of him building the \Release version and then copying that one file to the other computer.

*****

Cobi - that is what you did, correct?


"One who has no vices also has no virtues..."

You are probably correct, however, that doesn't make the Publish useless... I still maintain it is the simplest solution to the problem.

This one line of code:

Dim stream As StreamReader = New StreamReader("C:\Users\cobihopkins\documents\visual studio 2015\Projects\characterGame\characterGame\Resources\itemvalues.txt")

Needs to be changed to:

Dim stream As StreamReader = New StreamReader(Path.Combine(My.Application.Info.DirectoryPath, "itemvalues.txt"))

And then the itemvalues.txt file is added to the solution (Add -> Existing File) and its Copy to Output Directory property value is set to Copy Always.

The publish will now include and distribute this text file, but even without it, the file just needs to be copied along with the EXE.

Adding the file to the application resources is perfectly acceptable, it really comes down to whether or not you want the text file accessible outside of the application.

Reed Kimble on Mon, 16 Jan 2017 20:10:38


I assume she first has simply taken the RESX path from the development folder and is that forgotten. 


Success
Cor


I agree that was the problem when trying to adapt the code to use the text file from resources.

But the question has been edited and going from the original code, I think it is easiest to make the modification I suggest above and add the text file to the project as output.

Frank L. Smith on Mon, 16 Jan 2017 20:15:00


Reed,

If it's in the resources it can stay there and a "reader" of any sort isn't needed.

I'm hoping we'll get to better ways of doing all of this but it's contingent on him figuring it out on his own.

*****

I'm not yet convinced this has anything to do with the *real* problem, by the way...

CobiHopkins on Wed, 18 Jan 2017 08:37:06


I have found a fix. Whether it is ideal and logical in the eyes of others, I don't know. But for this assignment, it will do the job. It does leave the game open to slight modifications from the end-user by making alterations to the text file containing the data but in this case, that's ok. 

Sub Main() 'Retreive information from itemvalues.txt and return information for the selected node. 'cLine equals the value of stream.ReadLine() - stream.ReadLine() reads line from a text file. 'Print cLine to console. 'while cLine stores the value of selected node: enable purchase button; store cLine in itemChoice; read next line; 'Store cLine in addItemChoice; read new line; store cLine in addDefenceLevel; read new line; store cLine in addOffenceLevel; 'Read new line; store cLine in addMagicalLevel; Clear listbox; add variable values to listbox; end while loop. 'close stream when cLine has no value; return message when an exception is found. Try ' THE FOLLOWING 8 LINES OF CODE FIXED MY PROBLEM.

Dim findFile As System.IO.FileInfo findFile = My.Computer.FileSystem.GetFileInfo("itemvalues.txt") Dim folderPath As String = findFile.DirectoryName Dim fileName As String = findFile.Name Dim filePath As String filePath = My.Computer.FileSystem.CombinePath(folderPath & "\Resources", fileName) Dim stream As StreamReader = New StreamReader(filePath) Dim cLine As String = "" Do cLine = stream.ReadLine() Console.WriteLine(cLine) 'Working but only for trvAmour - can't add Or trvWeapons While cLine = trvArmour.SelectedNode.Text btnPurchase.Enabled = True itemChoice = cLine cLine = stream.ReadLine() addItemPrice = cLine cLine = stream.ReadLine() addDefenceLevel = cLine cLine = stream.ReadLine() addOffenceLevel = cLine cLine = stream.ReadLine() addMagicalLevel = cLine lstShopItemSpec.Items.Clear() lstShopItemSpec.Items.Add("Item Name: " & itemChoice) lstShopItemSpec.Items.Add("Price: " & addItemPrice & " Coins.") lstShopItemSpec.Items.Add("Defence Level: +" & addDefenceLevel) lstShopItemSpec.Items.Add("Offence Level: +" & addOffenceLevel) lstShopItemSpec.Items.Add("Magic Level: +" & addMagicalLevel) End While Loop Until cLine Is Nothing stream.Close() Catch E As Exception Console.WriteLine("The file could Not be read") Console.WriteLine(E.Message) End Try End Sub

The text file path will be generated on any computer and will read the text file from that location. The text file must be in a resources folder inside the same directory as the game executable file. Because of this, I have stored the game and a resources folder together for downloading. Not ideal, but this will work for me.


C.Hopkins


Frank L. Smith on Wed, 18 Jan 2017 13:25:48


I have found a fix. Whether it is ideal and logical in the eyes of others, I don't know. But for this assignment, it will do the job.

Good work then! :)