[RESOLVED] [2005] Checkbox trouble again...
Hi,
I have trouble with the checkbox I am using chkUseProxy. When I enter the address of the ip which the checkbox is false and when I click the button, it did not connect to the server. They only works when the checkbox is true. Somebody called christopherpm who helped me on my previous thread, I have told him the problem I have got and he got messed up which it is the wrong way round. The checkbox should be false but he made silly error with the checkbox which it is true. I am not really happy with him the way he have done is wasted my time to make another thread again! :mad:
here it the code:
Code:
Private Sub FindServer_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles FindServer.Click
If GetHTMLPage("http://www.whatismyip.com" & ProxyAddress.Text, chkUseProxy.Checked, ProxyAddress.Text, IIf(IsNumeric(ProxyPort.Text), ProxyPort.Text, 0), UserName.Text, Password.Text) Is "" Then
TextBox1.Text = TextBox1.Text
Else
Textbox1.Text = ProxyAddress.Text
End If
End Sub
Public Function GetExternalIP() As String
Dim IP_URL As String = "http://checkip.dyndns.org"
Dim strHTML, strIP As String
Try
Dim objWebReq As System.Net.WebRequest = System.Net.WebRequest.Create(IP_URL)
Dim objWebResp As System.Net.WebResponse = objWebReq.GetResponse()
Dim strmResp As System.IO.Stream = objWebResp.GetResponseStream()
Dim srResp As System.IO.StreamReader = New System.IO.StreamReader(strmResp, System.Text.Encoding.UTF8)
strHTML = srResp.ReadToEnd()
Dim regexIP As System.Text.RegularExpressions.Regex
regexIP = New System.Text.RegularExpressions.Regex("\b\d{1,3}.\d{1,3}.\d{1,3}.\d{1,3}\b")
strIP = regexIP.Match(strHTML).Value
Return strIP
Catch ex As Exception
MessageBox.Show("Can't retrieve external IP: " & ex.Message)
Return Nothing
End Try
End Function
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 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 frmMain_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
TextBox1.Text = GetExternalIP()
If chkUseProxy.Checked = False Then
ProxyAddress.Enabled = True
ProxyPort.Enabled = True
ElseIf chkUseProxy.Checked = True Then
ProxyAddress.Enabled = False
ProxyPort.Enabled = False
End If
End Sub
Private Sub chkUseProxy_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles chkUseProxy.CheckedChanged
If chkUseProxy.Checked = False Then
ProxyPort.Enabled = True
ProxyAddress.Enabled = True
ElseIf chkUseProxy.Checked = True Then
ProxyPort.Enabled = False
ProxyAddress.Enabled = False
End If
End Sub
I don't want to use the checkbox to be true and connect to the server, I only wants the checkbox to be false which connect to the server. That's the proper way what I wanted.
Hope you can help!!!!!!!!!!!!
Thanks,
Mark
Re: [2005] Checkbox trouble again...
change this
to
Code:
If not UseProxy Then
Re: [2005] Checkbox trouble again...
Quote:
Originally Posted by Mark107
Somebody called christopherpm who helped me on my previous thread, I have told him the problem I have got and he got messed up which it is the wrong way round. The checkbox should be false but he made silly error with the checkbox which it is true. I am not really happy with him the way he have done is wasted my time to make another thread again! :mad:
dont criticise anyone nobody forced you to accept solution given by him :D
Re: [2005] Checkbox trouble again...
Thanks for your quick advise, christopherpm did not use If Not UseProxy as statement. Thanks for your help! :thumb:
I am going to forgive him, he forgot to use that statement. ;)
Anyway, solved! :)