473,394 Members | 1,956 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Declaring/populating variable arrays in ASP.NET???

Sorry if this is the wrong group. I tried to find the one I thought
would be most relevant.

I'm an old PHP guy, who knows little about asp and NOTHING about
asp.net, but need to learn at least enough to convert a favorite PHP
script to work on an ASP.NET site.

I'm experimenting with simple example scripts that will help me learn
how to implement each "piece" of the puzzle.

Doing well so far... one piece of the puzzle at a time.
I need to create a simple funtion that will check the IP Address of a
visitor against an "array variable" of banned IPs.

In asp, it saeems simple enough. Here's the include that contains the
function to be called (in .asp):

##############################
<%
Dim sIPAddress
sIPAddress = Request.ServerVariables("HTTP_X_FORWARDED_FOR")
if sIPAddress = "" then
sIPAddress = Request.ServerVariables("REMOTE_ADDR")
End If
%>

<script language="VB" runat=server>

function BannedIP(sIPAddress)
Dim sBanned
sBanned =
Array("69.202.123.157","216.239.39.5","216.239.37. 5","216.239.37.104","2
16.155.200.231","216.155.200.232","216.155.200.233 ","216.155.200.234")

Dim i
For i = 0 to UBound( [sBanned] )
If selCriteria(i,1) = cstr(sBanned) Then
BannedIP = TRUE
Else
BannedIP = false
End Function

</script>
################################

The function is called from an existing .aspx page thus:
################################
if BannedIP(sIPAddress) then
' show it the "SORRY" page
Server.Execute("sorry.aspx")
' Then STOP! (same as PHP's "exit;" statement ???)
Response.End
' otherwise it's cool, go ahead and display this page below
End If
################################

ASP.NET doesn't like this at all!
It tells me: "'Array' is a type and cannot be used as an expression."
:-(

What is the proper syntax in ASP.NET for:
variable = Array("value1","value2","value3")

I would simply use the function as is, written in asp, but the pages
are VERY .aspx and choke on it.
ALSO: My next piece of the puzzle will be to tackle this one, using the
same test script:
If I want e to ban a violator with a dynamic IP, how do I deal with
entire C-blocks (e.g.: BannedIP is TRUE if sIPAdress contains
123.45.6.*)
Many TIA
:-)
Friday

--
#####################################
"The people cannot be all, & always well informed. The part which is wrong will
be discontented in proportion to the importance of the facts they misconceive.
If they remain quiet under such misconceptions it is a lethargy, the forerunner
of death to the public liberty. What country before ever existed a century & a
half without a rebellion? & what country can preserve it's liberties if their
rulers are not warned from time to time that their people preserve the spirit
of resistance? Let them take arms... The tree of liberty must be refreshed from
time to time with the blood of patriots & tyrants"
-- Thomas Jefferson
#####################################
Nov 19 '05 #1
34 2084
Friday wrote:

What is the proper syntax in ASP.NET for:
variable = Array("value1","value2","value3")

I would simply use the function as is, written in asp, but the pages
are VERY .aspx and choke on it.

http://www.vb-helper.com/howto_net_declare_arrays.html

ALSO: My next piece of the puzzle will be to tackle this one, using the
same test script:
If I want e to ban a violator with a dynamic IP, how do I deal with
entire C-blocks (e.g.: BannedIP is TRUE if sIPAdress contains
123.45.6.*)
Many TIA
:-)
Friday


To get the visitor's IP address (if you don't know this already):

http://groups-beta.google.com/group/...057ebbfed6c18b

To match the 'wildcard' comparison you need, just check

sIPAdress.IndexOf("123.45.6.") = 0

If this is true, then ban them...

--
Craig Deelsnyder
Microsoft MVP - ASP/ASP.NET
Nov 19 '05 #2
> What is the proper syntax in ASP.NET for:
variable = Array("value1","value2","value3")

Dim sBanned() As String =
{"69.202.123.157","216.239.39.5","216.239.37.5","2 16.239.37.104","216.155.200.231","216.155.200.232" ,"216.155.200.233","216.155.200.234"}

Jody
"Friday" <fr****@nowhere.org> wrote in message
news:060520051306302444%fr****@nowhere.org... Sorry if this is the wrong group. I tried to find the one I thought
would be most relevant.

I'm an old PHP guy, who knows little about asp and NOTHING about
asp.net, but need to learn at least enough to convert a favorite PHP
script to work on an ASP.NET site.

I'm experimenting with simple example scripts that will help me learn
how to implement each "piece" of the puzzle.

Doing well so far... one piece of the puzzle at a time.
I need to create a simple funtion that will check the IP Address of a
visitor against an "array variable" of banned IPs.

In asp, it saeems simple enough. Here's the include that contains the
function to be called (in .asp):

##############################
<%
Dim sIPAddress
sIPAddress = Request.ServerVariables("HTTP_X_FORWARDED_FOR")
if sIPAddress = "" then
sIPAddress = Request.ServerVariables("REMOTE_ADDR")
End If
%>

<script language="VB" runat=server>

function BannedIP(sIPAddress)
Dim sBanned
sBanned =
Array("69.202.123.157","216.239.39.5","216.239.37. 5","216.239.37.104","2
16.155.200.231","216.155.200.232","216.155.200.233 ","216.155.200.234")

Dim i
For i = 0 to UBound( [sBanned] )
If selCriteria(i,1) = cstr(sBanned) Then
BannedIP = TRUE
Else
BannedIP = false
End Function

</script>
################################

The function is called from an existing .aspx page thus:
################################
if BannedIP(sIPAddress) then
' show it the "SORRY" page
Server.Execute("sorry.aspx")
' Then STOP! (same as PHP's "exit;" statement ???)
Response.End
' otherwise it's cool, go ahead and display this page below
End If
################################

ASP.NET doesn't like this at all!
It tells me: "'Array' is a type and cannot be used as an expression."
:-(

What is the proper syntax in ASP.NET for:
variable = Array("value1","value2","value3")

I would simply use the function as is, written in asp, but the pages
are VERY .aspx and choke on it.
ALSO: My next piece of the puzzle will be to tackle this one, using the
same test script:
If I want e to ban a violator with a dynamic IP, how do I deal with
entire C-blocks (e.g.: BannedIP is TRUE if sIPAdress contains
123.45.6.*)
Many TIA
:-)
Friday

--
#####################################
"The people cannot be all, & always well informed. The part which is wrong
will
be discontented in proportion to the importance of the facts they
misconceive.
If they remain quiet under such misconceptions it is a lethargy, the
forerunner
of death to the public liberty. What country before ever existed a century
& a
half without a rebellion? & what country can preserve it's liberties if
their
rulers are not warned from time to time that their people preserve the
spirit
of resistance? Let them take arms... The tree of liberty must be refreshed
from
time to time with the blood of patriots & tyrants"
-- Thomas Jefferson
#####################################

Nov 19 '05 #3
In article <OT*************@TK2MSFTNGP12.phx.gbl>, Jody Gelowitz
<jg**************@blah.leevalley.com> wrote:
What is the proper syntax in ASP.NET for:
variable = Array("value1","value2","value3")

Dim sBanned() As String =

