| |
Code Samples
Visual Basic 6 Initial setup of file and Database by pulling from Registry and using file search class
! Setup registry or browse for files,
Public Function InitializeACCPAC()
Dim lsSearchFile As String
Dim lbstatus As Boolean
On Error GoTo err_InitializeACCPAC
lbstatus = True
' Get Registry information AR accounts files and directories
gsARPath = GetSetting(appname:="ROD", section:="ARData", Key:="path", Default:="Q:\ASP\DATA\newData\")
gsARCustomer = "Arcust'r.dat"
lsSearchFile = "Arcust'r.dat"
gsARCustomerFileName = gsARPath & gsARCustomer
If lbstatus = True Then
If StrComp(gsARCustomer, Dir(gsARCustomerFileName), 1) <> 0 Then
MsgBox gsARCustomerFileName & " was not found..." & vbCr & _
"Press any key to Search.", vbInformation, "Find File:"
lbstatus = OpenDialog(lsSearchFile)
If lbstatus = True Then
gsARPath = gsPath
' Save information in Registry
SaveSetting appname:="ROD", section:="ARData", Key:="path", setting:=gsARPath
gsARCustomerFileName = gsARPath & gsARCustomer
End If
End If
End If
gsARGlobal = "Arglob.dat"
lsSearchFile = "Arglob.dat"
gsARGlobalFileName = gsARPath & gsARGlobal
If lbstatus = True Then
If StrComp(gsARGlobal, Dir(gsARGlobalFileName), 1) <> 0 Then
MsgBox gsARGlobalFileName & " was not found..." & vbCr & _
"Press any key to Search.", vbInformation, "Find File:"
lbstatus = OpenDialog(lsSearchFile)
If lbstatus = True Then
gsARPath = gsPath
' Save information in Registry
SaveSetting appname:="ROD", section:="ARData", Key:="path", setting:=gsARPath
gsARGlobalFileName = gsARPath & gsARGlobal
End If
End If
End If
exit_InitializeACCPAC:
InitializeACCPAC = lbstatus
Exit Function
err_InitializeACCPAC:
ShowErrMsg ("InitializeACCPAC")
lbstatus = False
Resume exit_InitializeACCPAC
End Function
Visual Basic Connect to a Database and select/group using ADO technology
' Passes parameters to MS SQL 200 Database
Public Function CompanyConfigurationGET(typCmpConf As CompanyConfiguration) As Boolean
Dim rs1 As ADODB.Recordset
Dim objCmd As ADODB.Command
Dim bolCompltete As Boolean
On Error GoTo Err_CompanyConfigurationGET
CompanyConfigurationGET = False
bolCompltete = False
Set rs1 = New ADODB.Recordset
Set objCmd = New ADODB.Command
' objConn.Open gstrConnection
With objCmd
.ActiveConnection = gstrConnection
.CommandText = "RECompanyConfigurationGET"
.CommandType = adCmdStoredProc
.Parameters.Append .CreateParameter("@intCompanyCode", adInteger, adParamInput, , typCmpConf.CompanyCode)
End With
Do While 1
With rs1
.CursorLocation = adUseClient
.Open objCmd, , adOpenStatic, adLockReadOnly
If .BOF = False Or .EOF = False Then
.MoveLast
typCmpConf.CompanyCode = ![CompanyCode]
typCmpConf.CompanyString = ![CompanyName]
typCmpConf.InitialLetterLocation = ![InitialLetterLocation]
typCmpConf.FollowupLetterLocation = ![FollowupLetterLocation]
typCmpConf.ExpiryLetterLocation = ![ExpiryLetterLocation]
CompanyConfigurationGET = True
Exit Do
Else
If bolCompltete = True Then Exit Do 'Catch any infinite loops (???)
.Close
With typCmpConf
If .CompanyCode > 0 Then
.CompanyString = ""
.InitialLetterLocation = ""
.FollowupLetterLocation = ""
.ExpiryLetterLocation = ""
' Populate the company configuration 'type' collection
CompanyConfigurationDefault typCmpConf
If CompanyConfigurationSET(typCmpConf, True) = False Then Exit Do
bolCompltete = True
End If
End With
End If
End With
Loop
Exit_CompanyConfigurationGET:
On Error Resume Next
Set rs1 = Nothing
Set objCmd = Nothing
Exit Function
Err_CompanyConfigurationGET:
ShowErrMsg "CompanyConfigurationGET"
Resume Exit_CompanyConfigurationGET
End Function
Cold Fusion Connect to a Database and select/group
<cfquery name="artistlist"
datasource="#internal.dsn_datasource#"
username="#internal.dsn_username#"
password="#internal.dsn_password#">
select art.id, art.firstname, art.middlename,
art.lastname, count(ap.id) as picture_count
from artist as art
left join artpiece as ap on ap.artist_id = art.id
left join artimage as ai1 on ai1.id = ap.fullsize_id
left join artimage as ai2 on ai2.id = ap.preview_id
group by art.id
order by lastname, firstname
limit #Val(page_start_row)#, #Val(page_maximum)#
</cfquery>
<cfquery name="num_rec"
datasource="#internal.dsn_datasource#"
username="#internal.dsn_username#"
password="#internal.dsn_password#">
select count(art.id) as num_products from artist as art
</cfquery>
<cfset pc_totalpages=Ceiling( num_rec.num_products / page_maximum )>
PHP Connect to a Database and select/group
if (isset($submit) or $processd = 0) {
$processed = 1;
# Include all the default database and table names
include '../include/affiliatetable.php';
# Include file contents...
# $tablename1 = "result";
# $dbname = "affiliate";
# $hostname = "localhost";
# $username = "root";
# ...............................................................
# Connect to database and table(s). Basic connection.
# ...............................................................
$connect = mysql_connect($hostname,$username) or die("Could not connect");
$result_set = mysql_select_db($dbname,$connect);
# check for errors
if mysql_errno() > 0;
{
echo mysql_errno()." : " . mysql_error() . "<br />";
} else {
# Get a complete list of products for selecting.
# Should not have to be reviewed more than once
# per session.
$sql = "INSERT INTO $tablename2
(admin_email, admin_name, password, fileprefix, anumprefix, initialanum, allow_self_modify,
anotifydealer, anotify, auto_sponsor_notify, store_card, email_card, taxshipping, security,
log_hits, pages_to_log, mlm, evel1, level2, level3, level4)
VALUES
('$admin_email', '$admin_name', '$password', '$fileprefix', '$anumprefix', '$initialanum',
'$allow_self_modify', '$anotifydealer', '$anotify', '$auto_sponsor_notify', '$store_card',
'$email_card', '$taxshipping', '$security', '$log_hits', '$pages_to_log', '$mlm', '$evel1',
'$level2', '$level3', '$level4')";
if ($sql != ""){
$processed = 0;
$sendupdate = mysql_query($sql);
if mysql_errno() > 0;
{
header("Location: confirm.htm");
}
}
}
} else {
$processed = 0
}
ASP Connect to a Database and select/group
<%
Dim dbConnection
Dim dbConnectionString
Dim rsRecordset
Dim strSQL
Dim strMessage
Dim intCounter
intCounter = 1
'create an ADO connection object
Set dbConnection=Server.CreateObject("ADODB.Connection")
'define connection string, specify database driver and location of the database
dbConnectionString = "Provider=SQLOLEDB; Data Source=dbaServer; Initial Catalog=dba1; User ID=user_name; Password=pass_word"
'open the connection to the database
dbConnection.Open dbConnectionString
'create an ADO recordset object
Set rsRecordset=Server.CreateObject("ADODB.Recordset")
strSQL="select * from accountspage" & _
"where accountspage.active = true"
' Populate recordset given the database, SQL request and matching records
rsRecordset.Open strSQL, dbConnection
' Only proceed if we have records to display
If not rsRecordset.EOF Then
' Write out the page header
Response.write "<tr valign='bottom'>" &_
"<td bgcolor='#7479b6' valign='middle' width='35%'><b>Shareholder</b></td>" &_
"<td bgcolor='#7479b6' valign='middle' width='25%'><b>Country/State</b></td>" &_
"</tr>"
' if there are records then loop through the rows
Do While NOT rsRecordset.Eof
' Alternate background colours
If intCounter mod 2 = 0 then
strColour = "#d0dde1"
else
strColour = "#c8c8d5"
end if
' Loop through the database and assemble each line for web page display.
strMessage = "<tr valign='bottom'><td bgcolor=" & strColour &_
" valign='middle' width='35%'>" & rsRecordset("Lastname") &_
", " & rsRecordset("FirstName") & "</td>" &_
"<td bgcolor=" & strColour & " valign='middle' width='25%'>" &_
rsRecordset("Country") & "</td></tr>"
' Write the current row out to the page
Response.write strMessage
' Increment colour toggle and proceed to next record
intCounter = intCounter + 1
rs Recordset.MoveNext
Loop
End If
' Clean up Recordset and database connection
rsRecordset.Close
Set rsRecordset=Nothing
dbConnection.Close
Set dbConnection=Nothing
%>
ASPX Connect to a Database and populate a datagrid
' This is one part of the web page. There is also a actual web page and web config file.
' Standard declaration set
Imports System
Imports System.Web
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Data
Imports System.Data.SqlClient
Imports System.Configuration
Public Class ConnString : Inherits Page
Protected dbGrid01 As DataGrid
Protected Sub Page_Load(ByVal Sender As Object, ByVal E As EventArgs)
Dim dbConn As SqlConnection
Dim dbCmd As SqlCommand
Dim strConnection As String
Try
' Get connection string from Web.Config. The connections string may
' look like: 'server=MyServer;database=MyDatabase;uid=MyUser;password=MyPassword;'
strConnection = ConfigurationSettings.AppSettings("ConnectionString01")
' Set parameters for data source
dbConn = New SqlConnection(strConnection)
' Set up a command SQL string to retrieve specific data
dbCmd = New SqlCommand("SELECT * FROM Customers " _
& "WHERE debit > 0", dbConn)
' Now retrieve the data
dbConn.Open()
' Connect the retrieved data to the datagrid source
dbGrid01.DataSource = dbCmd.ExecuteReader()
' Bind that data source
dbGrid01.DataBind()
Catch ex As Exception
' In the event of an issue display the error
Response.Write(ex.ToString & "<br>")
Finally
' Close the connection to the data source
dbConn.Close()
End Try
End Sub
End Class
JavaScript Hide and Show parts of a web page
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Hide Show Code Sample</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script type="text/javascript">
<!--
function ShowHide(ref)
{
var reference = document.getElementById(ref);
var but_reference = document.getElementById("but" + ref);
if (reference.style.display =='none')
{
but_reference.innerHTML = 'Hide';
reference.style.display ='';
}
else
{
but_reference.innerHTML = 'Show';
reference.style.display ='none';
}
}
//-->
</script>
</head>
<body>
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr>
<td>
<a href="#" id="butShowHide10" onclick="ShowHide('ShowHide10');">Show</a> item 10
</td>
</tr>
<tr>
<td id="ShowHide10" style="display: none;">
<br />
The hidden information Item 10
<br /><br />
</td>
</tr>
<tr>
<td>
<a href="#" id="butShowHide11" onclick="ShowHide('ShowHide11');">Show</a> item 11
</td>
</tr>
<tr>
<td id="ShowHide11" style="display: none;">
<br />
The hidden information Item 11
<br /><br />
</td>
</tr>
</table>
</body>
</html>
Clarion Get from flat base file
! GET INFORMATION FROM ACCPAC DATA FILE
GETACCPAC PROCEDURE
SCREEN SCREEN WINDOW(9,34),AT(9,24),PRE(SCR),HUE(7,1)
ROW(2,3) STRING('ÉÍ{28}»')
ROW(3,3) REPEAT(5);STRING('º<0{28}>º') .
ROW(8,3) STRING('ÈÍ{28}¼')
ROW(4,6) STRING('Checking ACCPAC data ...'),ENH,BLK
ROW(6,6) STRING('Customer Number:')
CUSTNO COL(23) STRING(6),HUE(15,1)
.
| FILESIZE |
LONG |
!ACCPAC CUSTOMER FILE |
| ACCRECS |
LONG |
!ACCPAC RECORD COUNT |
| GLRECS |
SHORT |
!G/L RECORD COUNT |
| GOODRECS |
SHORT |
!DELETED RECORD TEST |
| DELETED |
SHORT |
!ACCPAC CUSTOMER FILE |
| FIRSTBAD |
SHORT |
!POINTER TO 1ST BAD RECORD |
| BADRECORDS |
BYTE |
!TRUE IF DELETED RECORDS |
CODE
ACFILENAME = CHE:DRIVE & CLIP(CHE:ARDATADIR) & 'ARCUST' & CHR(39) & | 'R.' & CHE:EXTENSION
OPEN(SCREEN)
OPEN(ACCPACCUS)
FILESIZE = BYTES(ACCPACCUS)
IF ERROR() THEN STOP(ERROR() & ' RO2').
SETCURSOR()
SET(ACCPACCUS)
GET(ACCPACCUS,1,2)
FIRSTBAD = VAL(APC:NUMBER) + VAL(SUB(APC:NUMBER,2,1)) * 256
FIRSTBAD = FIRSTBAD + 1
GET(ACCPACCUS,3,2)
GOODRECS = VAL(APC:NUMBER) + VAL(SUB(APC:NUMBER,2,1)) * 256
GET(ACCPACCUS,5,2)
CURECORDSIZE = VAL(APC:NUMBER) + VAL(SUB(APC:NUMBER,2,1)) * 256
IF CURECORDSIZE <> 288 THEN
STOP('Invalid Record size in ACCPAC')
.
ACCRECS = (FILESIZE-8)/CURECORDSIZE
IF ACCRECS = GOODRECS THEN
BADRECORDS = FALSE
ELSIF GOODRECS < ACCRECS THEN
BADRECORDS = TRUE
IF FIRSTBAD < 1 OR FIRSTBAD > ACCRECS THEN
STOP('First bad record pointer invalid')
. .
FREE(CUSTOMER_TBL)
LOOP COUNT# = 0 TO ACCRECS-1
POINTER# = COUNT#*CURECORDSIZE+9
GET(ACCPACCUS,POINTER#,36)
SCR:CUSTNO = APC:NUMBER
CTB:NUMBER = APC:NUMBER
IF BADRECORDS DELETED = VAL(CTB:NUMBER) + VAL(SUB(CTB:NUMBER,2,1)) * 256
IF (DELETED >= 0 AND DELETED <= ACCRECS) OR DELETED = 32767
CYCLE
. .
CTB:TBLPTR = COUNT#+1
CTB:NUMBER = LEFT(APC:NUMBER,SIZE(APC:NUMBER))
CTB:NAME = APC:NAME
POINTER# = COUNT#*CURECORDSIZE+243
GET(ACCPACCUS,POINTER#,6)
CTB:TYPE = SUB(APC:NUMBER,1,1)
IF CTB:TYPE = ' ' THEN CTB:TYPE = '?'.
ADD(CUSTOMER_TBL)
IF ERROR() THEN STOP(ERROR() & ' RO3').
.
SORT(CUSTOMER_TBL,CTB:NUMBER)
GET(CUSTOMER_TBL,1)
SET(ACCPACCUS)
RETURN

|
|