Developers Archive for February, 2007

Convert ASCII to Binary string

Convert ASCII to Binary string Wednesday, February 28th, 2007

The  following code shows how to convert an ASCII integer to its binary string.

Public Function cBINARY(ByVal i As Integer) As String
Dim X As Long, Y As Long, bC As Byte
cBINARY = “”
X = 256
For Y = 1 To 8
     bC = 0
     X = X / 2
     If i >= X Then
     bC = 1
     i = i - X
     End If
   cBINARY = cBINARY & bC
Next Y
End Function
 
The above function returns the binary string which can be called and assigned to a string like this
strBinValue = cBINARY(AnyInteger)

Looping Through the Forms and Elements Array

Looping Through the Forms and Elements Array Wednesday, February 28th, 2007

Accessing forms and form elements in JavaScript can be accomplished several different ways. As you’ve seen from previous examples, paths to forms and form elements can be followed by the name assigned them via the html name attribute.

However, the generic array notation reference, when used in conjunction with loops, provides a convenient, easy reference to form element objects as well as a more efficient decision making control structure. Lets review: A form can be referenced by its order within the document’s flow, and form elements by their order within a the flow of a single set of opening and closing form tags. Say there are two forms on the page, the first form containing one element:

<form name=”formOne”>
<input type=”text” name=”elementOne”>
</form>

Take a look at three different ways to code the path to the first form element in the first form on a page.

document.formOne.elementOne
document.forms[0].elements[0]
document.forms[”formOne”].elements[”elementOne”]

For standards compliant browsers using the HTML attribute ID, there is yet another path:

<input type=”text” id=”elementOne”>
document.getElementById(”elementOne”)

Since CGI scripts require name/value pairs (not ID/value pairs) from forms, and for the sake of code compatibility between the painfully uneven support amongst varying browsers, these tutorials do not use the latter convention when dealing with forms and form elements.

As you can see, just as different forms on a single page can be referenced as part of the forms array, form elements can be referenced as part of the elements array. When it comes to providing easy access to form elements, array notation with numbers as element indices is the most efficient and simple reference convention.

This technique is applied most practically when performing form validation. Looping through elements allows for easy checks of empty values, names, element types and other properties and values specific to element types. The following example will loop through each element of the form, checking various properties and values. Here is the HTML form:

<form>
<input type=”text” size=”15″ value=”Hello World” name=”elmOne”>
<input type=”checkbox” name=”elmTwo” checked>
<textarea name=”elmThree”>Small textarea</textarea>
<select name=”elmFour”>
<option selected> Yellow
<option> Green
</select>
<input type=”button” onclick=”elmName()” name=”elmFive” value=”Display Names”>
<input type=”button” onclick=”elmLoop()” name=”elmSix” value=”Display Properties and Values”>
</form>

socket_create

socket_create Wednesday, February 28th, 2007

socket_create

socket_create
It creates a endpoint(socket) for communication.

Syntax:

resource socket_create ( int domain, int type, int protocol)

It creates a communication endpoint (a socket), and returns a descriptor to the socket.

The domain parameter sets the domain. Currently, AF_INET and AF_UNIX are understood.

The type parameter selects the socket type. This is one of SOCK_STREAM, SOCK_DGRAM, SOCK_SEQPACKET, SOCK_RAW, SOCK_RDM, or SOCK_PACKET.

It returns a valid socket descriptor on success, or a negative error code on failure. This code may be passed to socket_strerror() to get a textual explanation of the error.

Example:

$socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);

- Defaultly, we use this parameter for creating socket. It returns the resource $socket which is uset to connect to the host.


All material @ copyrighted by chrisranjana.com. If you want to link to this article you are welcome to do so. Unauthorized publication is strictly prohibited. This developer tutorial website contains articles by Php programmers , Software developers, Mysql programmers and asp c# programmers. This website also contains ajax tutorials and advanced mysql sql stored procedures and functions tutorials and sample codes.