{"69.202.123.157","216.239.39.5","216.239.37.5","2 16.239.37.104","216.155.200.
231","216.155.200.232","216.155.200.233","216.155. 200.234"}

Jody


Many Thanks!
Can't wait to try it.
:-)

"Friday" <fr****@nowhere.org> wrote in message
news:060520051306302444%fr****@nowhere.org...
Sorry if this is the wrong group. I tried to find the one I thought
would be most relevant.

I'm an old PHP guy, who knows little about asp and NOTHING about
asp.net, but need to learn at least enough to convert a favorite PHP
script to work on an ASP.NET site.

I'm experimenting with simple example scripts that will help me learn
how to implement each "piece" of the puzzle.

Doing well so far... one piece of the puzzle at a time.
I need to create a simple funtion that will check the IP Address of a
visitor against an "array variable" of banned IPs.

In asp, it saeems simple enough. Here's the include that contains the
function to be called (in .asp):

##############################
<%
Dim sIPAddress
sIPAddress = Request.ServerVariables("HTTP_X_FORWARDED_FOR")
if sIPAddress = "" then
sIPAddress = Request.ServerVariables("REMOTE_ADDR")
End If
%>

<script language="VB" runat=server>

function BannedIP(sIPAddress)
Dim sBanned
sBanned =
Array("69.202.123.157","216.239.39.5","216.239.37. 5","216.239.37.104","2
16.155.200.231","216.155.200.232","216.155.200.233 ","216.155.200.234")

Dim i
For i = 0 to UBound( [sBanned] )
If selCriteria(i,1) = cstr(sBanned) Then
BannedIP = TRUE
Else
BannedIP = false
End Function

</script>
################################

The function is called from an existing .aspx page thus:
################################
if BannedIP(sIPAddress) then
' show it the "SORRY" page
Server.Execute("sorry.aspx")
' Then STOP! (same as PHP's "exit;" statement ???)
Response.End
' otherwise it's cool, go ahead and display this page below
End If
################################

ASP.NET doesn't like this at all!
It tells me: "'Array' is a type and cannot be used as an expression."
:-(

What is the proper syntax in ASP.NET for:
variable = Array("value1","value2","value3")

I would simply use the function as is, written in asp, but the pages
are VERY .aspx and choke on it.
ALSO: My next piece of the puzzle will be to tackle this one, using the
same test script:
If I want e to ban a violator with a dynamic IP, how do I deal with
entire C-blocks (e.g.: BannedIP is TRUE if sIPAdress contains
123.45.6.*)
Many TIA
:-)
Friday

--
#####################################
"The people cannot be all, & always well informed. The part which is wrong
will
be discontented in proportion to the importance of the facts they
misconceive.
If they remain quiet under such misconceptions it is a lethargy, the
forerunner
of death to the public liberty. What country before ever existed a century
& a
half without a rebellion? & what country can preserve it's liberties if
their
rulers are not warned from time to time that their people preserve the
spirit
of resistance? Let them take arms... The tree of liberty must be refreshed
from
time to time with the blood of patriots & tyrants"
-- Thomas Jefferson
#####################################



--
#####################################
"The people cannot be all, & always well informed. The part which is wrong will
be discontented in proportion to the importance of the facts they misconceive.
If they remain quiet under such misconceptions it is a lethargy, the forerunner
of death to the public liberty. What country before ever existed a century & a
half without a rebellion? & what country can preserve it's liberties if their
rulers are not warned from time to time that their people preserve the spirit
of resistance? Let them take arms... The tree of liberty must be refreshed from
time to time with the blood of patriots & tyrants"
-- Thomas Jefferson
#####################################
Nov 19 '05 #4
In article <uF**************@TK2MSFTNGP14.phx.gbl>, Craig Deelsnyder
<cdeelsny@NO_SPAM_4_MEyahoo.com> wrote:
Friday wrote:

What is the proper syntax in ASP.NET for:
variable = Array("value1","value2","value3")

I would simply use the function as is, written in asp, but the pages
are VERY .aspx and choke on it.


http://www.vb-helper.com/howto_net_declare_arrays.html

ALSO: My next piece of the puzzle will be to tackle this one, using the
same test script:
If I want e to ban a violator with a dynamic IP, how do I deal with
entire C-blocks (e.g.: BannedIP is TRUE if sIPAdress contains
123.45.6.*)
Many TIA
:-)
Friday


To get the visitor's IP address (if you don't know this already):
http://groups-beta.google.com/group/...ework.aspnet/b
rowse_frm/thread/dddc409ea9550571/ba057ebbfed6c18b?&rnum=2&hl=en#ba057ebbfed6c
18b

To match the 'wildcard' comparison you need, just check

sIPAdress.IndexOf("123.45.6.") = 0

If this is true, then ban them...


Thanks Craig
:-)
Friday

--
#####################################
"The people cannot be all, & always well informed. The part which is wrong will
be discontented in proportion to the importance of the facts they misconceive.
If they remain quiet under such misconceptions it is a lethargy, the forerunner
of death to the public liberty. What country before ever existed a century & a
half without a rebellion? & what country can preserve it's liberties if their
rulers are not warned from time to time that their people preserve the spirit
of resistance? Let them take arms... The tree of liberty must be refreshed from
time to time with the blood of patriots & tyrants"
-- Thomas Jefferson
#####################################
Nov 19 '05 #5
In article <OT*************@TK2MSFTNGP12.phx.gbl>, Jody Gelowitz
<jg**************@blah.leevalley.com> wrote:
What is the proper syntax in ASP.NET for:
variable = Array("value1","value2","value3")

Dim sBanned() As String =

