If.....Else?  
Author Message
JonDotG





PostPosted: Wed Dec 14 11:11:29 CST 2005 Top

Visual Basic >> If.....Else? I have a WebBrowser control & a hidden ListBox. When the Form loads,
the ListBox gets populated with those sites which the user has
categorized as Restricted Sites (the ListBox actually gets populated
with the different URLs from a text file).

Now what I want is when the user types a URL in the address bar (which
is a ComboBox), first it has to be checked whether the typed in URL
exists in the ListBox or not. If yes, then show a MsgBox to the user
asking hime whether he would like to proceed ahead or not (since it is
a restricted site). If yes, take the user to the URL but if no, stay
there itself & change the URL of the ComboBox to what it was before the
user typed in the URL of the restricted site.

For e.g. a user first visits www.yahoo.com which is not listed as a
restricted site (though it will be checked first whether www.yahoo.com
is listed as a restricted site or not). Next he types www.google.com,
which is listed as a restricted site, in the address bar. When he
presses 'Enter' on the keyboard, since www.google.com is a restricted
site, he will be first shown a MsgBox asking whether he would like to
proceed or not. If yes, direct the user to www.google.com but if no,
stay there itself & change the address in the address bar to
www.yahoo.com (since before typing www.google.com, the user was in
www.yahoo.com).

This is what I tried:

Private Sub cboURL_Click(Index As Integer)
Dim iCount
For iCount = 0 To lstSites(0).ListCount - 1
If (InStr(cboURL(0).Text, lstSites(0).List(iCount)) > 0) Then
If (vbYes = MsgBox("Are you sure you want to proceed?",
vbYesNo)) Then
wWeb.Navigate2 cboURL(0).Text
Else
wWeb.Stop
End If
'Else
' wWeb.Navigate2 cboURL(0).Text
End If
Next
End Sub

Suppose the user types www.google.com, which is a restricted site, in
the address bar. He is shown the MsgBox. Assume that he clicks No; so
he stays put where he was & doesn't proceed ahead.

Assume that next he enters www.yahoo.com in the address bar which is
not a restricted site. Under such circumstances, the commented "Else"
condition would take the user to www.yahoo.com after verifying that
www.yahoo.com is not a restricted site BUT if that "Else" condition
(i.e. the second "Else" condition) is not commented, then when the user
had been shown the MsgBox asking him whether he would like to proceed
or not after he had typed www.google.com in the address bar, then
irrespective of whether the user clicks Yes or No in the MsgBox, he is
still directed to www.google.com. The bottomline is there can be 3
scenarios:

1. URL typed in the address bar exists in the ListBox; show MsgBox
a. If "Yes" is clicked in the MsgBox, let the user proceed forward to
the restricted site (MsgBox="Yes")
b. If "No", stay there itself & don't let the user proceed ahead.
(MsgBox="No")

2. URL typed by the user in the address bar doesn't exist in the
ListBox; so let the user go ahead (which is as good as MsgBox="No").

So on one hand, when MsgBox="No", then stay there itself but on the
other hand, when MsgBox="No", proceed ahead. This is where I am getting
stuck up i.e. the condition is the same (MsgBox="No") but 2 different
statements have to be executed.

Any ideas how do I overcome this problem?

Thanks,

Arpan

Visual Studio76  
 
 
Veign





PostPosted: Wed Dec 14 11:11:29 CST 2005 Top

Visual Basic >> If.....Else? What happens if the user types http://google.com or http://video.google.com
or www.google.com/catalogs if www.google.com is a restricted site?

--
Chris Hanscom - Microsoft MVP (VB)
Veign's Resource Center
http://www.veign.com/vrc_main.asp
Veign's Blog
http://www.veign.com/blog
--


"Arpan" <EMail@HideDomain.com> wrote in message
news:EMail@HideDomain.com...
>I have a WebBrowser control & a hidden ListBox. When the Form loads,
> the ListBox gets populated with those sites which the user has
> categorized as Restricted Sites (the ListBox actually gets populated
> with the different URLs from a text file).
>
> Now what I want is when the user types a URL in the address bar (which
> is a ComboBox), first it has to be checked whether the typed in URL
> exists in the ListBox or not. If yes, then show a MsgBox to the user
> asking hime whether he would like to proceed ahead or not (since it is
> a restricted site). If yes, take the user to the URL but if no, stay
> there itself & change the URL of the ComboBox to what it was before the
> user typed in the URL of the restricted site.
>
> For e.g. a user first visits www.yahoo.com which is not listed as a
> restricted site (though it will be checked first whether www.yahoo.com
> is listed as a restricted site or not). Next he types www.google.com,
> which is listed as a restricted site, in the address bar. When he
> presses 'Enter' on the keyboard, since www.google.com is a restricted
> site, he will be first shown a MsgBox asking whether he would like to
> proceed or not. If yes, direct the user to www.google.com but if no,
> stay there itself & change the address in the address bar to
> www.yahoo.com (since before typing www.google.com, the user was in
> www.yahoo.com).
>
> This is what I tried:
>
> Private Sub cboURL_Click(Index As Integer)
> Dim iCount
> For iCount = 0 To lstSites(0).ListCount - 1
> If (InStr(cboURL(0).Text, lstSites(0).List(iCount)) > 0) Then
> If (vbYes = MsgBox("Are you sure you want to proceed?",
> vbYesNo)) Then
> wWeb.Navigate2 cboURL(0).Text
> Else
> wWeb.Stop
> End If
> 'Else
> ' wWeb.Navigate2 cboURL(0).Text
> End If
> Next
> End Sub
>
> Suppose the user types www.google.com, which is a restricted site, in
> the address bar. He is shown the MsgBox. Assume that he clicks No; so
> he stays put where he was & doesn't proceed ahead.
>
> Assume that next he enters www.yahoo.com in the address bar which is
> not a restricted site. Under such circumstances, the commented "Else"
> condition would take the user to www.yahoo.com after verifying that
> www.yahoo.com is not a restricted site BUT if that "Else" condition
> (i.e. the second "Else" condition) is not commented, then when the user
> had been shown the MsgBox asking him whether he would like to proceed
> or not after he had typed www.google.com in the address bar, then
> irrespective of whether the user clicks Yes or No in the MsgBox, he is
> still directed to www.google.com. The bottomline is there can be 3
> scenarios:
>
> 1. URL typed in the address bar exists in the ListBox; show MsgBox
> a. If "Yes" is clicked in the MsgBox, let the user proceed forward to
> the restricted site (MsgBox="Yes")
> b. If "No", stay there itself & don't let the user proceed ahead.
> (MsgBox="No")
>
> 2. URL typed by the user in the address bar doesn't exist in the
> ListBox; so let the user go ahead (which is as good as MsgBox="No").
>
> So on one hand, when MsgBox="No", then stay there itself but on the
> other hand, when MsgBox="No", proceed ahead. This is where I am getting
> stuck up i.e. the condition is the same (MsgBox="No") but 2 different
> statements have to be executed.
>
> Any ideas how do I overcome this problem?
>
> Thanks,
>
> Arpan
>


 
 
