Results 1 to 14 of 14

Thread: [RESOLVED] Error conversion from string name to type boolean is not valid

  1. #1

    Thread Starter
    Banned
    Join Date
    Oct 2009
    Posts
    315

    Resolved [RESOLVED] Error conversion from string name to type boolean is not valid

    Hi guys,

    I need your help. I want to connect to the proxy server using with the webbrowser while reads the strings of the proxy username, password, ip and the ports in each textbox.


    Here it is the code:

    Code:
    Imports System.Net
    Imports System.IO
    
    Public Class Form1
      Inherits System.Windows.Forms.Form
    
     Public Function GetHTMLPage(ByVal URL As String, Optional ByVal UseProxy As Boolean = False, Optional ByVal ProxyAddress As String = "", Optional ByVal ProxyPort As Integer = 0, Optional ByVal UserName As String = "", Optional ByVal PassWord As String = "", Optional ByVal Domain As String = "") As String
    
            Dim sResult As String = ""
            Try
                Dim objResponse As WebResponse
                Dim objRequest As WebRequest = System.Net.HttpWebRequest.Create(URL)
    
                If Not UseProxy Then
                    Dim oProxy As New WebProxy(ProxyAddress, ProxyPort)
                    If Domain <> "" Then
                        oProxy.Credentials = New NetworkCredential(UserName, PassWord, Domain)
                    Else
                        oProxy.Credentials = New NetworkCredential(UserName, PassWord)
                    End If
                    objRequest.Proxy = oProxy
                End If
    
    
                objRequest.Method = "GET"
                objRequest.Timeout = 120000 ' 20 sec.
                objResponse = objRequest.GetResponse
    
                Dim sr As System.IO.StreamReader = New System.IO.StreamReader(objResponse.GetResponseStream(), System.Text.Encoding.UTF7)
    
                sResult = sr.ReadToEnd()
                sr.Close()
                ' when code-execution has reached this point without
                ' throwing an error, the html page is loaded which
                ' means all is o.k.
                MessageBox.Show("You are connected Success")
            Catch ex As System.Exception
                MessageBox.Show("You have failed connected")
            End Try
            Return sResult
        End Function
    
        Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
            If GetHTMLPage("http://www.whatismyip.com" & ProxyAddress.Text & IIf(IsNumeric(ProxyPorts.Text), ProxyPorts.Text, 0), ProxyUsername.Text, ProxyPassword.Text) Is "" Then
                WebBrowser1.Url = New Uri("http://www.whatismyip.com")
            End If
        End Sub

    However, I have received the error that are jumping on If GetHTMLPage statement. The error is Conversion from string "name of string" to type 'Boolean' is not valid.


    I don't know what to do.


    Any idea?

  2. #2
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    Re: Error conversion from string name to type boolean is not valid

    in your If statement, change Is to =

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

    Re: Error conversion from string name to type boolean is not valid

    I'm not sure that kleinma's suggestion is correct; String Is String performs a reference comparison and returns Boolean, so that ought to not cause the error. It's worth a shot though; I typed up this guess before he posted so here's a second opinion:

    Even though your parameters are optional, they still have to be specified in a way the compiler can understand them. If you skip the second parameter, the compiler doesn't really have a way to know.

    So you probably think you are calling your function like this:
    Code:
    GetHTMLPage(URL, UserName, PassWord)
    But in reality the compiler is calling it as:
    Code:
    GetHTMLPage(URL, UseProxy, ProxyAddress)
    This is because without any other information, the compiler has to use the position of the parameter in order to figure out what to do.

    You could solve this by adding more parameters to put things in the right place:
    Code:
    If GetHTMLPage(http://www.whatismyip.com"..., True, "", 0, ProxyUsername.Text, ProxyPassword.Text)
    Or, you can play with named parameters to remove the ambiguity. You specify named parameters with the format name := value:
    Code:
    If GetHTMLPage("http://www."..., UserName := ProxyUsername.Text, PassWord := ProxyPassword.Text)

  4. #4
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    Re: Error conversion from string name to type boolean is not valid

    Sitten, I think you are right.. I just posted too quick

  5. #5

    Thread Starter
    Banned
    Join Date
    Oct 2009
    Posts
    315

    Re: Error conversion from string name to type boolean is not valid

    Thanks for your advice sitten.

    I have changed from this:
    Code:
    If GetHTMLPage("http://www.whatismyip.com" & ProxyAddress.Text & IIf(IsNumeric(ProxyPorts.Text), ProxyPorts.Text, 0), ProxyUsername.Text, ProxyPassword.Text) Is "" Then


    To this:
    Code:
    If GetHTMLPage("http://www.whatismyip.com" & ProxyAddress.Text, True, "", 0, ProxyUsername.Text, ProxyPassword.Text) Then

    So when I click on the button, it started to show the messagebox without connect to the proxy and it highlight the error on the same if statement.


    Any idea?

  6. #6
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    Re: Error conversion from string name to type boolean is not valid

    GetHTMLPage returns a string, so you do need some sort of boolean evaluation in your if statement.

    I don't really get the point of what your code does though. It looks like you try to connect to a URL using a proxy, and if you get data back, then you have a webbrowser navigate to the same URL without the proxy? What is the actual thing you are trying to do? Always use a proxy with the webbrowser control?

  7. #7

    Thread Starter
    Banned
    Join Date
    Oct 2009
    Posts
    315

    Re: Error conversion from string name to type boolean is not valid

    Quote Originally Posted by kleinma View Post
    GetHTMLPage returns a string, so you do need some sort of boolean evaluation in your if statement.

    I don't really get the point of what your code does though. It looks like you try to connect to a URL using a proxy, and if you get data back, then you have a webbrowser navigate to the same URL without the proxy? What is the actual thing you are trying to do? Always use a proxy with the webbrowser control?
    Yes, you are correct. I am trying to connect to a URL using with a proxy to get the data back. And I'd always wants to use proxy with the webbrowser control.


    As the code I have wrote with the webbrowser navigate, I am not sure how to use them with the proxy. Hope you can help.

    Thanks,
    Mark

  8. #8
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    Re: Error conversion from string name to type boolean is not valid

    The webbrowser control uses the global "internet settings" of Windows to determine a proxy. So if you were to go into internet options from the control panel or from internet explorer, and configured a proxy, the browser control would use this proxy as well. You need to remember that the browser control is nothing more than a managed IE window, so it takes all its settings from how IE is configured.

    So using a webrequest/webresponse with a proxy does not actually mean that the browser is using that proxy.

    The only thing you could do is modify the global settings of the proxy on the fly, which I would imagine requires admin rights. Then of course there is the problem if your app crashes for some reason before it closes, and does not change the proxy back, the user will be left with proxy settings for their entire computer when you only intended it to be for your app.

    Here is a C# example of changing the internet settings proxy on the fly in code.
    http://social.msdn.microsoft.com/for...d-95c917bed027

  9. #9

    Thread Starter
    Banned
    Join Date
    Oct 2009
    Posts
    315

    Re: Error conversion from string name to type boolean is not valid

    Thanks for this, so can I use more than one program to access to a each different proxy?



    Hopefully there is possible that if I can be able to do that.


    Thanks,
    Mark

  10. #10
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    Re: Error conversion from string name to type boolean is not valid

    I'm sorry but I don't think I understand what you are asking there.

  11. #11

    Thread Starter
    Banned
    Join Date
    Oct 2009
    Posts
    315

    Re: Error conversion from string name to type boolean is not valid

    Well, I mean that is it open to access to more than one proxy when I run more than one program?


    Hope there is possible to do that.


    Thanks,
    Mark

  12. #12
    Hyperactive Member
    Join Date
    Nov 2004
    Posts
    362

    Re: Error conversion from string name to type boolean is not valid

    you can use different proxy with raw http request, but if you use IE, one proxy at one time.

    in your code, "http://www.whatismyip.com" & ProxyAddress.Text & IIf(IsNumeric(ProxyPorts.Text), is it the correct URL? it looks like
    http://www.whatismyip.com123.123.123.1238080,

    something is missing. that's why the function always return "", the convert "" to boolean failed.

  13. #13

    Thread Starter
    Banned
    Join Date
    Oct 2009
    Posts
    315

    Re: Error conversion from string name to type boolean is not valid

    Thanks for the advice FlyingBear, so do you have the source for raw http request?

    On my code, no the url should be like this: http://www.whatismyip.com.

    All I am trying to connect to the proxy for the webbrowser control

    Do you think if I should remove the function of return or use the raw http request instead?



    Thanks,
    Mark
    Last edited by mark108; Sep 8th, 2010 at 06:23 PM.

  14. #14
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    Re: Error conversion from string name to type boolean is not valid

    The bottom line is if you want to make a webbrowser application, and you want to use the webbrowser control for this, and you want to use a proxy, you MUST change the system proxy settings on a global level, at least for the duration of the time your app is running.

    Using raw http requests are not going to help you, because you can not use them in conjunction with a webbrowser control to implement a proxy with that control.

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