{"69.202.123.157","216.239.39.5","216.239.37.5","2 16.239.37.104","216.155.200.
231","216.155.200.232","216.155.200.233","216.155. 200.234"}

Jody


Darn...
Now I'm geting an error: "Expression expected."

at: Dim sBanned() As String =

Something else wrong withmy little fndtion.
Any thoughts?

Now my little test reads:
##############################
<%
Dim sIPAddress
sIPAddress = Request.ServerVariables("HTTP_X_FORWARDED_FOR")
if sIPAddress = "" then
sIPAddress = Request.ServerVariables("REMOTE_ADDR")
End If
%>

<script language="VB" runat=server>

function BannedIP(sIPAddress)

Dim sBanned() As String =
("69.202.123.157","216.239.39.5","216.239.37.5","2 16.239.37.104","2
16.155.200.231","216.155.200.232","216.155.200.233 ","216.155.200.234")

Dim i
For i = 0 to UBound( [sBanned] )
If selCriteria(i,1) = cstr(sBanned) Then
BannedIP = TRUE
Else
BannedIP = false
End Function

</script>
################################

The function is called from an existing .aspx page thus:
################################
if BannedIP(sIPAddress) then
' show it the "SORRY" page
Server.Execute("sorry.aspx")
' Then STOP! (same as PHP's "exit;" statement ???)
Response.End
' otherwise it's cool, go ahead and display this page below
End If
################################

--
#####################################
"The people cannot be all, & always well informed. The part which is wrong will
be discontented in proportion to the importance of the facts they misconceive.
If they remain quiet under such misconceptions it is a lethargy, the forerunner
of death to the public liberty. What country before ever existed a century & a
half without a rebellion? & what country can preserve it's liberties if their
rulers are not warned from time to time that their people preserve the spirit
of resistance? Let them take arms... The tree of liberty must be refreshed from
time to time with the blood of patriots & tyrants"
-- Thomas Jefferson
#####################################
Nov 19 '05 #6
Dim sBan as String() = {...}

-Brock
DevelopMentor
http://staff.develop.com/ballen
In article <OT*************@TK2MSFTNGP12.phx.gbl>, Jody Gelowitz
<jg**************@blah.leevalley.com> wrote:
What is the proper syntax in ASP.NET for:
variable = Array("value1","value2","value3")

Dim sBanned() As String =

{"69.202.123.157","216.239.39.5","216.239.37.5","2 16.239.37.104","216
.155.200. 231","216.155.200.232","216.155.200.233","216.155. 200.234"}

Jody

Darn...
Now I'm geting an error: "Expression expected."
at: Dim sBanned() As String =

Something else wrong withmy little fndtion.
Any thoughts?
Now my little test reads:
##############################
<%
Dim sIPAddress
sIPAddress = Request.ServerVariables("HTTP_X_FORWARDED_FOR")
if sIPAddress = "" then
sIPAddress = Request.ServerVariables("REMOTE_ADDR")
End If
%>
<script language="VB" runat=server>

function BannedIP(sIPAddress)

Dim sBanned() As String =
("69.202.123.157","216.239.39.5","216.239.37.5","2 16.239.37.104","2
16.155.200.231","216.155.200.232","216.155.200.233 ","216.155.200.234")

Dim i
For i = 0 to UBound( [sBanned] )
If selCriteria(i,1) = cstr(sBanned) Then
BannedIP = TRUE
Else
BannedIP = false
End Function
</script>
################################
The function is called from an existing .aspx page thus:
################################
if BannedIP(sIPAddress) then
' show it the "SORRY" page
Server.Execute("sorry.aspx")
' Then STOP! (same as PHP's "exit;" statement ???)
Response.End
' otherwise it's cool, go ahead and display this page below
End If
################################


Nov 19 '05 #7
Friday, Jody's replied on the Array, but the syntac on your VB code needs a
couple of tweeks:
function BannedIP(sIPAddress as String) as Boolean
Dim sBanned, i as integar

sBanned = _
Array("69.202.123.157","216.239.39.5","216.239.37. 5","216.239.37.104", _
"216.155.200.231","216.155.200.232","216.155.200.2 33","216.155.200.234")

For i = 0 to UBound( [sBanned] )
If sIPAddress = cstr(sBanned(i)) Then
BannedIP = TRUE
Exit For
Else
BannedIP = false
End If
Next
End Function

I am assuming that you are passing the IPAddress to be checked. Also, if you
want to check through the whole array, you will want to check each element of
the array. Also, you will want to break if it finds a banned address.

Just to let you know, I have 25 years of C, C++, C#, and only 1 year of VB
(and then only in MS Office. So you might know more about VB than I.

John H W

"Friday" wrote:
Sorry if this is the wrong group. I tried to find the one I thought
would be most relevant.

I'm an old PHP guy, who knows little about asp and NOTHING about
asp.net, but need to learn at least enough to convert a favorite PHP
script to work on an ASP.NET site.

I'm experimenting with simple example scripts that will help me learn
how to implement each "piece" of the puzzle.

Doing well so far... one piece of the puzzle at a time.
I need to create a simple funtion that will check the IP Address of a
visitor against an "array variable" of banned IPs.

In asp, it saeems simple enough. Here's the include that contains the
function to be called (in .asp):

##############################
<%
Dim sIPAddress
sIPAddress = Request.ServerVariables("HTTP_X_FORWARDED_FOR")
if sIPAddress = "" then
sIPAddress = Request.ServerVariables("REMOTE_ADDR")
End If
%>

<script language="VB" runat=server>

function BannedIP(sIPAddress)
Dim sBanned
sBanned =
Array("69.202.123.157","216.239.39.5","216.239.37. 5","216.239.37.104","2
16.155.200.231","216.155.200.232","216.155.200.233 ","216.155.200.234")

Dim i
For i = 0 to UBound( [sBanned] )
If selCriteria(i,1) = cstr(sBanned) Then
BannedIP = TRUE
Else
BannedIP = false
End Function

</script>
################################

The function is called from an existing .aspx page thus:
################################
if BannedIP(sIPAddress) then
' show it the "SORRY" page
Server.Execute("sorry.aspx")
' Then STOP! (same as PHP's "exit;" statement ???)
Response.End
' otherwise it's cool, go ahead and display this page below
End If
################################

ASP.NET doesn't like this at all!
It tells me: "'Array' is a type and cannot be used as an expression."
:-(

What is the proper syntax in ASP.NET for:
variable = Array("value1","value2","value3")

I would simply use the function as is, written in asp, but the pages
are VERY .aspx and choke on it.
ALSO: My next piece of the puzzle will be to tackle this one, using the
same test script:
If I want e to ban a violator with a dynamic IP, how do I deal with
entire C-blocks (e.g.: BannedIP is TRUE if sIPAdress contains
123.45.6.*)
Many TIA
:-)
Friday

--
#####################################
"The people cannot be all, & always well informed. The part which is wrong will
be discontented in proportion to the importance of the facts they misconceive.
If they remain quiet under such misconceptions it is a lethargy, the forerunner
of death to the public liberty. What country before ever existed a century & a
half without a rebellion? & what country can preserve it's liberties if their
rulers are not warned from time to time that their people preserve the spirit
of resistance? Let them take arms... The tree of liberty must be refreshed from
time to time with the blood of patriots & tyrants"
-- Thomas Jefferson
#####################################

Nov 19 '05 #8
In article <0B**********************************@microsoft.co m>, John H
W <Jo****@discussions.microsoft.com> wrote:
Friday, Jody's replied on the Array, but the syntac on your VB code needs a
couple of tweeks:
function BannedIP(sIPAddress as String) as Boolean
Dim sBanned, i as integar
I see. Thank You.
But.... do I use Jody's example for declaring the variable or the
following example [variable=Array(...)]???
sBanned = _
Array("69.202.123.157","216.239.39.5","216.239.37. 5","216.239.37.104", _
"216.155.200.231","216.155.200.232","216.155.200.2 33","216.155.200.234")

For i = 0 to UBound( [sBanned] )
If sIPAddress = cstr(sBanned(i)) Then
BannedIP = TRUE
Exit For
Else
BannedIP = false
End If
Next
End Function

I am assuming that you are passing the IPAddress to be checked.
Yes.
Also, if you
want to check through the whole array, you will want to check each element of
the array. Also, you will want to break if it finds a banned address.

Just to let you know, I have 25 years of C, C++, C#, and only 1 year of VB
(and then only in MS Office. So you might know more about VB than I.


Not quite.
Just an old PHP guy.

--
Nov 19 '05 #9
I have not used Array as such. How I do it is:

Dim sIPAddress(8) as String
I would use 8 or some other amount that I would not exceed. I then use
another function to fill it from an XML or other "formated" file, passing the
array, i.e.,

brtn = FillBannedAddresses(sIPAddress())

Then declare the other function as
public function FillBannedAddresses(ByRef sIPAddress() as string) as Boolean
I then return a true if filled (false if a problem)

In this other function, I would open the file, parse it and load the
addresses into the passed array (byref).

I am leaving work now or I would give you some more "pointers."

John H W

"Friday" wrote:
In article <0B**********************************@microsoft.co m>, John H
W <Jo****@discussions.microsoft.com> wrote:
Friday, Jody's replied on the Array, but the syntac on your VB code needs a
couple of tweeks:
function BannedIP(sIPAddress as String) as Boolean
Dim sBanned, i as integar


I see. Thank You.
But.... do I use Jody's example for declaring the variable or the
following example [variable=Array(...)]???

sBanned = _
Array("69.202.123.157","216.239.39.5","216.239.37. 5","216.239.37.104", _
"216.155.200.231","216.155.200.232","216.155.200.2 33","216.155.200.234")

For i = 0 to UBound( [sBanned] )
If sIPAddress = cstr(sBanned(i)) Then
BannedIP = TRUE
Exit For
Else
BannedIP = false
End If
Next
End Function

I am assuming that you are passing the IPAddress to be checked.


Yes.
Also, if you
want to check through the whole array, you will want to check each element of
the array. Also, you will want to break if it finds a banned address.

Just to let you know, I have 25 years of C, C++, C#, and only 1 year of VB
(and then only in MS Office. So you might know more about VB than I.


Not quite.
Just an old PHP guy.

--

Nov 19 '05 #10
John H W <Jo****@discussions.microsoft.com> wrote:
I have not used Array as such. How I do it is:

Dim sIPAddress(8) as String
I would use 8 or some other amount that I would not exceed. I then use
another function to fill it from an XML or other "formated" file, passing the
array, i.e.,

brtn = FillBannedAddresses(sIPAddress())

Then declare the other function as
public function FillBannedAddresses(ByRef sIPAddress() as string) as Boolean
I then return a true if filled (false if a problem)

In this other function, I would open the file, parse it and load the
addresses into the passed array (byref).


Yuk. Exceptions are there precisely to indicate problems without you
needing to pass anything by reference or check return values all the
time.

Mind you, if you know how many you're going to parse beforehand, you
wouldn't need to pass the array variable by reference anyway...

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 19 '05 #11
Jon [C# MVP]:

I use exceptions, but sometimes I like the old, tried and true methods (25
years of writing code, starting with cobal, then C, C++, C# & VB.Net). In
the called funtion, I could use an exception, but opening a file, while
testing whether it is open, saves five or six lines for an exception.

Then while reading in the addresses, I check at each read, again testing in
the same if statement, saving even more lines it would take to "switch" to
another exception.

In thinking about what I wrote below while driving home, instead of using
the boolean, I would return the number of addresses read, so my code would
look like:

nNumberRead = FillBannedAddresses(sIPAddress())
if nNumberRead > 0 then
For i = 0 to nNumberRead then
...
Next
end if

Of course, in C#, I would just write:

AddressList *sIPAddress; // where AddressList is a structure for a linked list
if (nNumberRead = FillBannedAddresses(sIPAddress)) > 0 {
... }

Don't forget, Jon, we are giving pointers to a person who is new to VB, but
has plenty of programming experience. When this is the case, I like to give
small directions or pointers and letting the persons use his own experience.
Introducing expections is too great a leap and can cause problems relating to
expections.

I also like "small" functions. Problems are easier and quicker to find.
Therefore, because of memory scope, you have to pass a reference or the info
he needs will "disappear" when he needs to use it. I am fairly new to VB
myself, but when I did try to return a "string array" from a function
[myarray = FunctionReturnString()] contained only the first element - all the
other elements were empty. While it is possible I did not do it correctly,
passing myarray by reference worked [FunctionReturnString(myarray) and
FunctionReturnString(byref myarray as string)].

But I would like to thank you for all your help in these newsgroups.

John H W

"Jon Skeet [C# MVP]" wrote:
John H W <Jo****@discussions.microsoft.com> wrote:
I have not used Array as such. How I do it is:

Dim sIPAddress(8) as String
I would use 8 or some other amount that I would not exceed. I then use
another function to fill it from an XML or other "formated" file, passing the
array, i.e.,

brtn = FillBannedAddresses(sIPAddress())

Then declare the other function as
public function FillBannedAddresses(ByRef sIPAddress() as string) as Boolean
I then return a true if filled (false if a problem)

In this other function, I would open the file, parse it and load the
addresses into the passed array (byref).


Yuk. Exceptions are there precisely to indicate problems without you
needing to pass anything by reference or check return values all the
time.

Mind you, if you know how many you're going to parse beforehand, you
wouldn't need to pass the array variable by reference anyway...

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

Nov 19 '05 #12
John H W <Jo****@discussions.microsoft.com> wrote:
I use exceptions, but sometimes I like the old, tried and true methods (25
years of writing code, starting with cobal, then C, C++, C# & VB.Net).
You mean tried and failed - how many bugs have you seen because people
have failed to look at the return value of a function call? I've
certainly seen loads. Heck, just look at the number of people who don't
use the return value of Stream.Read, and that's giving actual
information beyond just success/failure!
In the called funtion, I could use an exception, but opening a file, while
testing whether it is open, saves five or six lines for an exception.
Well, you've still got to be able to handle the exception anyway...
even if you test for whether or not it's open, it could be opened
immediately after that.
Then while reading in the addresses, I check at each read, again testing in
the same if statement, saving even more lines it would take to "switch" to
another exception.
Are you considering handling the exception at each point? I wouldn't -
chances are if the operation fails, that should be an exception going
up to the next stack layer anyway - if you fail to read the list of
banned IPs, do you really want to just asssume that the visitor is
allowed?
In thinking about what I wrote below while driving home, instead of using
the boolean, I would return the number of addresses read, so my code would
look like:

nNumberRead = FillBannedAddresses(sIPAddress())
if nNumberRead > 0 then
For i = 0 to nNumberRead then
...
Next
end if
Why not just return the array in the first place? You could always
return null or an empty array if you absolutely had to.
Of course, in C#, I would just write:

AddressList *sIPAddress; // where AddressList is a structure for a linked list
if (nNumberRead = FillBannedAddresses(sIPAddress)) > 0 {
... }
Do you mean in C/C++? Or are you considering using unsafe code?
Don't forget, Jon, we are giving pointers to a person who is new to VB, but
has plenty of programming experience. When this is the case, I like to give
small directions or pointers and letting the persons use his own experience.
Introducing expections is too great a leap and can cause problems relating to
expections.
Whereas not introducing exceptions can cause problems relating to
failing to look at return values, and persists the error-prone error
handling from "the bad old days". Why not show best practice right from
the start? Personally I'd suggest that if exceptions are a problem, the
OP should suspend his ASP.NET work and start learning the basics of
..NET properly, starting with some console apps and working up from
there.
I also like "small" functions. Problems are easier and quicker to find.
Therefore, because of memory scope, you have to pass a reference or the info
he needs will "disappear" when he needs to use it.
a) There's a difference between passing an array reference and passing
a parameter *by* reference.
b) The information wouldn't disappear - while the caller has a
reference to the array, the array and everything within it won't
be garbage collected.
I am fairly new to VB
myself, but when I did try to return a "string array" from a function
[myarray = FunctionReturnString()] contained only the first element - all the
other elements were empty. While it is possible I did not do it correctly,
passing myarray by reference worked [FunctionReturnString(myarray) and
FunctionReturnString(byref myarray as string)].
That's certainly a failure in your code. It's hard to say exactly what
the failure was without seeing the code, but passing things by
reference isn't the best solution. Passing by reference should be very
rare.
But I would like to thank you for all your help in these newsgroups.


My pleasure.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 19 '05 #13
Friday,

I never use the notation from you. I use for Net1.1

Dim sBanned() As String =
("69.202.123.157","216.239.39.5","216.239.37.5","2 16.239.37.104","2
16.155.200.231","216.155.200.232","216.155.200.233 ","216.155.200.234")
For i as integer = 0 to sBanned.length - 1
If sBanned(i) = selCriteria Then
BannedIP = True
Else
BannedIP = False
End Function

I hope this helps,

Cor
Nov 19 '05 #14
doh,

my previous code would only test the last one. This is better in my opinion.

\\\\
Dim sBanned() As String =
("69.202.123.157","216.239.39.5","216.239.37.5","2 16.239.37.104","2
16.155.200.231","216.155.200.232","216.155.200.233 ","216.155.200.234")
For i as integer = 0 to sBanned.length - 1
If sBanned(i) = selCriteria Then
BannedIP = True
'take action
exit for
end if
End for
////

I hope this helps,

Cor

Nov 19 '05 #15
Cor Ligthert <no************@planet.nl> wrote:
I never use the notation from you. I use for Net1.1

Dim sBanned() As String =
("69.202.123.157","216.239.39.5","216.239.37.5","2 16.239.37.104","2
16.155.200.231","216.155.200.232","216.155.200.233 ","216.155.200.234")
For i as integer = 0 to sBanned.length - 1
If sBanned(i) = selCriteria Then
BannedIP = True
Else
BannedIP = False
End Function


Just to find an element within an array, I'd suggest using
Array.IndexOf. (In this case, Array.IndexOf(sBanned, selCriteria).) If
the return value is -1, the element isn't found. Otherwise, it is.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 19 '05 #16
Jon,
Just to find an element within an array, I'd suggest using
Array.IndexOf. (In this case, Array.IndexOf(sBanned, selCriteria).) If
the return value is -1, the element isn't found. Otherwise, it is.

I have never thought of using it in that way, however you are right, I will
remember it.

:-)

Cor
Nov 19 '05 #17
In article <e1**************@TK2MSFTNGP14.phx.gbl>, Cor Ligthert
<no************@planet.nl> wrote:
doh,

my previous code would only test the last one. This is better in my opinion.

\\\\
Dim sBanned() As String =
("69.202.123.157","216.239.39.5","216.239.37.5","2 16.239.37.104","2
16.155.200.231","216.155.200.232","216.155.200.233 ","216.155.200.234")
For i as integer = 0 to sBanned.length - 1
If sBanned(i) = selCriteria Then
BannedIP = True
'take action
exit for
end if
End for
////

I hope this helps,

Cor

GREAT advice from everyone!
Thank You.
:-)

But....

NOW I'm getting: "BC30198: ')' expected"
Where in the _WORLD_ does it expect a ')'???
(This little experiment doesn't seem that complicated 8-P)

If this were PHP, I would suspect a problem on the preceeding line:
"function BannedIP(sIPAddress as string) as Boolean"
hmmm...

Anyway, here's what I have on the included page with the function:
#######################
<%
Dim sIPAddress
' check for proxies
sIPAddress = Request.ServerVariables("HTTP_X_FORWARDED_FOR")
if sIPAddress = "" then
sIPAddress = Request.ServerVariables("REMOTE_ADDR")
End If
%>

<script language="VB" runat=server>

function BannedIP(sIPAddress as string) as Boolean

' The following line is where the error occurs [expecting ')']
Dim sBanned() As String =
("69.202.123.157","216.239.39.5","216.239.37.5","2 16.239.37.104","2
16.155.200.231","216.155.200.232","216.155.200.233 ","216.155.200.234")
' No line breaks, missing commas, or quotation marks in above line
For i as integer = 0 to sBanned.length - 1
If sBanned(i) = selCriteria Then
BannedIP = True
exit for
end if
End for

End Function
</script>
########################

And here is how the function is called from other .aspx pages:

########################
<!--#include file = "inc/IsBanned.aspx"-->
<%
if BannedIP(sIPAddress) THEN
' show it the GET LOST page
Server.Execute("get-lost.aspx")
' Then STOP! (same as PHP's "exit;" statement ???)
Response.End
' otherwise it's cool, serve up the page below:
End If
%>

<%@ import Namespace="StoreFront.StoreFront" %>
<%@ assembly name="StoreFront" %>
blah... blah... blah....
########################

Thanks to everyone for their patience.
Hard to teach an old L.A.M.P. dog new trix.
(Who thought Windows would ever catch on????)
;-)

--
#####################################
"The people cannot be all, & always well informed. The part which is wrong will
be discontented in proportion to the importance of the facts they misconceive.
If they remain quiet under such misconceptions it is a lethargy, the forerunner
of death to the public liberty. What country before ever existed a century & a
half without a rebellion? & what country can preserve it's liberties if their
rulers are not warned from time to time that their people preserve the spirit
of resistance? Let them take arms... The tree of liberty must be refreshed from
time to time with the blood of patriots & tyrants"
-- Thomas Jefferson
#####################################
Nov 19 '05 #18
In article <MP***********************@msnews.microsoft.com> , Jon Skeet
[C# MVP] <sk***@pobox.com> wrote:
Cor Ligthert <no************@planet.nl> wrote:
I never use the notation from you. I use for Net1.1

Dim sBanned() As String =
("69.202.123.157","216.239.39.5","216.239.37.5","2 16.239.37.104","2
16.155.200.231","216.155.200.232","216.155.200.233 ","216.155.200.234")
For i as integer = 0 to sBanned.length - 1
If sBanned(i) = selCriteria Then
BannedIP = True
Else
BannedIP = False
End Function


Just to find an element within an array, I'd suggest using
Array.IndexOf. (In this case, Array.IndexOf(sBanned, selCriteria).) If
the return value is -1, the element isn't found. Otherwise, it is.


That's very interestinf Jon.
Thx.

How exactly would I use time-saver? i.e.: where and how would I define
the strings contained within the array (array variable?)?

Just as shown above?
Then simply replace the "IF" statement with your examle?

Thnx Again
Friday

--
#####################################
"The people cannot be all, & always well informed. The part which is wrong will
be discontented in proportion to the importance of the facts they misconceive.
If they remain quiet under such misconceptions it is a lethargy, the forerunner
of death to the public liberty. What country before ever existed a century & a
half without a rebellion? & what country can preserve it's liberties if their
rulers are not warned from time to time that their people preserve the spirit
of resistance? Let them take arms... The tree of liberty must be refreshed from
time to time with the blood of patriots & tyrants"
-- Thomas Jefferson
#####################################
Nov 19 '05 #19
In article <66**********************@msnews.microsoft.com>, Brock Allen
<ba****@NOSPAMdevelop.com> wrote:
Dim sBan as String() = {...}

-Brock
DevelopMentor
http://staff.develop.com/ballen

Thanks Brock. That seems to be the concensus of the proper way to do it.
Still... I'm now getting an error "expecting ')' "
Where in the world it wants a ')' is beyond me.
There are no open parenthesis. (Then again, this isn't perl, is it -not
that I miss Perl.)
8-P
Please see my most recent post.
Drat.

--
#####################################
"The people cannot be all, & always well informed. The part which is wrong will
be discontented in proportion to the importance of the facts they misconceive.
If they remain quiet under such misconceptions it is a lethargy, the forerunner
of death to the public liberty. What country before ever existed a century & a
half without a rebellion? & what country can preserve it's liberties if their
rulers are not warned from time to time that their people preserve the spirit
of resistance? Let them take arms... The tree of liberty must be refreshed from
time to time with the blood of patriots & tyrants"
-- Thomas Jefferson
#####################################
Nov 19 '05 #20
In article <09***********************@nowhere.org>, Friday
<fr****@nowhere.org> wrote:
In article <e1**************@TK2MSFTNGP14.phx.gbl>, Cor Ligthert
<no************@planet.nl> wrote:
doh,

my previous code would only test the last one. This is better in my opinion.

\\\\
Dim sBanned() As String =
("69.202.123.157","216.239.39.5","216.239.37.5","2 16.239.37.104","2
16.155.200.231","216.155.200.232","216.155.200.233 ","216.155.200.234")
For i as integer = 0 to sBanned.length - 1
If sBanned(i) = selCriteria Then
BannedIP = True
'take action
exit for
end if
End for
////

I hope this helps,

Cor

GREAT advice from everyone!
Thank You.
:-)

But....

NOW I'm getting: "BC30198: ')' expected"
Where in the _WORLD_ does it expect a ')'???
(This little experiment doesn't seem that complicated 8-P)

If this were PHP, I would suspect a problem on the preceeding line:
"function BannedIP(sIPAddress as string) as Boolean"
hmmm...

Anyway, here's what I have on the included page with the function:
#######################
<%
Dim sIPAddress
' check for proxies
sIPAddress = Request.ServerVariables("HTTP_X_FORWARDED_FOR")
if sIPAddress = "" then
sIPAddress = Request.ServerVariables("REMOTE_ADDR")
End If
%>

<script language="VB" runat=server>

function BannedIP(sIPAddress as string) as Boolean

' The following line is where the error occurs [expecting ')']
Dim sBanned() As String =
("69.202.123.157","216.239.39.5","216.239.37.5","2 16.239.37.104","2
16.155.200.231","216.155.200.232","216.155.200.233 ","216.155.200.234")
' No line breaks, missing commas, or quotation marks in above line
For i as integer = 0 to sBanned.length - 1
If sBanned(i) = selCriteria Then
BannedIP = True
exit for
end if
End for

End Function
</script>
########################

And here is how the function is called from other .aspx pages:

########################
<!--#include file = "inc/IsBanned.aspx"-->
<%
if BannedIP(sIPAddress) THEN
' show it the GET LOST page
Server.Execute("get-lost.aspx")
' Then STOP! (same as PHP's "exit;" statement ???)
Response.End
' otherwise it's cool, serve up the page below:
End If
%>

<%@ import Namespace="StoreFront.StoreFront" %>
<%@ assembly name="StoreFront" %>
blah... blah... blah....
########################

OK! Now I'm getting somewhere.
When I replace the () in the array with containers {}, the compiler
gets happy.
:-)
(WTF?! Oh well.)
Thenit tells me I need a NXT statement to balance the FOR

OK, I'm down with that.

So, now I have:
#################################
<script language="VB" runat=server>

Dim sBanned() As String =
("69.202.123.157","216.239.39.5","216.239.37.5","2 16.239.37.104","2
16.155.200.231","216.155.200.232","216.155.200.233 ","216.155.200.234")

selCriteria = sIPAddress
For i as integer = 0 to sBanned.length - 1
If sBanned(i) = selCriteria Then
BannedIP = True
exit for
end if
Next
End for

End Function
</script>
#########################################

And the sever tells me:
Name 'selCriteria' is not declared.

I was under the impression selCriteria was a built-in function...
No?

So, I add:
Dim selCriteria As String

Good! Good!
SH*T

Error: 'End' statement not valid.

Something out of order. Let's get rid of the "end for" since we
al;ready have "exit for"

and...
and...
something is happening!
Lookslike it might be working.

I'll get back to you after I plkug my oen IP in there and see what
happens.

Keep your fingers crossed!
:-)
TIA
AGAIN!
:-)
Friday

--
#####################################
"The people cannot be all, & always well informed. The part which is wrong will
be discontented in proportion to the importance of the facts they misconceive.
If they remain quiet under such misconceptions it is a lethargy, the forerunner
of death to the public liberty. What country before ever existed a century & a
half without a rebellion? & what country can preserve it's liberties if their
rulers are not warned from time to time that their people preserve the spirit
of resistance? Let them take arms... The tree of liberty must be refreshed from
time to time with the blood of patriots & tyrants"
-- Thomas Jefferson
#####################################
Nov 19 '05 #21
This works for me:

Module Module1
Sub Main()
Dim sBan As String() = {"one", "two", "three"}
For Each s As String In sBan
Console.WriteLine(s)
Next
End Sub
End Module
-Brock
DevelopMentor
http://staff.develop.com/ballen
In article <66**********************@msnews.microsoft.com>, Brock
Allen <ba****@NOSPAMdevelop.com> wrote:
Dim sBan as String() = {...}

-Brock
DevelopMentor
http://staff.develop.com/ballen

Thanks Brock. That seems to be the concensus of the proper way to do
it.
Still... I'm now getting an error "expecting ')' "
Where in the world it wants a ')' is beyond me.
There are no open parenthesis. (Then again, this isn't perl, is it
-not
that I miss Perl.)
8-P
Please see my most recent post.
Drat.


Nov 19 '05 #22
In article <69**********************@msnews.microsoft.com>, Brock Allen
<ba****@NOSPAMdevelop.com> wrote:
This works for me:

Module Module1
Sub Main()
Dim sBan As String() = {"one", "two", "three"}
For Each s As String In sBan
Console.WriteLine(s)
Next
End Sub
End Module
-Brock
DevelopMentor
http://staff.develop.com/ballen

Yep! Dead on.
It wants "{" and NOT "("
Fussy little thing.
Thanks Again
Friday

--
#####################################
"The people cannot be all, & always well informed. The part which is wrong will
be discontented in proportion to the importance of the facts they misconceive.
If they remain quiet under such misconceptions it is a lethargy, the forerunner
of death to the public liberty. What country before ever existed a century & a
half without a rebellion? & what country can preserve it's liberties if their
rulers are not warned from time to time that their people preserve the spirit
of resistance? Let them take arms... The tree of liberty must be refreshed from
time to time with the blood of patriots & tyrants"
-- Thomas Jefferson
#####################################
Nov 19 '05 #23
In article <09***********************@nowhere.org>, Friday
<fr****@nowhere.org> wrote:

<GREAT BIF SNIP>
And the sever tells me:
Name 'selCriteria' is not declared. So, I add:
Dim selCriteria As String
selCriteria = sIPAddress Good! Good!
SH*T

Error: 'End' statement not valid.

Something out of order. Let's get rid of the "end for" since we
already have "exit for"

and...
and...
something is happening!
Lookslike it might be working.

I'll get back to you after I plkug my oen IP in there and see what
happens.

Keep your fingers crossed!
:-)


OK, it works after a little fine-tuning.
Survey says:
###############################
Dim sBanned() As String =
{"216.239.39.5","216.239.37.5","216.239.37.104","6 9.202.123.157"}

' My IP for testing is: "69.202.123.157",

Dim selCriteria as String
selCriteria = sIPAddress
For i as integer = 0 to sBanned.length - 1
If sBanned(i) = selCriteria Then
BannedIP = True
exit for
Else
BannedIP = FALSE
end if
Next
End Function
###############################

NOW THEN....

One final lesson I need to learn in my little experiment.

Suppose I want to include someone with a dynamic IP from
"69.202.123.*",
So I want to match IPs against the entire C-block: "69.202.123."...
Without too much convolution, how do I tell the above function to check
for that?
Or do I simply make the last entry in my array "69.202.123"?
With or without the final "."?
With or without a wildcard?

In PHP, I do it like this (note the last two enties in array):

$Banned = "^216.239.39.5|^216.239.37.8|^216.239.37|^69.202.1 23";

Thanks again for everyone's help and TIA once again.
:-)
Friday

--
#####################################
"The people cannot be all, & always well informed. The part which is wrong will
be discontented in proportion to the importance of the facts they misconceive.
If they remain quiet under such misconceptions it is a lethargy, the forerunner
of death to the public liberty. What country before ever existed a century & a
half without a rebellion? & what country can preserve it's liberties if their
rulers are not warned from time to time that their people preserve the spirit
of resistance? Let them take arms... The tree of liberty must be refreshed from
time to time with the blood of patriots & tyrants"
-- Thomas Jefferson
#####################################
Nov 19 '05 #24
Friday <fr****@nowhere.org> wrote:
How exactly would I use time-saver? i.e.: where and how would I define
the strings contained within the array (array variable?)?

Just as shown above?
Then simply replace the "IF" statement with your examle?


Yup:

If Array.IndexOf(sBanned, selCriteria) = -1 Then
.... do stuff you want to do when it's not found ...
Else
.... do stuff you want to do when it's found ...
End If

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 19 '05 #25
Friday,

It seems that we all had sht in our eyes.
Dim sBanned() As String = {"69.202.123.157", "216.239.39.5",
"216.239.37.5", "216.239.37.104", "216.155.200.231", "216.155.200.232",
"216.155.200.233", "216.155.200.234"}

( = {
) = }

:-)