Arpan





PostPosted: Wed Dec 14 11:40:09 CST 2005 Top

Visual Basic >> If.....Else? >>What happens if the user types http://google.com or http://video.google.com
>>or www.google.com/catalogs if www.google.com is a restricted site?

I have taken care of that......didn't include it for
brevity.......already it's quite huge a post.

Arpan

 
 
Larry





PostPosted: Wed Dec 14 12:50:04 CST 2005 Top

Visual Basic >> If.....Else?
"Arpan" <EMail@HideDomain.com> wrote in message news:EMail@HideDomain.com...
> I have a WebBrowser control & a hidden ListBox. When the Form loads,
> the ListBox gets populated with those sites which the user has
> categorized as Restricted Sites (the ListBox actually gets populated
> with the different URLs from a text file).
>
> Now what I want is when the user types a URL in the address bar (which
> is a ComboBox), first it has to be checked whether the typed in URL
> exists in the ListBox or not.

I don't know what you are actually trying to accomplish, but I would
suppose a restricted site should not be visited unless explicitly agreed
to. What you propose here only catches the user selecting a site from
your list, it does nothing about a web page that has a link to some
restricted site. If the web page has such a link, then the user is free to
go there. If this was a parental control thing, a kid could easily whip up
a 'favorites' page with links to any site they wanted, bypassing the parental
control. If the sites were actually dangerous (in some fashion) then again,
they could still be happened upon through a link in some other page.

The following method would be a more appropreate route:

(Add a textbox, a button and a webbrowser to a new form)

HTH
LFS

Private Sub Command1_Click()
wWeb.Navigate2 Text1.Text
End Sub

Private Sub wWeb_BeforeNavigate2(ByVal pDisp As Object, URL As Variant, Flags As Variant, TargetFrameName As Variant, PostData As
Variant, Headers As Variant, Cancel As Boolean)
If IsRestricted(URL) Then
If vbNo = MsgBox("The requested site is restricted from use. Proceed?", vbYesNo, "Restricted Site Notice") Then
Cancel = True
Text1.Text = Text1.Tag
End If
End If
End Sub

Private Sub wWeb_NavigateComplete2(ByVal pDisp As Object, URL As Variant)
Text1.Text = URL
Text1.Tag = URL
End Sub

Private Function IsRestricted(ByVal URL As String) As Boolean
' Test URL here
IsRestricted = True ' for testing
End Function





 
 
Arpan





PostPosted: Wed Dec 14 14:51:00 CST 2005 Top

Visual Basic >> If.....Else? >>I don't know what you are actually trying to accomplish, but I would
>>suppose a restricted site should not be visited unless explicitly agreed
>>to. What you propose here only catches the user selecting a site from
>>your list, it does nothing about a web page that has a link to some
>>restricted site. If the web page has such a link, then the user is free to
>>go there. If this was a parental control thing, a kid could easily whip up
>>a 'favorites' page with links to any site they wanted, bypassing the parental
>>control. If the sites were actually dangerous (in some fashion) then again,
>>they could still be happened upon through a link in some other page.

I very well agree with you & as said earlier, to keep my post concise,
I have reproduced just a part of what I have actually done but I have
to admit my mistake that what you have done in the BeforeNavigate2
event function, I incorporated that in the CommandStateChange event
function. I should have done that in the BeforeNavigate2 event
function. Thanks for pointing it out.

Regards,

Arpan

 
 
Arpan





PostPosted: Wed Dec 14 15:21:14 CST 2005 Top

Visual Basic >> If.....Else? This is how I finally did it:

Private Sub cboURL_Click(Index As Integer)
Dim blnRestricted As Boolean
Dim i
blnRestricted = False
For i = 0 To lstSites(0).ListCount - 1
If (InStr(cboURL(0).Text, lstSites(0).List(i)) > 0) Then
blnRestricted = True
Exit For
End If
Next i
If (blnRestricted) Then
If (vbYes = MsgBox("Are you sure you want to proceed?",
vbYesNo)) Then
wWeb.Navigate cboURL(0).Text
End If
Else
wWeb.Navigate cboURL(0).Text
End If
End Sub

Using something similar, I incorporated the code to ensure that
parental guidance is adhered to when a link is clicked.

Arpan