Page 1 of 2 12 LastLast
Results 1 to 40 of 44

Thread: [RESOLVED] Using Resources

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jan 2016
    Location
    Anderson, SC
    Posts
    70

    Resolved [RESOLVED] Using Resources

    In previous posts I explained that I was having a problem getting a project from my computer to another computer. Both computers apparently are running 4 Framework but on my computer my project properties shows 4.5 for the FrameWork.

    When I access the project on the 2nd computer, which has VB 2013 installed, and to which I have copied the folder that contains my project, Debug results in an error that says my call to use a file, .jpg, from the computer's C:\ (which as the specified .jpr there) it can't do it as it says ".. path doesn't exist ...", where the path is, e.g.

    Directory = "c:\Boscobel Fly Over Video Data\"
    AdPicture.Image = Image.FromFile(Directory & "hole 0.jpg")

    Directory is a string defined in my Module.

    Due to this problem (getting both the project and its deployment files to the 2nd computer) I am thinking that putting all my .jpg, .mp4, and two .txt files in Resources. However, being new (only several week of using VB 2013) I have tried to find the code to "grab" a .jpg to place in a PictureBox or a .mp4 to put in a MultimediaBox or read the lines of text in the .txt files. All links are don't explain how to do this the same way.

    I would appreciate some help (either links to go to or actual code) in trying to use Resources. I think I can put the files in Resources but a explanation of that would certainly help.

    While wait patiently for your replies I will set up a test project, add resources, and placing them in either a PictureBox or mediaplayer. Probably leave the reading of the .txt files until later.

  2. #2
    Super Moderator dday9's Avatar
    Join Date
    Mar 2011
    Location
    South Louisiana
    Posts
    11,715

    Re: Using Resources

    To assign a PictureBox's Image from an image in your Resources it's as simple as:
    Code:
    MyPictureBox.Image = My.Resources.MyPictureName
    The same goes for your MP4 file(I think). Your text file will be a little bit different in the fact that it will be stored as one long String:
    Code:
    Dim myTextFile As String = My.Resources.MyTextFileName
    To get the lines you'd then split that String:
    Code:
    Dim lines() As String = myTextFile.Split({Environment.NewLine})
    "Code is like humor. When you have to explain it, it is bad." - Cory House
    VbLessons | Code Tags | Sword of Fury - Jameram

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Jan 2016
    Location
    Anderson, SC
    Posts
    70

    Re: Using Resources

    Well, I will try those in a test file. VB 2013 is very frustrating and I have been using Basic for over 20 years. VB 6 was very easy and straight forward to use.

  4. #4
    Super Moderator dday9's Avatar
    Join Date
    Mar 2011
    Location
    South Louisiana
    Posts
    11,715

    Re: Using Resources

    To each their own.

    If you try to use VB.NET like it was VB6 then you'll only become frustrated.
    "Code is like humor. When you have to explain it, it is bad." - Cory House
    VbLessons | Code Tags | Sword of Fury - Jameram

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Jan 2016
    Location
    Anderson, SC
    Posts
    70

    Re: Using Resources

    I am learning and can make a great project using VB 2013 but can't get it on another computer which is why I am thinking of trying to use Resources for all the .jpg, .mp4, and .txt file. But damn tough to figure out how to do such a simple task. For example, I can't find out how to add the files to Resource which I don't see in the solution's frame. I tried the "Add Items" but don't understand that or how it creates a Resource file.

    How do you create a Resource in the Solution? I did it in one project but can't figure out how to do in a test project using you codes.
    Last edited by movingonto2013; Jan 22nd, 2016 at 11:45 AM.

  6. #6
    Super Moderator dday9's Avatar
    Join Date
    Mar 2011
    Location
    South Louisiana
    Posts
    11,715

    Re: Using Resources

    In Visual Studio 2013 here are the steps to add your files to My.Resources:
    1. Double-click on My Project in the solution explorer
    2. Click on the Resources tab on the left hand side
    3. Click on the Add button
    4. Select Add Existing Item


    From there it will bring up a file browser dialog and you can select the items that you wish to include.
    "Code is like humor. When you have to explain it, it is bad." - Cory House
    VbLessons | Code Tags | Sword of Fury - Jameram

  7. #7

    Thread Starter
    Lively Member
    Join Date
    Jan 2016
    Location
    Anderson, SC
    Posts
    70

    Re: Using Resources

    Ok, thanks. That worked, i.e. have a Resource folder (I guess that is what it is) and a graphic in it.. Have a graphic there. Next will do a sub Form1_Load to get the
    picture in the picturebox1.

    Maybe if a simple test project works, i.e. use a .jpg, .mp4, and .txt files, then I can go back to my real project and try to change the code to use resources that I already have put there.

  8. #8

    Thread Starter
    Lively Member
    Join Date
    Jan 2016
    Location
    Anderson, SC
    Posts
    70

    Re: Using Resources

    I don't understand, "MyPictureBox.Image = My.Resources.MyPictureName". My PictureBox is named "AdPicture". The resource image I want to use is named, "hole 0.jpg".

    so what is the code I should use?

  9. #9
    Super Moderator dday9's Avatar
    Join Date
    Mar 2011
    Location
    South Louisiana
    Posts
    11,715

    Re: Using Resources

    so what is the code I should use?
    I really don't mind helping you, I just want you to understand how frustrating it is when you don't put forth any effort on your behalf.

    My PictureBox is named "AdPicture". The resource image I want to use is named, "hole 0.jpg".
    In my example change the control name of MyPictureBox to AdPicture and change the resource name of MyPictureName to your resource name which if there was a space(hole 0) then VS probably replaced the space with an underscore(hole_0) since there cannot be any spaces in a Resource name.
    Code:
    AdPicture.Image = My.Resources.hole_0.jpg
    "Code is like humor. When you have to explain it, it is bad." - Cory House
    VbLessons | Code Tags | Sword of Fury - Jameram

  10. #10
    You don't want to know.
    Join Date
    Aug 2010
    Posts
    4,578

    Re: Using Resources

    When I have tried this (and I did, the other day, in a thread I spent an hour writing about this same topic for the same user), I found that adding files as a resource trimmed the extension off of it. So the variable name would be "My.Resources.hole_0". But this is also something Intellisense would guide one to, that's part of the dangers of pasting code. And it could be something unique to how I added the resources, there's at least two different ways.

    movingonto2013, I think it would be best to solve your problems with using files first, before abandoning them for resources. It sort of suggests there's a problem with your deployment methodology, and it could be that you exchange one set of errors for another when doing this. File access is pretty fundamental, and if it's not working for you there could be other problems that make even My.Resources not work.

    Still, this is part of the frustration of helping over the internet. I'm pretty sure if I was at your desk, I could find the problem and tell you how to address it in less than 10 minutes. But I'm not. Even if you give me all of your code and project files, it could be that I set it up on my machine in a way that works when the problem is a tiny typo on the failing machine. I've lost a lot of time to file names and directories that had two spaces instead of one. It's very hard to catch, and even though my eyes are young a lot of computer text is irresponsibly small.

    One problem I find is when people approach a problem like this, their mentality is "It should be working", and as such they make accidental assumptions that help cloud reality. It's not working. So you know something's wrong. The right approach is to look at every detail and prove it's right before moving on. This is one of the hardest things to do when you're new to a language, which is why I suggest slow, gentle progress over the course of a few weeks instead of diving in head-first.

    But it's not VB 2013's fault. If there were a reproducible bug with file I/O, Microsoft would know, and thoussands of people would be complaining. File I/O's working for those thousands of people, and they've all managed to deploy a project with satellite files. That means that the problem must lie in something unique to your configuration. Hopping from solution to solution won't make it easier to figure that out. What you need to do is learn what you have done wrong, so you can stop making that mistake in the future.
    This answer is wrong. You should be using TableAdapter and Dictionaries instead.

  11. #11

    Thread Starter
    Lively Member
    Join Date
    Jan 2016
    Location
    Anderson, SC
    Posts
    70

    Re: Using Resources

    Sitten Spynne:

    Thanks for the reply. Yep, I know it has to be something in my project that was developed on my computer doesn't work on another computer. So, since I have eyt to find what is wrong or any posts here that can lead me to a solution I will "punt" by doing the following:

    1. Bring the other computer home so I can work with it using my mouse, keyboard, and monitor.
    2. Develop the project again by duplicating the Design (a full screen media player, list box, picturebox, and several labels).
    3. Copy the code from my computer project to a NotePad file which is then put on a flash drive
    4. Copy the code from the NotePad file (just a .txt) file on the flash drive now in the "other" computer.
    5. Paste it into code in the "other" computer code.
    6. Fiddle with everything until it run OK, i.e. Debugs has no errors
    7. Build and deploy the project to the "other" computer which is were is being developed.

    I have been writing computer programs since 1965 when I used FORTRAN on a IBM 360 main frame. This was with a natural gas corporation research department. Switched to Basic when it became available on personal computers. Wrote Expert System programs to replace an expert engineer who was being promoted and a new engineer would have to take over his task of diagnosis problems with a Glycol Dehydration plant which involved about 15 different tests that could be run which he was the only one who knew how. Worked great. Also did a Basic project to design Regulator Station which was easy as only about 15 things to check off so the proper station could be built.

    Used my Expert System background to computerize the rating of golf courses (you can read about this at http://www.usga.org/handicapping-art...-e5bf725f.html). Project took over six months and is constantly being updates. My system is being used by raters in Brazil, Puerto Rico, South Africa, Hungry, and Russia.

    Yes, I know just about all the errors that one can make programming. But this one is tough due to my lack of experience with VB 2013. Maybe a time in the future when I will go back, find the error, beat my head against the nearest wall, and get it to finally working. But for now, develop the project on the "offending" computer and be done with it.

    By the way, you can view a short video of my project at http://visualgolfsoftware.com/fly%20over%20video.mp4. As you can see, just a full screen (more or less) media player showing a fly over by a drone of a golf course. I just took the raw video, timed it so when it switched to a different hole the picturebox at lower right would change plus the description (tips) for playing hole. Simple Project, well, once you know how to use VB 2013. All .mp4, .jpg, and tips are read in from C:/

  12. #12

    Thread Starter
    Lively Member
    Join Date
    Jan 2016
    Location
    Anderson, SC
    Posts
    70

    Re: Using Resources

    TO ALL WHO HAVE REPLIED -

    On my "other" computer, which has VB 2013 installed, I started a simple project, a Form1, with a Media Player on it. In the Code I placed this:

    Directory = "c:/Boscobel Fly Over Video Data/"

    Dim fileReader As System.IO.StreamReader
    Dim stringReader As String


    fileReader = My.Computer.FileSystem.OpenTextFileReader(Directory & "hole tips.txt")

    I also used:

    fileReader = My.Computer.FileSystem.OpenTextFileReader("c:/Boscobel Fly Over Video Data/hole tips.txt")

    I further used a capital "C" rather than a lower case "c".

    In all case, on my other computer I get the error message that "...path is not there ...".

    What could possibly be the difference between the two computer to cause this? It is not the FrameWork as both project use 4.5.
    I even went through the process of starting with My. and added as needed in each step.

    I am at the edge of the cliff now and have no idea how to proceed.

  13. #13
    You don't want to know.
    Join Date
    Aug 2010
    Posts
    4,578

    Re: Using Resources

    Well, that's still a "/" instead of a "\", which is generally more important than the case of the file. That was something you didn't say you tried. Here's what I would do.

    We need to be able to sanity check everything about this. So step 1 is to not involve absolute paths at all. I'd write and run this code as a console application:
    Code:
    System.IO.File.WriteAllText("test.txt", "This is some test text.")
    Dim textRead As String = System.IO.File.ReadAllText("test.txt")
    Console.WriteLine(textRead)
    That should run and print "This is some test text.". You should be able to find the file test.txt in your project's output folder. If this is not the case, there is something on that machine that's not allowing applications to create or read files. We won't make any progress until you figure out what that is. Check what antivirus it's running. If it's anything except "Microsoft Security Essentials", I don't trust it. Especially if it's McAffee, Symantec, or Trend Micro. Disable them and try again. If that's not it, that machine is borked. Reformat. Reinstall Windows.

    (If you deploy that and it ends up in Program Files, there's your answer. You haven't been allowed to write files there since Vista. So just move on to the next test.)

    Now, if that does work, let's get a little bit more advanced. Maybe it's just specific folders. A user ought to be able to write to My Documents. So let's modify the test code to do that.
    Code:
    Dim directoryPath As String = System.Environment.GetFolderPath(System.Environment.SpecialFolder.MyDocuments)
    Dim filePath As String = System.IO.Path.Combine(directoryPath, "test.txt")
    System.IO.File.WriteAllText(filePath, "This is some test text.")
    Dim textRead As String = System.IO.File.ReadAllText(filePath)
    Console.WriteLine(textRead)
    That should print the same thing, only this time the file should end up in the user's My Documents folder. If it doesn't, there's something preventing the application from working with files in My Documents, and you need to figure out what that is.

    If it works, now comes the bigger test. Create the folder "C:\abc". Now let's try this:
    Code:
    Dim filePath As String = "C:\abc\test.txt"
    System.IO.File.WriteAllText(filePath, "This is some test text.")
    Dim textRead As String = System.IO.File.ReadAllText(filePath)
    Console.WriteLine(textRead)
    If that doesn't work, there might be something special about folders in the root of the C: drive, I vaguely remember that. We do know, if we got here, that we can write and read files elsewhere. So consider putting your files somewhere else if this doesn't work.

    If it does work, I can't solve this problem remotely. I suspect there's a misspelling somewhere, or that the appropriate slashes aren't being used. But I can't check that for you without being at the machine.
    This answer is wrong. You should be using TableAdapter and Dictionaries instead.

  14. #14

    Thread Starter
    Lively Member
    Join Date
    Jan 2016
    Location
    Anderson, SC
    Posts
    70

    Re: Using Resources

    Here, perhaps in clearer form, is my problem. I have two computer, A and B. On A I set a simple form with nothing on it. The entire code consists of:


    Directory = "c:/Boscobel Fly Over Video Data/"

    Dim fileReader As System.IO.StreamReader
    Dim stringReader As String
    Dim n As Integer
    '*** THIS CODE READS IN HOLE TIPS FOR EACH HOLE, 5 LINES EACH 0-19 HOLES ***

    fileReader = My.Computer.FileSystem.OpenTextFileReader(Directory & "hole tips.txt")

    I put the same identical code on a simple form on computer B.

    Computer A Debugs fine but Computer B say the "path is not found", i.e. the file, Directory & "hole tips.txt" doesn't exist.

    Why can this happen? Both are running VB 2013 with the same FrameWork.

  15. #15
    Karen Payne MVP kareninstructor's Avatar
    Join Date
    Jun 2008
    Location
    Oregon
    Posts
    6,684

    Re: Using Resources

    Never assume a folder exists, always check first.

    Code:
    Dim Directory As String = "c:/Boscobel Fly Over Video Data/"
    If IO.Directory.Exists(Directory) Then
        ' do work
    End If

  16. #16
    You don't want to know.
    Join Date
    Aug 2010
    Posts
    4,578

    Re: Using Resources

    I'm not an idiot, I know the problem is it can't find the file and you feel like the file is there. But I also know the computer will only tell you the file isn't there if it truly believes it isn't. Computers don't lie. They just don't try to make up for our mistakes. The reason I didn't post code specifically for your problem is I was trying to find out if a series of successively more complicated file accesses worked at all on your system: if they worked, the blame falls on your code. If they didn't, then we learn that there's something special about this one computer and we need to do more experiments. But fine. You don't want to write ANY code unless it looks EXACTLY like yours. Let's do it that way, and review what we know.

    • You have code, that IF the file is at the location should open the file. You claim it works in one environment, and my experience tells me this is probably true because it's very standard file I/O code that will work if its conditions are met.
    • You have a file that you claim is at a particular path. I can't prove this one on my end. But it's an important precondition for the code, and you are getting an error that indicates it is not at the path.
    • The most common reason a file isn't at a path is a misspelling, or a mistake formatting the path string. One error in your formatting has been pointed out, but you haven't indicated you even tried to change it. I can't prove anything about the correctness of your path from over here.


    kevininstructor also reminds me:

    If you're going to post an error you get, drown me in too much information. All you are giving us is a paraphrase of the message. But here's the important parts of the Exception class, and an explanation of how if you would post each bit this question might have been answered days ago:

    • Exception Name: OpenTextFileReader() can only throw three different exceptions. From that name alone, we can tell if it's a problem with the path formatting, a problem finding the file, or a security issue. That's a single word that confirms the nature of the problem.

      In lower-level APIs, there's a distinction between FileNotFoundException and DirectoryNotFoundException. That can be enlightening. But it's not present here, unfortunately.
    • Message: When the name isn't enough, the Message often is. This is a string that MS believes describes the error you are having. For most exceptions, this is detailed like: "Could not find file or a portion of the path: 'C:/Boscobel Fly Over Video Data/ test.txt'." This is helpful because it provides detailed information, like the path it tried to find, that you can compare to what you think the path should be. I put an error in the path above, can you tell what it is?
    • InnerException: When this is not Nothing, it's very useful. Some exceptions are caused by other exceptions happening, and they put those exceptions inside the InnerException property. When you get a TargetInvocationException or a handful of other types, the outer exception is always useless compared to this InnerException.
    • Stack Trace: This tells you the line that threw the exception, and how the program thinks it got there. That's helpful for figuring out how variables might get weird values, or which of several situations the code got into.


    We need to see the exact message, not a paraphrase, especially if it has the path it was looking for. In fact, this is what I would do. Credit to kevininstructor for the idea:

    In your code, before the line that opens the file, add this:
    Code:
    Dim filePath = Directory & "hole tips.txt"
    MessageBox.Show(String.Format("I think the file path is '{0}'.", filePath)
    Clipboard.SetText(filePath)
    
    If Not System.IO.Directory.Exists(filePath) Then
        MessageBox.Show("I do not think it exists. Check the spelling until you find the error.")
    Else
        MessageBox.Show("I believe the directory exists.")
    End If
    
    If Not System.IO.File.Exists(filePath)
        MessageBox.Show("I do not think the file path exists. Check the spelling until you find the error.")
    Else
        MessageBox.Show("I think the file exists. There's no good reason the code should fail unless something else is breaking file I/O.")
    End If
    That will test both the directory and the file separately, and tell you if one or the other is busted. If it says the directory is stop there, do not shriek and wail that CLEARLY the file is there. VB .NET is much like a child with a mental quirk that can only do EXACTLY what they are told. Sort of like a genie, with equal disdain for hubris.

    Copy the path from the first message box. In fact, that code puts it on the Clipboard for you. Open the Run dialog, usually Windows Key + R but sometimes in the Start Menu as well. Paste the path and press Enter. Either:
    • The .txt file will open in Notepad, and the path is correct, so if the program is not finding the file something's wrong with your computer.
    • You will get an error because the file is not found. Something is spelled wrong either in that path or on disk. Figure out what doesn't match and fix it.

    Those are the only two options it could possibly be, and I'm not contributing anything more until I see the things I've asked for.
    This answer is wrong. You should be using TableAdapter and Dictionaries instead.

  17. #17

    Thread Starter
    Lively Member
    Join Date
    Jan 2016
    Location
    Anderson, SC
    Posts
    70

    Re: Using Resources

    Copied your code into my file (graphic below). Note that I had to put another ")" at the end of your first IF.

    Name:  copied code.jpg
Views: 1278
Size:  32.1 KB

    I "debug" and got these msgboxs:

    Name:  msgbox 1.jpg
Views: 1129
Size:  15.3 KB Name:  msgbox 2.jpg
Views: 1121
Size:  13.4 KB Name:  msgbox 3.jpg
Views: 1156
Size:  20.4 KB

    NOTE: the program is running on My Computer, not the "other" computer that is having a problem using the code. And my program executes correctly, i.e. the video is running and I can use the various buttons and listbox.

    Do you recommend testing this on the "other" computer? Not a big deal as I have VB 2013 installed on along with the folder that contain the project. Just a matter of going to the "other" computer and bring it home to use my monitor there.
    Last edited by movingonto2013; Jan 24th, 2016 at 01:19 PM.

  18. #18
    Super Moderator dday9's Avatar
    Join Date
    Mar 2011
    Location
    South Louisiana
    Posts
    11,715

    Re: Using Resources

    Let's assume that you've stored your text file in My.Resources and named it hole_tips.txt. If so then attempt this code:
    Code:
    Public Class Form1
    
        Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs) Handles MyBase.Load
            Dim directory As String = IO.Path.Combine("C", "Boscobel Fly Over Video Data")
            Dim path As String = IO.Path.Combine(directory, "hole tips.txt")
    
            If IO.Directory.Exists(directory) AndAlso Not IO.File.Exists(path) Then
                IO.File.WriteAllText(path, My.Resources.hole_tips.txt)
            ElseIf Not IO.Directory.Exists(directory) Then
                IO.Directory.CreateDirectory(directory)
                IO.File.WriteAllText(path, My.Resources.hole_tips.txt)
            End If
    
            Dim contents() As String = IO.File.ReadAllLines(path)
            'Do the rest of your code
    
        End Sub
    End Class
    What this code will do is first check if the file doesn't exist and if not then it will create it with the contents in your resource file. If the first condition fails(ie - the directory doesn't exist) then it will check if just the directory doesn't exist and if not then it will first create the directory and then the file. Finally it gets all the lines from your text file and places it into an array.
    "Code is like humor. When you have to explain it, it is bad." - Cory House
    VbLessons | Code Tags | Sword of Fury - Jameram

  19. #19

    Thread Starter
    Lively Member
    Join Date
    Jan 2016
    Location
    Anderson, SC
    Posts
    70

    Re: Using Resources

    I will pick up the "other" computer tomorrow AM, bring it home and try what you suggested. Not sure if the .txt is in my Resources but, if not, I will try to get it there. Let you know tomorrow.

    Thanks for your help. I intend to figure this situation out sometime.

  20. #20

    Thread Starter
    Lively Member
    Join Date
    Jan 2016
    Location
    Anderson, SC
    Posts
    70

    Re: Using Resources

    I will be using this code to test reading a .txt file on a computer (both home and "other".

    Public Class Form1

    Private Sub cmdExit_Click(sender As Object, e As EventArgs) Handles cmdExit.Click
    End
    End Sub

    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load

    Dim Tips(19, 5) As String
    Dim Directory As String = "C:/"
    Dim fileReader As System.IO.StreamReader
    Dim stringReader As String
    Dim n As Integer
    '*** THIS CODE READS IN HOLE TIPS FOR EACH HOLE, 5 LINES EACH 0-19 HOLES ***

    fileReader = My.Computer.FileSystem.OpenTextFileReader(Directory & "hole tips.txt")
    ListBox1.Items.Add("Reading From " & Directory & "hole tips.txt")

    stringReader = ""
    While Not IsNothing(stringReader)
    stringReader = fileReader.ReadLine()
    If Not IsNothing(stringReader) Then
    n = Val(stringReader)
    ListBox1.Items.Add(n)

    For i = 1 To 5
    stringReader = fileReader.ReadLine()
    ListBox1.Items.Add(stringReader)
    Tips(n, i) = stringReader
    Next

    End If
    End While
    End Sub
    End Class

    This code should produce this result on any computer:

    Name:  Output from Test.jpg
Views: 1161
Size:  49.8 KB

    I will see how it works on my "other" (problem) computer shortly.

    Stay tuned for more bulletins.

  21. #21
    You don't want to know.
    Join Date
    Aug 2010
    Posts
    4,578

    Re: Using Resources

    I didn't ask you "insert this code with the file path that you're already having trouble with". I asked you to execute it with very specific other paths. I also asked you to please try using "\" instead of "/", because on Windows, "\" is the directory separator character and you might get odd results if you use "/".

    I spent a dang hour writing that post that I could've spent working on my iOS project. I asked you, multiple times, to try a very simple file that isn't misspelled to verify what's going on. For some reason, you refuse.

    I'm quite upset, and a lot of what I want to say about how you should continue is just an insult packaged as "advice" in that venomous way that polite Southern women speak daggers to each other. (Bless their hearts.) I think I'm done in this thread.
    This answer is wrong. You should be using TableAdapter and Dictionaries instead.

  22. #22
    Super Moderator dday9's Avatar
    Join Date
    Mar 2011
    Location
    South Louisiana
    Posts
    11,715

    Re: Using Resources

    I'm with Sitten on this one... I'm concerned because you continue to ignore the suggestions made by the various members.

    For example both Sitten Spynne and I suggested to use IO.Path.Combine but you continue to try and manually type out your path. Another example is that Karen, Sitten, and I all suggested checking if the directory or file exists prior to executing your code that uses the file but you continue to use your code assuming as if the file exist.

    I'm not quite to Sitten's point yet of backing out but if you continue to blatantly ignore our advise then... well.
    "Code is like humor. When you have to explain it, it is bad." - Cory House
    VbLessons | Code Tags | Sword of Fury - Jameram

  23. #23

    Thread Starter
    Lively Member
    Join Date
    Jan 2016
    Location
    Anderson, SC
    Posts
    70

    Re: Using Resources

    Finally got it working by 1st using the code in my post of 4:37 AM. Once I saw that would work on the "other" computer I then went back to my project and copied the code there. After fiddling with it for a bit I finally got it to Debug. Of course it helped that I set "line numbers" on and was able to track down one other error and fix it.

    As all of you have said, it probably is some sort of typo error and I am sure that was the case. Not quite sure exactly what I changed to get the darn thing working but it works.

    By the way, it works using my Directory ="C:/Boscobel Video Fly Over Video Data" file. It probably would be nice to use Resources but, hey, "If it ain't broken, don't fix it!" Just Frustrating to program and not be able to find errors. I have several other programs written in VB 6 that have over 10,000 lines of code with over 30 forms. They, too, took a long time to debug but, yes, I got them working.

    By the way, it takes from 65-120 seconds for Debug to run and produce the output. Is this normal or would it be due to processor speed or something else?

    Again, thanks for all your suggestion and comments. I tried to follow what everyone suggested but I had to keep things "simple" for me being new to using VB 2013. I was afraid that I had spent $500 for a program that I could not use. Seems like VB 2013 is a soaped up of all other versions using OOPS. Wonder why when the other versions, e.g. VB 6 worked. Microsoft is always updating their products with "bells & whistles" so people will think they are a better product and buy them. No wonder Bill has billions!

  24. #24
    You don't want to know.
    Join Date
    Aug 2010
    Posts
    4,578

    Re: [RESOLVED] Using Resources

    The longer you believe there is some problem with newer versions of Visual Basic that is why you keep having problems, the longer it will take you to be proficient. It means you aren't asking two important questions: "What did I do wrong?" and "How can I not do this again?" So long as you believe some arbitrary boogeyman such as OOP is the cause, you will find it easy and convenient to blame that when you make a mistake. That means you will keep making the same mistakes again.

    Thousands of people aren't experiencing the same problem as you. That means there's something unique about your experience. That almost always means it's a mess you made yourself. Learning how to prove to yourself that the mistake is yours is more important than any API you might study. And, in the 1/100 case where you have actually found a bug, it's exactly the process that proves the problem is not yours.

    On another note, VS has had free editions since 2010. VS 2013 and VS 2015 don't require any money for most development. The versions that cost money come with some additional tools that are useful if you use them. I'm not sure if I've used any of them in the last 10 years.
    This answer is wrong. You should be using TableAdapter and Dictionaries instead.

  25. #25

    Thread Starter
    Lively Member
    Join Date
    Jan 2016
    Location
    Anderson, SC
    Posts
    70

    Re: [RESOLVED] Using Resources

    The damn program is acting just like before but now it won't run on my computer but does on the "other" computer. Same good code that worked an hour or so ago now doesn't on my computer where it originally worked. I give up. At least I can make a workable project in VB 6. Have so idea how I could make coding mistake going from one computer to another. Same old thing: "Path is not found".

    I didn't know 2013 was available for free. Obviously, if I knew this I wouldn't have spent the money. Oh, well, live and learn.

  26. #26
    Super Moderator dday9's Avatar
    Join Date
    Mar 2011
    Location
    South Louisiana
    Posts
    11,715

    Re: [RESOLVED] Using Resources

    Quote Originally Posted by movingonto2013 View Post
    The damn program is acting just like before but now it won't run on my computer but does on the "other" computer. Same good code that worked an hour or so ago now doesn't on my computer where it originally worked. I give up. At least I can make a workable project in VB 6. Have so idea how I could make coding mistake going from one computer to another. Same old thing: "Path is not found".

    I didn't know 2013 was available for free. Obviously, if I knew this I wouldn't have spent the money. Oh, well, live and learn.
    Before going back to VB6 have you at least tried my suggestion in post #18?
    "Code is like humor. When you have to explain it, it is bad." - Cory House
    VbLessons | Code Tags | Sword of Fury - Jameram

  27. #27

    Thread Starter
    Lively Member
    Join Date
    Jan 2016
    Location
    Anderson, SC
    Posts
    70

    Re: [RESOLVED] Using Resources

    Actually, I got the project working on both computers by using the code in post #20. But, ran into another problem just now. A deployment made on one computer didn't work on the other. All it did was put the icon on the desktop but clicking it did nothing. I am quite confused as to what is going on between the computers. I very carefully copy the folder to a flash drive. Go to the other computer and run the "setup" on the flash drive. Done this many times back and forth. Sometime "setup" works, other times it doesn't. When it doesn't work I simply use VB 2013 on that computer to make a new deploy folder and then run "setup" which, generally, always work.

    Another thing - I haven't been able to figure out how to save the project to another folder. Set up new folder, used the "Save As ..." but could not then find the project in the new folder. I'll tell you, VB 2013 can surely drive you to the "nut house".

  28. #28
    You don't want to know.
    Join Date
    Aug 2010
    Posts
    4,578

    Re: [RESOLVED] Using Resources

    This isn't really breaking my resolution to leave the thread, I just wanted to point something out.

    Post #20 has only one difference from any other file access code you've written: it doesn't use the folder "Boscobel Fly Over Video Data". Don't you find it interesting that, when you remove that folder from the path, everything works? Now, what could that mean about the folder? Wouldn't it be neat if, all along, that folder either wasn't there or misspelled? Or, better, what if the folder was there, but the file was in the wrong place all along?

    In terms of the deployment project, I don't muck about with ClickOnce much. There's probably a process you have to follow. Forgetting a step probably leads to things going wrong. Adopting a philosophy of randomly mashing buttons and hoping it works is sort of like forgetting a step. You should probably make a different thread for that problem, and let someone who routinely wrestles with ClickOnce give you advice.
    This answer is wrong. You should be using TableAdapter and Dictionaries instead.

  29. #29
    Super Moderator dday9's Avatar
    Join Date
    Mar 2011
    Location
    South Louisiana
    Posts
    11,715

    Re: [RESOLVED] Using Resources

    I think that I am at Sitten's point now. I'm unsubscribing from this thread, best of luck to you.
    "Code is like humor. When you have to explain it, it is bad." - Cory House
    VbLessons | Code Tags | Sword of Fury - Jameram

  30. #30

    Thread Starter
    Lively Member
    Join Date
    Jan 2016
    Location
    Anderson, SC
    Posts
    70

    Re: [RESOLVED] Using Resources

    I was under the impression that there is only one place in VB 2013 that you Publish. There are no steps other than clicking "Publish" which I assume you mean by "ClickOnce". Thanks for helping. Good Luck to you and the other in the future.

    Over the past several years (probably at least 6 by now) using VB 6 I have made installation programs using Inno-Script and InnoSetUp. They both work great and it is easy to make an installation program, e.g. declare the installation folder, add files that are needed. I will (tomorrow) go through this process and try to create an installation program for my VB 2013 project. Let you know how it works rather than use VB 2013 Publish.
    Last edited by movingonto2013; Jan 25th, 2016 at 09:33 PM.

  31. #31
    You don't want to know.
    Join Date
    Aug 2010
    Posts
    4,578

    Re: [RESOLVED] Using Resources

    There is an entire section of documentation devoted to ClickOnce deployment. A lot of people think documentation is for idiots, and anyone who spends time reading it instead of diving in head-first is a fool. Those people flail their way through projects, and sometimes dig a hole so deep they can't get out. Then they come to forums and ask people what they need to do, and ignore any advice that isn't a pat on the back and a puff of faerie dust that magically fixes the problem. They can't figure out why the world's so stupid and why everyone's asking them to think instead of program, this book said it was easy! Other people spend hours poring over documentation and learn the way their tools work before they get too deep. Sometimes they might spend a whole week on side projects before trying something for reals. For some reason those people don't spend a lot of time asking questions, they're too busy having stable careers and making lots of money that can't even buy a reasonable property in their inflated housing market, such is the life of an idiot.

    That said, I've used Inno Setup and I like it a heck of a lot better than I do ClickOnce. I don't trust Microsoft's tools, especially when they declare them idiot-proof. That just means that I'm going to end up in some scenario that's "an edge case" and I won't have a way to get out of it. Inno Setup has its own community of people that waste time reading documentation, so if you have problems with those scripts I'm sure some of them will be glad to try and help you.
    This answer is wrong. You should be using TableAdapter and Dictionaries instead.

  32. #32

    Thread Starter
    Lively Member
    Join Date
    Jan 2016
    Location
    Anderson, SC
    Posts
    70

    Re: [RESOLVED] Using Resources

    So, how does one not use Publish, develop a .exe that can be installed anywhere on a computer AND attach the required files? How to you create the .exe (which appears in the .obj file) that can be installed anywhere?

    Using VB 6, Inno-Script (Why does this forum replace the word without the hyphen with "*********"?), and InnoSetUp I found it very easy ... once I had a few things explained to me. One advantage of VB 6 is that I could "make an .exe" without going through the process of "Debug". So, in my VB 6 program I could test it by setting my Directory to my project file location (with all necessary files there) but then reset Directory = "" to make the .exe so that the user could install it anywhere on their computer. Haven't found any way to do this with VB 2013, in fact, if I use Directory = "" (or any other location than where I put my necessary files (.jpg, .mp4, .txt) I get "Path Not Found". Inno-Script requires a .pjt file to run which is set up when you start IS. IS expects your .exe in a certain place, i.e. in your project folder. I can, using VB 6, create the .iss file and run InnoSet up to produce an installation .exe which can be installed any place on a computer, including any files that I want use. In my Fly Over project I have two .txt, 20 .jpg and 20 .mp4 file. Using IS I just Add them to the project. Other of my VB 6 projects require over 50 files that will be placed in the Default folder specified in IS.

    I know that I don't fully explain my problems but does any novice do so? Communicating via forums is difficult, at least for a VB 2013 novice like me. I guess I better start a Post asking for help in NOT using Publish and, 2nd, creating an .exe (that can be installed anywhere) without using Debug.

    I appreciate your thoughts and help. Just wish I could figure these things out as very frustrating. The only reason I am trying to use VB 2013 is I stupidly purchased it and don't want to waste money. I probably, even if I figure out how to finally use it, would NOT use it to create programs. Why should I? I can easily create them in VB 6 and deploy them using IS and InnoSetUp.

    Thanks again for sticking with me on this. At least this forum has one person who is trying to help.

  33. #33
    PowerPoster SJWhiteley's Avatar
    Join Date
    Feb 2009
    Location
    South of the Mason-Dixon Line
    Posts
    2,256

    Re: [RESOLVED] Using Resources

    For simple applications, such as yours, there is no difference between VB6 and the .NET incarnation of VB as far as deployment is concerned - they are pretty much exactly the same as long as the 'runtime' is installed (VB6Runtime and the .NET framework, respectively). Indeed, the .NET deployment can be a lot simpler (XCopy deployment is possible). There's no reason you can't use a third party installer the same way that it has always been used.

    There's no difference between 'making' a VB6 executable and 'building' a VB assembly/executable. they are put in different locations, but so what? You can define the location as you see fit, but the default makes a lot of sense (bin/debug and bin/release). Personally, I 'distribute' the debug version and never build a release version. VB gives you a lot more options when building, that's all, bringing it inline with the more 'grown up' (sic) languages. The IDE isn't just used for VB projects, but C#, Java, ASP, JavaScript, and so on.

    There's a lot of additional tools; it takes time to use them: don't try to make it like VB6, as you will be sorely disappointed. Learn to use the tools provided. It seems like you have bought-and-paid-for Geo Metro application, but purchased a brand new Expedition SUV, and are complaining about the space in the back (which you feel like you don't need) and the price you paid for it. Two different things, performing similar functions, but with more versatility with the latter.
    "Ok, my response to that is pending a Google search" - Bucky Katt.
    "There are two types of people in the world: Those who can extrapolate from incomplete data sets." - Unk.
    "Before you can 'think outside the box' you need to understand where the box is."

  34. #34

    Thread Starter
    Lively Member
    Join Date
    Jan 2016
    Location
    Anderson, SC
    Posts
    70

    Re: [RESOLVED] Using Resources

    Interesting. Thanks very much for replying. My problem is that I am not using resources, rather I read the files, .jpg, .txt, and .mp4, in from the computer. Normally, in VB 6, I would test the program by using my development folder with the files there. Then to use it on any computer, I first change the Directory my my folder to "" which allows the user to install the program in any folder they wish rarther than the default folder. I use Inno-Script and Innosetup to deploy and they work just fine.

    I have no idea how to do the same thing with VB 2013 as the only .exe for the program, Debug folder, using my testing folder and if I change it to "" then Debug catches this as "path not found".

    I hope that is enough information so you can understand my problem.

  35. #35
    PowerPoster SJWhiteley's Avatar
    Join Date
    Feb 2009
    Location
    South of the Mason-Dixon Line
    Posts
    2,256

    Re: [RESOLVED] Using Resources

    What do you mean 'the Directory'? It sounds like you are changing your application code before deployment; then you are just guessing that it'll work. Not surprisingly, it doesn't work. Don't change your application after you have debugged it.

    Just put all your files, along with the executable, in a single folder. Then you know exactly where to find your files. This may not be the 'best' way, but it'll work, and probably make distribution easier (you can just zip up the whole folder).

    Again, probably not the best way, but you could add all your media files as items in your root folder of your solution. Mark them as 'Build Action: None' and 'Copy to output directory: Always' or 'Copy if newer'.

    Your real problem is that you are hard coding folder paths in your code. As has been pointed out, above, you don't need to do that - use various special folders (and realistically, that's where your media files should be), but for the sake of argument, you put them in the same folder as the executable, then you would use the folder that the application exists in to access the media. As always, you will perform a check on that folder, and on each file, prior to using that folder or file, and report a message in a controlled manner. Never let a program crash on a 'file not found' error.
    "Ok, my response to that is pending a Google search" - Bucky Katt.
    "There are two types of people in the world: Those who can extrapolate from incomplete data sets." - Unk.
    "Before you can 'think outside the box' you need to understand where the box is."

  36. #36

    Thread Starter
    Lively Member
    Join Date
    Jan 2016
    Location
    Anderson, SC
    Posts
    70

    Re: [RESOLVED] Using Resources

    I don't understand how to deploy to a specific folder on the user's hard drive nor how to allow them to select the folder they wish to store the program in. In the past, using Inno-Script and InnoSetUp I could set the default installation folder but users could still install in a folder they want. Of course the installation .exe would put the files, .jpg, .mp4, and .txt, in the installation folder no matter where it is located. So, in my program I set of a string named Directory="C:/My project programs/". It is set to my development folder. But, naturally, I would not want the installation folder to be named, "My programs". When I made the .exe using VB 6 I would set Directory = "" which would then use my default directory as the installation folder. You can't do this in VB 2013. In fact, you can only make a .exe file using Debug which means if Directory="" the debug will stop.

    Oh, well, since I cannot do what I want and that VB 2013 always installs the program in "Programs Files (x86) then how or where do I put the .jpg, .mp4, and .txt files? And how do I get them there? How does VB 2013 install files along with the .exe?

    I don't yet understand exactly how VB 2013 functions but it sure if totally 180 degrees from VB 6.

  37. #37
    You don't want to know.
    Join Date
    Aug 2010
    Posts
    4,578

    Re: [RESOLVED] Using Resources

    You are using ClickOnce, the "easy mode" version of deployment. That means a lot of decisions about what you can and can't do with your deployment are made for you. This is a big part of why I don't like ClickOnce, if you get in a fight with ClickOnce then you have to change, rather than telling ClickOnce to bend to your will.

    I spent two minutes reading the ClickOnce documentation I linked, curious if it has a technique to deploy loose files. Two whole minutes. At three minutes and thirty seconds, I was halfway through an article explaining that it has a special way to tell it about those files, and it wants to put them in a special folder that it controls, and you have to access them using special code. By the time five minutes had passed, I was looking at example code and walkthroughs.

    At the end of that section, there was a brief mention of putting files on other parts of the hard drive. It was one paragraph long, and had no code or examples. That tends to indicate they don't want you to do it, and you're on your own for supporting it. It did indicate you had to request a particular permission in the deployment settings to do so. That'd be an interesting reason for it to fail on some machines.

    I've linked you to the ClickOnce documentation. You have to read it. Devote an hour to at least skimming it. Most of it is about features you'll quickly figure out you don't need, and you can skip those sections. But ClickOnce is made to deploy applications that are built a very specific way, and that means you have to make sure your application plays by its rules. I'm not going to spend a day learning those rules to regurgitate them at you: I don't and probably will never need to use ClickOnce. But you're not going to get very far flailing about and flipping all the switches you can while complaining that Inno Setup and VB6 were so much easier.

    Nothing's stopping you from using Inno Setup with your application. But if you want to do that, you're committing to potentially reading a different set of documentation. The part about that I like is Inno Setup has its own forums and its own community for you to inform that things were easier when you were a VB6 king of the hill. You'll get better answers out of them than you will get here.

    I see in you a burning desire to avoid anything that looks like reading documentation, or performing critical analysis. I see the belief that you can solve any problem with a simple snippet copy-pasted from some stranger on the internet. This is not true, this has never been true, and you're just as likely to get Code Herpes from those snippets if you never care to ask how they work.

    If you keep going down this road...
    You're gonna have a bad time.
    This answer is wrong. You should be using TableAdapter and Dictionaries instead.

  38. #38

    Thread Starter
    Lively Member
    Join Date
    Jan 2016
    Location
    Anderson, SC
    Posts
    70

    Re: [RESOLVED] Using Resources

    Good Advise! But no solution. How does one avoid using ClickOnce? How does one use Inno Script plus Inno SetUp? To use Inno Script you must have the location of the project .vb. Where is this stored using VB 2013. You also need the .exe created? Where is this stored? With these two things you should be able to use the tool and, if necessary, attach folders/files to the compiled code.

    Whoa! Guess I shouldn't be asking for advice which probably include code as you never know who is posting the code and does that person really know what they are doing?

    Anyway, thanks for sticking around. Going off in a different direction.

    "If it ain't broken, then don't fix it ... or use something newer just because it is newer."

  39. #39
    PowerPoster SJWhiteley's Avatar
    Join Date
    Feb 2009
    Location
    South of the Mason-Dixon Line
    Posts
    2,256

    Re: [RESOLVED] Using Resources

    Quote Originally Posted by movingonto2013 View Post
    ... So, in my program I set of a string named Directory="C:/My project programs/". ...
    Again, don't do this. Do not hard code any strings for folders in your application.

    If you have uses Inno, then you know how to allow the user to supply any install folder they like. Don't you?
    "Ok, my response to that is pending a Google search" - Bucky Katt.
    "There are two types of people in the world: Those who can extrapolate from incomplete data sets." - Unk.
    "Before you can 'think outside the box' you need to understand where the box is."

  40. #40
    You don't want to know.
    Join Date
    Aug 2010
    Posts
    4,578

    Re: [RESOLVED] Using Resources

    Quote Originally Posted by movingonto2013 View Post
    Good Advise! But no solution. How does one avoid using ClickOnce? How does one use Inno Script plus Inno SetUp? To use Inno Script you must have the location of the project .vb. Where is this stored using VB 2013. You also need the .exe created? Where is this stored? With these two things you should be able to use the tool and, if necessary, attach folders/files to the compiled code.

    Whoa! Guess I shouldn't be asking for advice which probably include code as you never know who is posting the code and does that person really know what they are doing?

    Anyway, thanks for sticking around. Going off in a different direction.

    "If it ain't broken, then don't fix it ... or use something newer just because it is newer."
    It's amazing what you can find out if you listen to the people who want to help you. Some of these questions have already been answered. I guess I don't blame you if you can't find that in this clusterflop of a thread.

    First, Inno Setup probably has its own forums. You can go talk to them about Inno Setup issues. That'd be a lot faster than asking me, I got quite enough of installers at my last job.

    In terms of "Where is the location of the project .vb?" First, I want you to explain to me why you think you need to deploy a .vb file. Or, alternately, if what you mean is, "I don't know where I saved my project on my computer", then you should rectify that. If you right-click a file in Solution Explorer, you should see "View in Explorer". Sometimes. It seems it only appeared in recent versions of VS. If you don't see that, you can push Alt-Enter or right-click the file and choose "Properties" and, in those properties, there is a path. Now you know where your file is. Hurry up and write it down on a post-it note and stick it to your monitor so you don't forget.

    You've been told the location of the .exe several times, but here it is again for reference. When you found your "project .vb" in the last paragraph, did you write down where the file was? Of course you didn't. Here's why I asked you to remember it: your .exe file will be very close to it in the file system! It will have a path that looks something like "C:\Users\YourName\Documents\Visual Studio Something\Projects\YourProgram\YourProgram\Form375.vb". If that's the case, I'd expect to find the executable somewhere around "C:\Users\YourName\Documents\Visual Studio Something\Projects\YourProgram\YourProgram\Bin\Debug\YourProgram.exe". That might not be exactly it. If it's not exactly there, look nearby in the file structure.

    Now, if we were on better terms, I'd talk about making a Release build, but right now I think it would confuse you. If you're serious, and you're going try the project in VB6, then happy trails. But I don't think they're going to be able to help you, and it has nothing to do with VB6.

    In terms of this:
    Whoa! Guess I shouldn't be asking for advice which probably include code as you never know who is posting the code and does that person really know what they are doing?
    This is actually true, and a fundamental truth. I don't even trust the code I wrote yesterday.

    When you get an example from the internet, you don't even know if it works. You don't even know if it's doing something stupid, or dangerous. But you know that you don't know. It's important to act on it.

    That means picking apart the example line-by-line and telling yourself what it does, before you try it. That means looking in the documentation to see what bits you don't understand do, before you try it. 9 times out of 10, you'll figure out the example has half a snowball's chance of working before you've even run the code. But even then, there's further considerations. Does it call Dispose() on everything it should? What exceptions could be thrown, and which can be safely handled? Does it require Imports statements or DLL references? Is it using API specific to certain versions of .NET? Do those APIs require specific versions of Windows? Examples are meant to be simple demonstrations, and don't answer all of those questions. Which is why they shouldn't be copy/pasted into anything but a throwaway test harness so after verification they can be tweaked and modified to meet the standards of your project.

    But if you aren't in the mood to think when you're programming, you're going to be assembling little nuggets of code you don't understand with bits of glue you don't understand, and it's no surprise when the rat's nest that results is incomprehensible to the person that wrote it. You have to know what you don't know, and proceed carefully. The worst programmer in a room is the one who declares he knows what he's doing.
    This answer is wrong. You should be using TableAdapter and Dictionaries instead.

Page 1 of 2 12 LastLast

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