I hope this helps,

Cor
Nov 19 '05 #26
Friday <fr****@nowhere.org> wrote:
OK! Now I'm getting somewhere.
When I replace the () in the array with containers {}, the compiler
gets happy.
:-)
(WTF?! Oh well.)


<snip>

At this stage, I would *seriously* give up on just experimenting within
ASPX. It's really not a good way of learning any language unless you
already have a reasonably solid foundation and are just checking one
particular aspect - and even then I'd check the spec afterwards.

I suggest you start learning VB.NET (or C#) with small console apps,
and when you're happy with the language itself without the ASP.NET
adornments, *then* move on to web apps.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 19 '05 #27
In article <MP************************@msnews.microsoft.com >, Jon Skeet
[C# MVP] <sk***@pobox.com> wrote:
Friday <fr****@nowhere.org> wrote:
OK! Now I'm getting somewhere.
When I replace the () in the array with containers {}, the compiler
gets happy.
:-)
(WTF?! Oh well.)


<snip>

At this stage, I would *seriously* give up on just experimenting within
ASPX. It's really not a good way of learning any language unless you
already have a reasonably solid foundation and are just checking one
particular aspect - and even then I'd check the spec afterwards.

I suggest you start learning VB.NET (or C#) with small console apps,
and when you're happy with the language itself without the ASP.NET
adornments, *then* move on to web apps.


Thanks Jon,

Iunderstand, and agree with your reasoning 100%. One day, time
permitting, I would like to learn this intriguing and powerful language
more thoroughly.

What I'm striving to do at this point, is to convert a series of PHP
scripts I make my living with to work for a client who recently
migrated to IIS. The rest Ive researched (along with the basics), but
this one small part has become a sticking point.
Thanks to the help of all the knowledgeable and helpful folks here,
however, I'm 99% there.

Thanks Again and Have a GREAT Day (Week, Year, and Beyond),
:-)
Sincerely,
Friday

--
#####################################
"The people cannot be all, & always well informed. The part which is wrong will
be discontented in proportion to the importance of the facts they misconceive.
If they remain quiet under such misconceptions it is a lethargy, the forerunner
of death to the public liberty. What country before ever existed a century & a
half without a rebellion? & what country can preserve it's liberties if their
rulers are not warned from time to time that their people preserve the spirit
of resistance? Let them take arms... The tree of liberty must be refreshed from
time to time with the blood of patriots & tyrants"
-- Thomas Jefferson
#####################################
Nov 19 '05 #28
In article <On**************@TK2MSFTNGP14.phx.gbl>, Cor Ligthert
<no************@planet.nl> wrote:
Friday,

It seems that we all had sht in our eyes.
Dim sBanned() As String = {"69.202.123.157", "216.239.39.5",
"216.239.37.5", "216.239.37.104", "216.155.200.231", "216.155.200.232",
"216.155.200.233", "216.155.200.234"}

( = {
) = }

:-)

