First ASP component: Setting up a server date-time component

Source: Internet
Author: User
Tags date integer time and date
Portal of server network
     
Before entering the first component we need to learn, the Tiger first has to say that because the tiger's level is limited, it may be in the following instructions
A lot of mistakes, I hope you put forward the evidence, here I hope to share with you the learning experience of ASP, the tiger's site is the original spirit, a lot of
Things are DIY, so the process of writing will be infected with the tiger itself bad programming habits. and the entire teaching site is only a small tiger maintenance, so the technology
There must be a lot of problems, I hope you understand.
ASP components for our ASP programming provides a powerful extension, such as we need to start an application in the server, set the server time,
Access to the internal operating system information, etc., can not be done by ASP. Most of them need to use their own developed ASP components to achieve, the ASP itself provides us with
A few very useful components, ADO database access Components, file input and output components, advertising rotation components and so on. But there are a lot of times when we need some special
The function.
First of all, the tiger with their most familiar with VB to do this component, everyone first in their own calculation of the chicken on the D version of the VB Bar, version does not require, but the tiger is used
VB6 's. How about starting the first step?

(i) running VB6, the system pops up a "New project" dialog box. Select an ActiveX Dll
Then you can see "Project One" and a class "Class1" in the project manager, let us want to help them to change a nice name first,
If you use this homemade component in ASP, do you use
Set Obj=server.createobject ("Engineering I. Class1")
Such a nasty name? Go ahead and change it. We renamed the Project One: Systimeset, and Class1 changed to: Timeset. That's better.
, huh? OK, start adding Code for Class Timeset, think first, VB6 itself seems to have no ability to set the system time and date of the function bar (Tiger does not remember there is no
So what can I do? Don't worry, have you heard the WIN32API function? This is Microsoft's Windows system-level function. Provides a wealth of operating system features,
Don't change the date, change the time, is to let your window restart also can. The tiger opened the thick Win32API function encyclopedia, finally found the SetSystemTime
This function, Win32API originally designed for C + + programmers to use, in VB call it must first fame, fortunately Microsoft also think very thoughtful, VB40 above version,
All with the API text browser, we run it, it is in the Start menu of the VB program group, run out of the box, from the File menu, choose to load this article
Thing Select the declaration in the WIN32API.TXT,API type, and then find the SetSystemTime in that available item, double-click it, and a piece of code
Now select the item, then the selection, the type in the API type, find SYSTEMTIME This type, also double-click it, OK click Copy,
The items that you just selected are attached to the Clipboard. By shutting down the API browser, we have enough stuff.
Now write VB code, double-click the Timeset class, add the following code to the class.
Option Explicit
Private SystemTime as SystemTime
' These are from the pasteboard, and we look at the type of systemtime, the structure in almost C + +, and just look at his eight.
Year, month, day, hour, minute ... And so on the eight items, now as long as the eight items to assign value and then call SetSystemTime this Win32API function, look at you
Server bar, the date time has been changed, if you use Win98 to do the server, try to turn it to number 26th to see if there is no cih,^0^, because this is an example
, so most of the values I have fixed values, rather than from the ASP passed the value, from the ASP passed only hour, and minute, hours and minutes, such as
If you are interested in adding a few other words, then revise the program.
Private Declare Function setsystemtime Lib "kernel32" (Lpsystemtime as SystemTime) as Long
Private Type SystemTime
Wyear as Integer
Wmonth as Integer
Wdayofweek as Integer
Wday as Integer
Whour as Integer
Wminute as Integer
Wsecond as Integer
Wmilliseconds as Integer
End Type

Dim tmp
Private M_hour as Integer
Private M_minute as Integer

' Declare the public properties of the Timeset class, such as when you created a server object with Set Obj=server.createobject ("Systimeset.timeset")
, you need to assign a value to the Timeset, that is, to specify the system time you want to set, then you have to declare the following Timeset public properties, I have a sound
Clear hour and minute, that is, only to provide changes in hours and minutes, such as you want to change the other several, then get yourself up.
Public Property Get Hour () as Integer
Hour = M_hour
End Property
Public Property Let Hour (Tmp_hour as Integer)
M_hour = Tmp_hour
End Property
Public Property Get Minute () as Integer
Minute = M_minute
End Property
Public Property Let Minute (Tmp_minute as Integer)
M_minute = Tmp_minute
End Property
With the hour and minute attributes, when you create the server object obj in ASP, you can use the

Obj. hour=10
Obj. MINUTE=10 a sample to assign a value to it, meaning that you intend to set the time to 10:10 points.

Well, finally, the public way, we sound a setup () method, as long as the call it, immediately change the time. Several other parameters I use regularly
Quantity, we can change, this does not need me to say? Should be changed will have experience, in short, can not be empty, or call the WIN32API function will fail to return 0, such as the
It was 1 and it was successful. I am here for the 1999-10-1 Day, our 50 anniversary National Day.


Public Function setup () as Integer
Systemtime.wday = 1
Systemtime.wdayofweek = 1
Systemtime.wmilliseconds = 0
Systemtime.wmonth = 10
Systemtime.wsecond = 0
Systemtime.wyear = 1999
Systemtime.whour =hour
Systemtime.wminute =minute
Setup = SetSystemTime (SystemTime)

End Function


Finally, save the project and compile the DLL, the component will be automatically registered by VB6, so we can call it immediately in ASP. We'll write a
A simple ASP program.
*test.asp
<% @language = "VBScript"%>
<%
Response. Expires=0
Set Obj=server.createobject ("Systimeset.timeset")
Obj. hour=10
Obj. minute=10
Result=obj.setup

If Result=1 Then

Response.Write "System time has been modified successfully"

Else

Response.Write "System Time Modification failed"

endif


Set obj=nothing

%>


I'm tired of doing this component and playing with so many words, the specific ASP component registration and other issues I will explain to you next time. I put ASP component source program
First pack, then we do not have to knock, directly to compile on the line, because the project is VB6 do, so need VB6 to open the compilation. If people think that Ben
Station do very good words, please for the website of the Tiger to make a recommendation and friendship Connection bar, hope that through the exchange of learning, we can progress together. such as the article reproduced Tiger, please
Note that the source, will be small tiger is spent a lot of time to knock. ~0~
The operating environment for the above components is: PWIN98+PWS4



Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.