Page 1 of 1 1
Topic Options
#57743 - 2001-07-30 11:23 AM How to use CreateObj?
Anonymous
Unregistered


Dear all,

The following script was copy from here, should be from Shawn post, using kix363, I know kix2k1 are using createobj() now. How can I get the same function on the following script?

code:
  
break on

; Everytime this script is run - it updates the
; database and displays the results...

; Create a blank database called logon.mdb
; then set the following variable as required...

$database= "y:\lanadmin\cshare\access\logon.mdb"

$dsn= "data source= $database; provider= microsoft.jet.oledb.4.0;"

; Create connection...
$connection= olecreateobject("adodb.connection")

if @error
?"mdac:adodb not insalled on this machine"
quit(0)
endif

; Set the connect string ...
$= oleputproperty($connection,"connectionstring","s","$dsn")

; Open connection ...
$= olecallfunc ($connection,"open")

; Create a table ...
$= olecallfunc($connection,"execute","s","create table logon (stamp char(50) primary key, userid char(50), wksta char(10))")

; Add a record ...
$= olecallfunc($connection,"execute","s","insert into logon (stamp,userid,wksta) values ('@time', '@userid', '@wksta')")

; Create a recordset...
$recordset= val("&"+olecallfunc($connection,"execute","s","select * from logon"))

; Get the fields...
$fields= val("&"+olegetproperty($recordset,"fields"))
$stamp= val("&"+olecallfunc($fields,"item","s","stamp"))
$userid= val("&"+olecallfunc($fields,"item","s","userid"))
$wksta=val("&"+olecallfunc($fields,"item","s","wksta"))

; Enumerate the recordset...

while olegetproperty($recordset,"eof")= "0" and @error= 0

?"stamp : " olegetproperty($stamp,"value")
?"userid : " olegetproperty($userid,"value")
?"wskta : " olegetproperty($wksta,"value")

; Next record please ...

$= olecallfunc($recordset,"movenext")

loop

?
; Closeup (important!) ...
$= olecallfunc($recordset,"close")
$= olecallfunc($connection,"close")

; Cleanup (not so important!) ...
$= olereleaseobject($stamp)
$= olereleaseobject($userid)
$= olereleaseobject($wksta)
$= olereleaseobject($fields)
$= olereleaseobject($recordset)
$= olereleaseobject($connection)

exit


The above script is to create a record using access database.

Thanks for anyone attention.

Top
#57744 - 2001-07-30 11:36 AM Re: How to use CreateObj?
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
all I know about object creation is also learned from the gurus of this BB.
like reading this topic:
K2K/IE: A postcard to Ruud
_________________________
!

download KiXnet

Top
#57745 - 2001-07-31 03:30 PM Re: How to use CreateObj?
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
Gilbert,

Here's the KiXtart 2001 version of the above script - much cleaner ...

code:

break on


; Everytime this script is run - it updates the
; database and displays the results...
; Create a blank database called logon.mdb
; then set the following variable as required...


$database = "m:\msaccess\logon.mdb"
$dsn = "data source= $database; provider= microsoft.jet.oledb.4.0;"


$connection = createobject("adodb.connection")
$connection.connectionstring = $dsn
$connection.open()
$connection.execute("create table logon (stamp char(50) primary key, userid char(50), wksta char(10))")
$connection.execute("insert into logon (stamp,userid,wksta) values ('@time', '@userid', '@wksta')")
$recordset = $connection.execute("select * from logon")


; Prefetching field handles should improve performance (but not required)


$stamp = $recordset.fields("stamp")
$userid = $recordset.fields("userid")
$wksta = $recordset.fields("wksta")


while not $recordset.eof and @error= 0


?
?"stamp : " $stamp.value
?"userid : " $userid.value
?"wskta : " $wksta.value
$recordset.movenext()


loop


$recordset.close()
$connection.close()


$stamp=0
$userid=0
$wksta=0
$recordset=0
$connection=0


exit


-Shawn

[ 31 July 2001: Message edited by: Shawn ]

Top
#57746 - 2001-07-31 07:59 PM Re: How to use CreateObj?
Anonymous
Unregistered


Thanks Shawn,

A minor question:

code:
  
$connection = createobject("adodb.connection")
$connection.connectionstring = $dsn
$connection.open()
$connection.execute("create table logon (stamp char(50) primary key, userid char(50), wksta char(10))")
$connection.execute("insert into logon (stamp,userid,wksta) values ('@time', '@userid', '@wksta')")
$recordset = $connection.execute("select * from logon")

How do I know such syntax like

$connection.execute, .open ?

Also from Microsoft Technet ADO? OLE?

Thanks a lot.

Gilbert Ng

Top
#57747 - 2001-07-31 08:05 PM Re: How to use CreateObj?
Jochen Administrator Offline
KiX Supporter
*****

Registered: 2000-03-17
Posts: 6380
Loc: Stuttgart, Germany
Gilbert,

one way is :

in any Office Application , open the VB Editor and add under tools -> references the wished library and just see what it contains in the object browser ...


hth

Jochen

_________________________



Top
#57748 - 2001-07-31 08:16 PM Re: How to use CreateObj?
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
Gilbert -

The MSDN keeps changing all the time - here's some links I just dug-up:

ADO Programmers Guide

ADO Object Model

ADO Reference

I hope the TOC's sync-up for you. Most examples are written in VB but with the KiXtart 2001 COM enhancements - that's just gravy

-Shawn

[has anyone noticed - MS is converting MSDN to ASP's and the quality and response time of queries is going down the drain]

p.s.

J was faster that time - his way is even better !!!

[ 31 July 2001: Message edited by: Shawn ]

Top
Page 1 of 1 1


Moderator:  Glenn Barnas, NTDOC, Arend_, Jochen, Radimus, Allen, ShaneEP, Ruud van Velsen, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 735 anonymous users online.
Newest Members
JimDunn, fgarcia, Viginette, ManuvdWielNL, Sir_Barrington
17890 Registered Users

Generated in 0.053 seconds in which 0.023 seconds were spent on a total of 12 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org