I hope this helps,

Cor

THat was indeed the problem, Cor.
The only way I caught it was that I noticed than an earlier poster had
used the '{' indstead of the '(' So I tried it, not really expecting it
to make a diofference, but whether working on a car that stalls, or
programming, I always look to the seemingly insiognificant ("Stupid" if
you will) little things first. Or at least I try to make a practice of
that.
:-)
Odd thing that it would make the difference.
But MS never was much for adhering to time-honored standards, were they?
;-)
Thanks Again for Taking the Time to Help,
Friday

--
#####################################
"The people cannot be all, & always well informed. The part which is wrong will
be discontented in proportion to the importance of the facts they misconceive.
If they remain quiet under such misconceptions it is a lethargy, the forerunner
of death to the public liberty. What country before ever existed a century & a
half without a rebellion? & what country can preserve it's liberties if their
rulers are not warned from time to time that their people preserve the spirit
of resistance? Let them take arms... The tree of liberty must be refreshed from
time to time with the blood of patriots & tyrants"
-- Thomas Jefferson
#####################################
Nov 19 '05 #29
In article <MP************************@msnews.microsoft.com >, Jon Skeet
[C# MVP] <sk***@pobox.com> wrote:
Friday <fr****@nowhere.org> wrote:
OK! Now I'm getting somewhere.
When I replace the () in the array with containers {}, the compiler
gets happy.
:-)
(WTF?! Oh well.)


