Arrays are one of the basics of programming. We can create lots of things via arrays like matrices, databases, tables… Let’s make it shorter and start.
Array() Function in ASP
We define our arrays using the Array() function. We can store values with two different ways. We can create the array and put values in array at the same time, or we can create the array then we can initialize the values. For getting the values from arrays we have to know position of value in array. For example; second value of array, third value of array, 56th value of array etc. There is very important point that you have to know: Array() function is zero based. That mean’s first value of array is the 0th element of array.
1.1) Fixed Size Arrays
It’s better to use this usage, if you know exactly number of elements which will be used, because the compiler will know the size of array and make the processes faster.
Example 1.0: Creating the array and initializing the values at the same time.
1 2 3 4 5 6 7 8 9
| < %
dim my_array
my_array=Array("First","Second","Third","Fourth")
Response.Write "my_array(0) : "&my_array(0)&"<br/>"
Response.Write "my_array(1) : "&my_array(1)&"<br />"
Response.Write "my_array(2) : "&my_array(2)&"<br />"
Response.Write "my_array(3) : "&my_array(3)
%> |
Output of Example 1.0:
1 2 3 4
| my_array(0) : First
my_array(1) : Second
my_array(2) : Third
my_array(3) : Fourth |
This is a fixed array that includes only 4 elements that you define. You can not add another element in this array. Also, Click to Read Complete Article »
Functions are generally used to perform same operations, or compute equations. For example, suppose that you need to get an average of some numbers. What do you have to do? Are you going to write the equations all the time? A good programmer has to find the shortest way to do works. So, if we always need to get average of numbers, we write a function that evaluates average of numbers instead of writing equations for each operation. That’s why, we need functions, and that’s why you have to know how to use functions.
A function works in two different ways. It can return a value or it can do just operations. If the function makes only operations, doesn’t return a value then it is called void function, else it is called avoid function.
We use function procedure to create functions in ASP.
1.1 ) Making Avoid Functions in ASP
Structure 1.0: Structure of an avoid function in ASP
1 2 3 4 5 6 7 8 9
| < %
function FunctionName( arguments )
'…
'Operations
'…
FunctionName=value
end function
%> |
Click to Read Complete Article »
One of the most disturbing problems of webmasters is users which have no idea about typing a sentence. It’s should be so difficult for website owner’s to see, some silly sentences typed incorrectly on their well-designed and good-looking websites. As we all know each word of titles, names and surnames or the first letter of a sentence ALWAYS start with an uppercase letter. Unfortunately there is no such rule in caveman literature. They write the first letters of sentences or their first letter of their names small. However, you don’t need to get angry anymore. There is a little solution for these cavemen. We are going to write a function that will change first letters of each word in a sentence or the first letter of a sentence. It means, we will set the cavemen’s sentences in a correct sentence format. Also, we can convert the first letter of lines to uppercase. This can be useful when you write a poem, lyric or something like that. Let’s begin.
Firstly, there is our UppercaseTheFirstLetter() function then we will clarify it with examples.
Function 1.0: No Cavemen No Cry
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
| < %
function UppercaseTheFirstLetter(string, object)
if object=0 Then 'if first letter of words in sentence must be uppercased.
splitby = " "
elseif object=1 Then 'if first letter of sentence must be uppercased.
splitby = "."
elseif object=2 Then 'if first letter of a new line must be uppercased. (ie: poem, lyric etc.)
splitby = "<br>"
end if
'These keywords can be changed or added manually.
string=trim(string) 'we removed unnecessary spaces at the beginning and ending of string.
parts = Split(string,splitby) 'string is split by our intercept criteria.
'parts is an array that contains each piece of divided string.
for fi=0 to uBound(parts) 'loop 0 to size of parts array.
the_part=trim(parts(fi)) 'we removed extra spaces at the beginning and ending of part.
if len(the_part)>0 Then 'if the part is not null or not space.
uppercased = ucase(mid(the_part,1,1))&mid(the_part,2,len(the_part)-1)
'The first letter of the_part is taken and converted to uppercase,
'Rest of the_part is added at the end of the letter.
if fi>0 then output=output&splitby&uppercased else output=uppercased'string is gathered again.
end if
next
UppercaseTheFirstLetter=output
end function
%> |
Click to Read Complete Article »
Using databases gives us lots of advantages. Listing and paging our records dynamically is one of them. In our applications, we may need to show so many records to user and in order to make it clear we have to list them well-arranged. However, listing too many database records in one time can be a handicap for us, because if the number of records reaches the huge values, then loading pages takes long time. So, we should separate records to pages. It means that in respect of number of database records, pages will be created automatically and a specified number of records will be shown on each page.
We have to know some paging and listing statements to do this issue. There are some paging and listing statements which will be used in this article.
Paging Statements
- PageSize is used to define limit number of records which will be shown in each page.
- AbsolutePage is used to determine the page selected.
- PageCount is used to get number of pages created automatically.
Listing Statements
- Move(X) is used to get Xth record from current record.
- MoveNext is used to get the next record.
- MovePrevious is used to get the previous record.
- MoveLast is used to get the last record.
- MoveFirst is used to get the first record.
There is also RecordCount statement for getting number total records Click to Read Complete Article »
1.1) MSSQL ( Microsoft SQL Server ) Connection in ASP
Sturcture 1.1:
1 2 3 4
| < %
Set ConnectionName=Server.CreateObject("Adodb.Connection")
ConnectionName.Open "driver={SQL Server};server=MyHost;uid=MyLogin;pwd=MyPassword;database=MyDatabaseName"
%> |
You can determine the server, uid, pwd and database variables as you need.
Example 1.1:
1 2 3 4
| < %
Set MyConn=Server.CreateObject("Adodb.Connection")
MyConn.Open "driver={SQL Server};server=127.0.0.1;uid=memisologin;pwd=memiso;database=memisodb"
%> |
1.2) MDB ( Microsoft Access Database ) Connection in ASP
Click to Read Complete Article »
Generating random numbers is very important in programming. We have to use random numbers to show a random record (Image, Saying, Article etc.) on our pages. Also, we can use random numbers for everything that we can imagine. In this article, we will see easiness of generating random numbers with ASP.
Structure 1.0:
1 2 3 4
| < %
randomize
response.write int(rnd*MaxNumber)
%> |
Formula: 0 < = result < MaxNumber
At line 2, randomize statement is used to generate a different number for each time we call the rnd() function.
At line 3, a random number was generated between 0 and MaxNumber variable but except the MaxNumber’s value, was converted integer with int() function and was printed. Let’s make an example.
Example 1.0: This usage gives us a random number between 0 and 100 but except 100. Minimum value of generated number can be Click to Read Complete Article »
We are going to talk about doing loops with ASP. There are many different methods to make a loop with ASP and we should choose the best way. There is a list of all looping statements in asp:
I. Do … Loop Statement
II. While … Wend Statement
III. For … Next Statement
IV. For Each … Next Statement
I. Do … Loop Statement
This statement can be very useful if you don’t have or don’t know number of repetitions because it loops the operations until or while specified conditions are true.
1.1 ) Do While Conditions Are True
The While keyword repeats operations while conditions are true. We make our operations by using the while keyword after do or after loop statements. Every do statement have to be closed with loop statement.
Structure 1.0 : If we use while keyword near do statement, Click to Read Complete Article »
Recently Typed