Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

Visual Studio 2005 help

Options
  • 30-04-2008 12:37pm
    #1
    Posts: 0


    We're using Visual Studio 2005 in college at the moment. Visual Basic, to be precise. Only problem is that our lecturer isn't the most .. competent .. person. So now I'm having extreme problem with this. I've only started using VB so have no idea what to do really and google searches have become useless.

    Basically I'm trying to embed a website on my project. I've gotten the MDI parent form done and a child form created. On this child form I've done the WebBrowser tool. Only thing is that from here I get stuck. I don't know what the code should look like to do this.

    Also having the same problem with videos. I would like a clip from, say youtube, to play but since this lecturer isn't very competent (and actually gives out when we pose questions), I've no idea.

    The website I would like to embed is this(http://ironmanmovie.marvel.com/). Remember I'm only a beginner so go easy :)


Comments

  • Moderators, Society & Culture Moderators Posts: 9,689 Mod ✭✭✭✭stevenmu


    For better or worse, Visual Studio can do a lot for you without writing any code at all. The web browser control you use will have certain properties that can be set to define it's behaviour. You can set these by right-clicking on the control and choosing "properties", that should show you the properties pane. (you can also just select the control and go to the properties pane yourself, the pane will automatically show properties for the selected object).

    If you've done any object orientated programming, these properties are just the standard object properties you would define in your own classes.

    You should be aware either way that you can set them through the properties pane in the designer, or equally you can set them through lines of code.


  • Posts: 0 [Deleted User]


    Ok, I should probably go into better detail and this is what I'm having trouble with.

    I have a MenuStrip set up and one of these is for Iron Man -> Official Site. I want this to open my other form which contains the web browser. This is the code I have in
    Private Sub OfficialSiteToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OfficialSiteToolStripMenuItem.Click
            Dim IrnManWebsite As New IrnManWebsite()
            IrnManWebsite.MdiParent = Me
            IrnManWebsite.Show()
        End Sub
    

    And on the IrnManWebsite the WebBrowser is IrnManWeb and the code I found is
    Public Class IrnManWebsite
    
        Private Sub IrnManWebsite_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    
            IrnManWeb.Navigate("http://ironmanmovie.marvel.com/")
    
        End Sub
    End Class
    

    for some reason it is having trouble with the line
    Dim IrnManWebsite As New IrnManWebsite()
    and I'm not entirely sure why. It says that the request failed.


  • Registered Users Posts: 7,468 ✭✭✭Evil Phil


    What happens in the contructor for the IrnManWebSite class? Post the code for that.

    It may also be worth your while to step through the code as it executes. Place a breakpoint on the offending line and when it stops at it use the F11 key to step into the code.


  • Registered Users Posts: 6,190 ✭✭✭Talisman


    If the posted code is all that you have for the IrnManWebsite class, then that's where your problem lies.
    Public Class IrnManWebsite
    
        Private Sub IrnManWebsite_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    
            IrnManWeb.Navigate("http://ironmanmovie.marvel.com/")
    
        End Sub
    End Class
    

    For a start there is no constructor for the class that is why you are having an error here:
    Dim IrnManWebsite As New IrnManWebsite()
    

    Also IrnManWeb is not defined in the class.

    EDIT: Have a look at the code for this project:
    http://www.codeproject.com/KB/recipes/IE7_Clone_VS2005_Browser.aspx


  • Posts: 0 [Deleted User]


    Ok I've changed the code so that it reads
    Public Class IrnManWebsite
     Private Sub WebBrowser1_DocumentCompleted(ByVal sender As System.Object, ByVal e As System.Windows.Forms.WebBrowserDocumentCompletedEventArgs) Handles WebBrowser1.DocumentCompleted
            WebBrowser1.Navigate("http://ironmanmovie.marvel.com/")
        End Sub
    End Class
    

    But for some reason it's still giving me a problem with the same line

    this is really frustrating as I'm trying to teach myself from scratch but my lecturer is so incompetent (the head of department has recieved countless complaints)


  • Advertisement
  • Moderators, Society & Culture Moderators Posts: 9,689 Mod ✭✭✭✭stevenmu


    Can you give an instance the same name as it's class i.e. in
    Dim IrnManWebsite As New IrnManWebsite()
    your class is IrnManWebsite and you're trying to create an instance called IrnManWebsite, maybe give your instance a different name?


  • Posts: 0 [Deleted User]


    stevenmu wrote: »
    Can you give an instance the same name as it's class i.e. in
    Dim IrnManWebsite As New IrnManWebsite()
    your class is IrnManWebsite and you're trying to create an instance called IrnManWebsite, maybe give your instance a different name?

    What exactly do you mean by instance though?

    Sorry, I'm a complete newbie ha ha


  • Moderators, Society & Culture Moderators Posts: 9,689 Mod ✭✭✭✭stevenmu


    No problem, IrnManWebsite is a class, a class just defines an object, what properties it has and what actions/methods/functions it can do, but it's just a definition (in this case it's defining your child window). To do anything you create an "instance" of that class which is an object created from that definition.

    So in this case your creating an instance/object, which is the actual child window you are going to display, from your IrnManWebsite class/definition, which defines what that window is going to be/have/do.

    The way you are doing that is with the line
    "Dim IrnManWebsite As New IrnManWebsite() "
    which translates roughly to
    Create and object called IrnManWebsite from the class called IrnManWebsite.

    I can't remember if it will let you give an object the same name as it's class or not (I suspect not), but it's a bad practice either way you should really give the object a different name.


  • Posts: 0 [Deleted User]


    stevenmu wrote: »
    No problem, IrnManWebsite is a class, a class just defines an object, what properties it has and what actions/methods/functions it can do, but it's just a definition (in this case it's defining your child window). To do anything you create an "instance" of that class which is an object created from that definition.

    So in this case your creating an instance/object, which is the actual child window you are going to display, from your IrnManWebsite class/definition, which defines what that window is going to be/have/do.

    The way you are doing that is with the line
    "Dim IrnManWebsite As New IrnManWebsite() "
    which translates roughly to
    Create and object called IrnManWebsite from the class called IrnManWebsite.

    I can't remember if it will let you give an object the same name as it's class or not (I suspect not), but it's a bad practice either way you should really give the object a different name.

    Ok, that does make sense! I think you can't have them the same name as this is what was giving me the problem.

    So
    Private Sub OfficialSiteToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OfficialSiteToolStripMenuItem.Click
    
    would be the class and
    Dim IrnManWebsite As New [b]IrnManWebsite[/b]()
    
    would be setting up the instance, with the instance in bold? I think I'm just so used to using c++ as I had done this previously, and you had to declare everything - int blah, double blah etc etc

    So the problem lies within the bolded part and I should rename that?

    Once I get this working I could be cheeky and have another website as a yourtube video


  • Moderators, Science, Health & Environment Moderators Posts: 8,952 Mod ✭✭✭✭mewso


    So
    Private Sub OfficialSiteToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OfficialSiteToolStripMenuItem.Click
    
    would be the class and

    No thats just an event handler that runs when you click on the ToolStrip that you have called OfficialSiteToolStripMenuItem. The class involved here is called IrnManWebsite and is a windows form. When you created it you named the form IrnManWebsite but when you did VS create a .vb file called IrnManWebsite and in that file is public class IrnManWebSite and so on. A windows form is a class that inherits from a basic form.
    Dim IrnManWebsite As New [B]IrnManWebsite[/B]()
    

    So the problem lies within the bolded part and I should rename that?

    No what you should do is change the variable name:-
    Dim imwForm As New [B]IrnManWebsite[/B]()
    

    or some such. I'm not sure if this is necessarily the problem as your error said the request failed which suggests to me that the IrnManWebsite form was successfully created and initialised and the load event that you coded to navigate to that website attempted to run but failed. Also a few folks mentioned the lack of a constructor. I'm pretty sure that being a windows form it will implicitly have an empty constructor whether you create one or not. I'll have a look at this on my VS and see if I can replicate your problem.


  • Advertisement
  • Moderators, Science, Health & Environment Moderators Posts: 8,952 Mod ✭✭✭✭mewso


    Tested it and it worked fine for me.


  • Posts: 0 [Deleted User]


    Ok so now I'm officially confused. It still wont work! I've created a new form, and edited the code so that it says
    Private Sub OfficialSiteToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OfficialSiteToolStripMenuItem.Click
            Dim Iron As New IronMan()
            Iron.MdiParent = Me
            Iron.Show()
    
        End Sub
    

    on the other one I brought in the WebBroswer tool, added in http://www.google.com as the URL on the properties tab and double clicked on that. Only thing is that it's still having the same problem with the line

    Dim Iron as New IronMan()

    and the error its giving me is
    {"Request failed."}

    The thing is that I've used the code that a friend has done, did the exact same thing as him, only his works and mine doesn't. Could it be the computers I'm using as apparently there are problems with them. I'll try it in a different computer lab and see what happens


  • Registered Users Posts: 7,468 ✭✭✭Evil Phil


    Can you give us the entire error trace? "Request Failed" doesn't tell us a whole lot.


  • Posts: 0 [Deleted User]


    This is the error message I'm recieving and this is when I click on 'View Detail'

    So I tried creating a button with the code
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
            Dim ButtonResponse As New Testing()
            ButtonResponse.MdiParent = Me
            ButtonResponse.Show()
    
        End Sub
    

    Testing is another form I created with the WebBroswer, same idea, and put google.com as the URL in the properties and put the code in as :
    Public Class Testing
    
        Private Sub WebBrowser1_Navigating(ByVal sender As System.Object, ByVal e As System.Windows.Forms.WebBrowserNavigatingEventArgs) Handles WebBrowser1.Navigating
            WebBrowser1.Navigate("http://www.google.com")
        End Sub
    
    End Class
    

    And it gave me the exact same error, yet I have no idea where I'm going wrong


  • Moderators, Science, Health & Environment Moderators Posts: 8,952 Mod ✭✭✭✭mewso


    Are you running this locally or on a network? Is it blocked by your firewall?


  • Posts: 0 [Deleted User]


    It's running locally. Well, perhaps more of a network.

    Each student is given their own drive in which to store data on, and this can be accessed from any computer once you have logged on to the system. What I find peculiar is the fact that people who are in my class use the exact same code yet it works for them.


  • Moderators, Science, Health & Environment Moderators Posts: 8,952 Mod ✭✭✭✭mewso


    Well theres a good chance it's linked to security. The quick test would be to lower the security level in the internet settings of IE and see if it works. The specific error message suggests to me that the executing assembly (i.e. your application) can't get the required permission to access the web.


  • Posts: 0 [Deleted User]


    Oh, thats very interesting actually. Will certainly try that now. I'm working on it at home at the moment, so hopefully I wont encounter the same problems.

    I believe you are right and that is the problem I was having all along. I used to same coding on my home computer and it worked without a hitch.


  • Posts: 0 [Deleted User]


    Bumping this as have come up against another slight problem.

    I have my project finished. Only thing is that I have a windows media player component added, and the url is set to the file path of the video. However, I realise that I will need to change the file path if I transfer it to my hard-drive and then on to a cd rom (which is the eventual destination of this project)

    Faintly I can remember being told that if you put them in the bin directory of your project folder, you don't need to change the path, but I am unsure of what it would be then. Any help would be greatly appreciated.


  • Moderators, Science, Health & Environment Moderators Posts: 8,952 Mod ✭✭✭✭mewso


    Do a search for resource files. I don't know the ins and outs but you can add a file to a project and specify in it's properties that it should be an internal resource and then you will have access to it in my.resources. You should be able to find some articles on it.


  • Advertisement
  • Posts: 0 [Deleted User]


    musician wrote: »
    Do a search for resource files. I don't know the ins and outs but you can add a file to a project and specify in it's properties that it should be an internal resource and then you will have access to it in my.resources. You should be able to find some articles on it.

    Ok cool, thanks a million for your help.

    I'm quite pleased with how it turned out- its my first proper VB project and I have a lot in there


  • Moderators, Society & Culture Moderators Posts: 9,689 Mod ✭✭✭✭stevenmu


    The resources way is the right way to do it I think.

    But I think if you put it in your bin folder then you should be able to reference it with just the filename, not a full path. But I don't know if that will work for the media player component or not, it might need a fully formed uri, in which case you will ned to find your applications startup path, then the uri for your file just becomes startup path + filename.

    I think you can get the startup path with Application.Startuppath() or something like that.


  • Posts: 0 [Deleted User]


    stevenmu wrote: »
    The resources way is the right way to do it I think.

    But I think if you put it in your bin folder then you should be able to reference it with just the filename, not a full path. But I don't know if that will work for the media player component or not, it might need a fully formed uri, in which case you will ned to find your applications startup path, then the uri for your file just becomes startup path + filename.

    I think you can get the startup path with Application.Startuppath() or something like that.

    Thats what I was kinda thinking too. I'm going to edit the filepath now to see if it works

    I copied the movie into the bin directory. And changed the url to the file name, pressed play, but it doesn't show any indication of playing, but it sometimes does take its time- yet not this long

    What do you mean by the starup path, exactly?

    Actually in the bin folder theres 2 folders - debug and release. I wasn't sure if i should place the file in either of these so just left it outside


  • Posts: 0 [Deleted User]


    Ok so I dragged and dropped the movie file into my resource folder via the solution explorer. Only thing is I have no idea what to do here and not having much luck with google.


  • Moderators, Science, Health & Environment Moderators Posts: 8,952 Mod ✭✭✭✭mewso


    Once you have the file in your resources directory you should be able to access it in code using my.resources. For example if I drop an image called image1.jpg into the resources folder then I can get to it with my.resources.image1. If I wanted to set it as the background of the form then Me.BackgroundImage = My.Resources.image1. I'm not sure if all this works with video files but worth a try.


  • Posts: 0 [Deleted User]


    so with regards to the windows media player component, i would have the code in as
    Private Sub IrnTrailerPlay_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles IrnTrailerPlay.Click
    'a label that tells people to wait as the video loads        
    Me.IrnTrailerInfo.Visible = True
           
     AxWindowsMediaPlayer1.URL = "my.resources.[From www.metacafe.com] 903653.5280939.9.wmv"
    
        End Sub
    


  • Moderators, Science, Health & Environment Moderators Posts: 8,952 Mod ✭✭✭✭mewso


    Well I don't know much about the media player control. You might have to use a file property instead of a url property if such a property exists seeing as it's not really a url. I'm just guessing here.


Advertisement