<snip>

At this stage, I would *seriously* give up on just experimenting within
ASPX. It's really not a good way of learning any language unless you
already have a reasonably solid foundation and are just checking one
particular aspect - and even then I'd check the spec afterwards.

I suggest you start learning VB.NET (or C#) with small console apps,
and when you're happy with the language itself without the ASP.NET
adornments, *then* move on to web apps.


Which would you recomnmend?
VB or C#
Or does it depend upon which language the site is built around?

Thx Agn
Friday

--
#####################################
"The people cannot be all, & always well informed. The part which is wrong will
be discontented in proportion to the importance of the facts they misconceive.
If they remain quiet under such misconceptions it is a lethargy, the forerunner
of death to the public liberty. What country before ever existed a century & a
half without a rebellion? & what country can preserve it's liberties if their
rulers are not warned from time to time that their people preserve the spirit
of resistance? Let them take arms... The tree of liberty must be refreshed from
time to time with the blood of patriots & tyrants"
-- Thomas Jefferson
#####################################
Nov 19 '05 #30
In article <MP***********************@msnews.microsoft.com> , Jon Skeet
[C# MVP] <sk***@pobox.com> wrote:
Cor Ligthert <no************@planet.nl> wrote:
I never use the notation from you. I use for Net1.1

Dim sBanned() As String =
("69.202.123.157","216.239.39.5","216.239.37.5","2 16.239.37.104","2
16.155.200.231","216.155.200.232","216.155.200.233 ","216.155.200.234")
For i as integer = 0 to sBanned.length - 1
If sBanned(i) = selCriteria Then
BannedIP = True
Else
BannedIP = False
End Function


Just to find an element within an array, I'd suggest using
Array.IndexOf. (In this case, Array.IndexOf(sBanned, selCriteria).) If
the return value is -1, the element isn't found. Otherwise, it is.


Excelent Jon!
Fewer lines of code is GOOD.

This works well for my intended application:
##########################
function BannedIP(sIPAddress As String) As Boolean

Dim selCriteria as String
selCriteria = sIPAddress

Dim sBanned() As String =
{"68.142.230.181","66.228.164.108","202.165.98.144 "}

If Array.IndexOf(sBanned, selCriteria) > -1 Then
IsMember = True
End If

End Function
##################################
Very tight.

Seems I don't even need the "Else = False"
Or would it be considered bad protocall to leave that out?

Many Thx
Friday

--
#####################################
"The people cannot be all, & always well informed. The part which is wrong will
be discontented in proportion to the importance of the facts they misconceive.
If they remain quiet under such misconceptions it is a lethargy, the forerunner
of death to the public liberty. What country before ever existed a century & a
half without a rebellion? & what country can preserve it's liberties if their
rulers are not warned from time to time that their people preserve the spirit
of resistance? Let them take arms... The tree of liberty must be refreshed from
time to time with the blood of patriots & tyrants"
-- Thomas Jefferson
#####################################
Nov 19 '05 #31
Friday <fr****@nowhere.org> wrote:
I suggest you start learning VB.NET (or C#) with small console apps,
and when you're happy with the language itself without the ASP.NET
adornments, *then* move on to web apps.


Which would you recomnmend?
VB or C#
Or does it depend upon which language the site is built around?


Personally I'd recommend C# as having a cleaner syntax and less baggage
from the past. Certainly if you're not familiar with VB to start with,
C# is the more natural choice for most people.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 19 '05 #32
Friday <fr****@nowhere.org> wrote:
This works well for my intended application:
##########################
function BannedIP(sIPAddress As String) As Boolean

Dim selCriteria as String
selCriteria = sIPAddress

Dim sBanned() As String =
{"68.142.230.181","66.228.164.108","202.165.98.144 "}

If Array.IndexOf(sBanned, selCriteria) > -1 Then
IsMember = True
End If

End Function
##################################
Very tight.

Seems I don't even need the "Else = False"
Or would it be considered bad protocall to leave that out?


I'm afraid I don't know what VB does in terms of unspecified function
return values.

However, you could just change it to:

IsMember = (Array.IndexOf(sBanned, selCriteria) > -1)

Or at least, you could in C# and I assume you can in VB.NET...

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 19 '05 #33

"Jon Skeet [C# MVP]"
However, you could just change it to:

IsMember = (Array.IndexOf(sBanned, selCriteria) > -1)

Or at least, you could in C# and I assume you can in VB.NET...


Function BannedIP(ByVal sIPAddress As String) As Boolean
Dim sBanned() As String = {"68.142.230.181", _
"66.228.164.108", "202.165.98.144"}
Return (Array.IndexOf(sBanned, sIPAddress) > -1)
End Function

I don't know if it goes still shorter.

Cor
Nov 19 '05 #34
In article <MP************************@msnews.microsoft.com >, Jon Skeet
[C# MVP] <sk***@pobox.com> wrote:
Friday <fr****@nowhere.org> wrote:
This works well for my intended application:
##########################
function BannedIP(sIPAddress As String) As Boolean

Dim selCriteria as String
selCriteria = sIPAddress

Dim sBanned() As String =
{"68.142.230.181","66.228.164.108","202.165.98.144 "}

If Array.IndexOf(sBanned, selCriteria) > -1 Then
IsMember = True
End If

End Function
##################################
Very tight.

Seems I don't even need the "Else = False"
Or would it be considered bad protocall to leave that out?


I'm afraid I don't know what VB does in terms of unspecified function
return values.

However, you could just change it to:

IsMember = (Array.IndexOf(sBanned, selCriteria) > -1)

Or at least, you could in C# and I assume you can in VB.NET...


Hmmm.... nice.

--
#####################################
"The people cannot be all, & always well informed. The part which is wrong will
be discontented in proportion to the importance of the facts they misconceive.
If they remain quiet under such misconceptions it is a lethargy, the forerunner
of death to the public liberty. What country before ever existed a century & a
half without a rebellion? & what country can preserve it's liberties if their
rulers are not warned from time to time that their people preserve the spirit
of resistance? Let them take arms... The tree of liberty must be refreshed from
time to time with the blood of patriots & tyrants"
-- Thomas Jefferson
#####################################
Nov 19 '05 #35

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

29
by: Friday | last post by:
Sorry if this is the wrong group. I tried to find the one I thought would be most relevant. I'm an old PHP guy, who knows little about asp and NOTHING about asp.net, but need to learn at least...
6
by: JNY | last post by:
Hello, Is it possible to declare an array with variable indeces? i.e. int x = 4; int myArray; for (j = 0;j < 5;j++) {
4
by: Peter Duniho | last post by:
On Thu, 14 Aug 2008 18:56:00 -0700, Phill <Phill@discussions.microsoft.comwrote: For future reference, if you are asking for help with an error (compile or execution), you really should post...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.