Results 1 to 16 of 16

Thread: [RESOLVED] Need Help With Some Code

  1. #1

    Thread Starter
    Lively Member yomamathecableguy's Avatar
    Join Date
    Jun 2008
    Posts
    67

    Resolved [RESOLVED] Need Help With Some Code

    I'm using this program to log in to a site, and then send a message. What am I doing wrong? Any help is appreciated.

    Form1:
    Private Sub Command1_Click()
    newurl = "http://goallineblitz.com/game/new_message.pl?to=" & Text1.Text
    WebBrowser1.Navigate (newurl)
    End Sub

    Private Sub Command2_Click()
    Load Form2
    Form2.Show
    End Sub

    Private Sub WebBrowser1_DocumentComplete(ByVal pDisp As Object, URL As Variant)
    If (pDisp Is WebBrowser1.Application) Then
    If (InStr(URL, "http://goallineblitz.com/game/new_message.pl?to=") <> 0) Then
    Dim HTML As HTMLDocument
    Set HTML = WebBrowser1.Document
    HTML.All.Item("subject").Value = Text2.Text
    HTML.All.Item("message").Value = Text3.Text
    HTML.All.Item("action").Click
    ElseIf URL = "http://goallineblitz.com/game/login.pl" Then
    HTML.All.Item("user_name").Value = Label4.Caption
    HTML.All.Item("password").Value = Label5.Caption
    HTML.All.Item("action").Click
    End If
    End If
    End Sub

    Form2:
    Private Sub Command1_Click()
    Load Form1
    Form1.Label4.Caption = Text1.Text
    Form1.Label5.Caption = Text2.Text
    Form1.WebBrowser1.Navigate ("http://goallineblitz.com/game/login.pl")
    Unload Me
    End Sub

  2. #2
    PowerPoster
    Join Date
    Jan 2008
    Posts
    11,074

    Re: Need Help With Some Code

    Maybe you should tell us what it is not doing that you believe it should be doing and state any and all errors that you may be getting.

  3. #3

    Thread Starter
    Lively Member yomamathecableguy's Avatar
    Join Date
    Jun 2008
    Posts
    67

    Re: Need Help With Some Code

    Well the webbrowser is hidden, so that the user doesn't see all the stuff going on (as to not clutter the screen), and I think that for some reason it isn't carrying out any of the actions.

  4. #4
    PowerPoster
    Join Date
    Jan 2008
    Posts
    11,074

    Re: Need Help With Some Code

    You still need to be more explicit. I don't even know what the contents of your textboxes and labels are and that could make a difference. I can't test it if I dont have all the necessary info. If you don't want to expose this info (maybe it's your userid and password and I understand that) but then is there some way to give me enough info to at least get it going after I make a connection.

  5. #5
    PowerPoster
    Join Date
    Jan 2008
    Posts
    11,074

    Re: Need Help With Some Code

    Well, you might try changing your _DocumentComplete event to the below code instead of what you have,
    Code:
    Private Sub WebBrowser1_DocumentComplete(ByVal pDisp As Object, URL As Variant)
     If (pDisp Is WebBrowser1.Application) Then
       Dim HTML As HTMLDocument
       Dim HTMLI As HTMLInputElement
         
       Set HTML = WebBrowser1.Document
      
       If (InStr(URL, "http://goallineblitz.com/game/new_message.pl?to=") <> 0) Then
         For Each HTMLI In HTML.getElementsByTagName("input")
           If HTMLI.Name = "subject" Then
             HTMLI.Value = Text2.Text
           ElseIf HTMLI.Name = "message" Then
             HTMLI.Value = Text3.Text
           ElseIf HTMLI.Name = "action" Then
             HTMLI.Click
           End If
         Next
       ElseIf URL = "http://goallineblitz.com/game/login.pl" Then
         For Each HTMLI In HTML.getElementsByTagName("input")
           If HTMLI.Name = "user_name" Then
             HTMLI.Value = Label4.Caption
           ElseIf HTMLI.Name = "password" Then
             HTMLI.Value = Label5.Caption
           ElseIf HTMLI.Name = "action" Then
             HTMLI.Click
           End If
         Next
       End If
     End If
    End Sub

  6. #6

    Thread Starter
    Lively Member yomamathecableguy's Avatar
    Join Date
    Jun 2008
    Posts
    67

    Re: Need Help With Some Code

    Sorry for not elaborating very much. XD Here are the controls in my forms:

    Form1
    Recipient ID (textbox - text1)
    Subject (textbox - text2)
    Message (textbox - text3)
    Login First! (commandbutton - Command2)
    Send! (commandbutton - Command1)
    Web Browser (webbrowser - webbrowser1)

    Form2
    Username (textbox - text1)
    Password (textbox - text2)
    Login (commandbutton - Command1)

    Form2 stores the username and password in hidden labels and uses those to fill in the web page.

    I've provided my 2 forms as attachments.
    Attached Files Attached Files

  7. #7

    Thread Starter
    Lively Member yomamathecableguy's Avatar
    Join Date
    Jun 2008
    Posts
    67

    Re: Need Help With Some Code

    can anyone help with this?

  8. #8
    PowerPoster
    Join Date
    Jan 2008
    Posts
    11,074

    Re: Need Help With Some Code

    Are you saying that my post didn't help you with your problem?

  9. #9

    Thread Starter
    Lively Member yomamathecableguy's Avatar
    Join Date
    Jun 2008
    Posts
    67

    Re: Need Help With Some Code

    I tried your code, and it did not solve the problem. Both of our codes looked to be good. I'm not sure why they aren't working.

  10. #10
    PowerPoster
    Join Date
    Jan 2008
    Posts
    11,074

    Re: Need Help With Some Code

    Maybe it didn't solve your entire problem but it was necessary to solve that part of it because I know the code you had was incorrect and the code I posted corrected it.

  11. #11
    PowerPoster
    Join Date
    Jan 2008
    Posts
    11,074

    Re: Need Help With Some Code

    I looked at your two Forms and you didn't change it to what I posted and that is one reason why it doesn't work and it never will the way you have it. What I posted is the correct way to do it. You have to add a reference to Microsoft HTML Object Library to you project

  12. #12
    PowerPoster
    Join Date
    Jan 2008
    Posts
    11,074

    Re: Need Help With Some Code

    BTW: Make your WebBrowser control Visible = True and hide it underneath the textbox. Invisible WebBrowser control does not fire your DocumentComplete event. Put the code I gave you back in your project and add the reference like I said and it should work.

  13. #13

    Thread Starter
    Lively Member yomamathecableguy's Avatar
    Join Date
    Jun 2008
    Posts
    67

    Re: Need Help With Some Code

    The attachments I provided were with my original code. I tried your code also.. I'll try making the webbrowser visible with your code ^_^

  14. #14

    Thread Starter
    Lively Member yomamathecableguy's Avatar
    Join Date
    Jun 2008
    Posts
    67

    Re: Need Help With Some Code

    After a little tweaking I finally got it working. I think the invisible webbrowser was the main thing screwing me up. Thanks jmstrickland! btw, I can upload the working forms if you would like ^_^

  15. #15
    PowerPoster
    Join Date
    Jan 2008
    Posts
    11,074

    Re: [RESOLVED] Need Help With Some Code

    I think the invisible webbrowser was the main thing screwing me up.

    Not the main thing.

    Your DocumentComplete event was totally wrong because you were trying to work with all elements of the same name...

    HTML.All.Item("subject").Value = Text2.Text

    ...and some of them did not support your request.

  16. #16

    Thread Starter
    Lively Member yomamathecableguy's Avatar
    Join Date
    Jun 2008
    Posts
    67

    Re: [RESOLVED] Need Help With Some Code

    Ah I see. Well thanks so much man ^_^ Helped my project a lot

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