• About us
  • Contact us

Wahana Press

~ build a society that likes to write and read

Wahana Press

Monthly Archives: September 2003

VB: Tambah Kontrol ke Form saat Run-Time

26 Friday Sep 2003

Posted by Immawan Buchori in Pemrogramman

≈ Leave a Comment

Tags

Contoh Script, Visual Basic

Bagaimana caranya menambahkan berbagai kontrol ke form VB pada saat program berjalan (Run-Time)?
Contoh program ini (source code) membantu anda dalam menambah kontrol ke form beserta cara cara mesetting jenis font, size, mengisi text ke dalam listbox, label, dll.

Source code ini sangat mudah untuk dipelajari, dan anda sebagai pemula programmer VB, contoh ini sangat membantu didalam menambah wawasan pemrogramman VB.

Option Explicit
'**************************************************
'
' Menambahkan Control ke Form
'
' Copyright (c) Sep 2003 by Immawan Buchori
' http://wahanapress.net
'
'**************************************************
Dim WithEvents Text1 As VB.TextBox
Dim WithEvents List1 As VB.ListBox
Dim WithEvents Label1 As VB.Label
Dim WithEvents Label2 As VB.Label
Private Sub Form_Load()
Dim i As Integer

  Form1.Caption = "Menambahkan Control ke Form Saat Run-Time"

  ' Tambahkan kontrol ListBox
  Set Label1 = Controls.Add("VB.Label", "Label1", Form1)
  Set Label2 = Controls.Add("VB.Label", "Label2", Form1)

  ' Letakkan posisi List1 dan atur tingginya
  Label1.Move 100, 100, 5500, 300
  Label2.Move 100, 500, 5500, 500

  ' Tampilkan List1
  Label1.Visible = True
  Label2.Visible = True
  Label1.FontBold = True
  Label1.FontSize = 12
  Label2.FontSize = 10
  Label2.Alignment = vbCenter
  Label1.Caption = "Wahana Bagi Pemula Programmer Indonesia"
  Label2.Caption = "Copyright (c) Sep 2003 by Wahana Press"

  ' Tambahkan kontrol ListBox
  Set List1 = Controls.Add("VB.ListBox", "List1", Form1)
  List1.Move 1500, 1000, 2500, 3000
  List1.Visible = True

  ' Tambahkan data ke List1
  For i = 1 To 25
    List1.AddItem "Ini adalah baris ke - " & i
  Next

  ' Tambahkan TextBox
  Set Text1 = Controls.Add("VB.TextBox", "txtText1", Form1)
  Text1.Move 1500, List1.Top + List1.Height + 200, 2500, 100
  Text1.Visible = True

End Sub

Private Sub List1_Click()
  Text1.Text = List1.Text
End Sub

Sebelumnya anda buatkan satu project baru (Project Standart.EXE)

new Form1

double-click Form1, setelah itu, Anda COPY source code diatas, kemudian PASTE ke dalam Form1.

Tekan F5 atau klik menu Run…

Tampilan setelah dijalankan.

Semoga berhasil.

How to Connect to SQL Server from Visual FoxPro

10 Wednesday Sep 2003

Posted by Immawan Buchori in Pemrogramman

≈ Leave a Comment

Tags

Contoh Script, Petunjuk Tehnis, Visual FoxPro

by Sayed Geneidy
Published: 24th Aug 2003
Link: sql-server-performance.com; devarticles.com

In Microsoft public newsgroups, I’ve noticed a recent increase in the number of questions that deal with how to connect from Visual Foxpro to SQL Server, and the problems related to making this connection. So I’ve decided to write this article to cover such an important topic.

There are two functions that can be used to establish a connection with the a remote SQL Server from Visual FoxPro:

  • SQLConnect()
  • SQLStringConnect()

The SQLConnect() Function

There are two ways to use the SQLConnect() function to connect to a remote data source, such as SQL Server. The first requires that you supply the name of a data source as defined in the ODBC Data Source Administrator applet of the Control Panel.

The following example creates a connection to a remote server using the ODBCNorthwind DSN:

LOCAL hConn
hConn = SQLConnect("ODBCNorthwind", "sa", "")

The second way to use SQLConnect() is to supply the name of a Visual FoxPro connection that was created using the create connection command. The CREATE CONNECTION command stores the metadata that Visual FoxPro needs to connect to a remote data source.

The following example creates a Visual FoxPro connection named Northwind and then connects to the database described by the connection:

LOCAL hConn
CREATE DATABASE cstemp
CREATE CONNECTION Northwind ;
DATASOURCE "ODBCNorthwind" ;
USERID "sa" ;
PASSWORD ""
hConn = SQLConnect("Northwind")

SQLStringConnect() Function

The other function that can be used to establish a connection to a remote data source, such as SQL Server, is SQLStringConnect(). Unlike SQLConnect(), SQLStringConnect() requires a single parameter, a string of semicolon-delimited options that describes the remote data source and optional connections settings.

The valid options are determined by the requirements of the ODBC driver. Specific requirements for each ODBC driver can be found in that ODBC driver’s documentation.

The following table lists some commonly used connection string options for SQL Server:

Option Description
DSN References an ODBC DSN.
Driver Specifies the name of the ODBC driver to use.
Server Specifies the name of the SQL Server to connect to.
UID Specifies the login ID or username.
PWD Specifies the password for the given login ID or username.
Database Specifies the initial database to connect to.
APP Specifies the name of the application making the connection.
WSID The name of the workstation making the connection.
Trusted_Connection Specifies whether the login is being validated by the Windows NT Domain.

Not all of the options listed in the above table have to be used for each connection.

For instance, if you specify the Trusted_Connection option and connect to SQL Server using NT Authentication, there is no reason to use the UID and PWD options since SQL Server would invariably ignore them. The following code demonstrates some examples of using SQLStringConnect().

Note: You can use the name of your server instead of the string.

SQL Server 2000 code example:

LOCAL hConn
hConn = SQLStringConnect("Driver=SQL Server;Server=<SQL2000>;"+ ;
        UID=sa;PWD=;Database=Northwind")
hConn = SQLStringConnect("DSN=ODBCNorthwind;UID=sa;PWD=;Database=Northwind")
hConn = SQLStringConnect("DSN=ODBCNorthwind;Database=Northwind;Trusted_Connection=Yes")

Handling Connection Errors

Both the SQLConnect() and SQLStringConnect() functions return a connection handle. If the connection is established successfully, the handle will be a positive integer. If Visual FoxPro failed to make the connection, the handle will contain a negative integer. A simple call to the AERROR() function can be used to retrieve the error number and message. The following example traps for a failed connection and displays the error number and message using the Visual FoxPro MESSAGEBOX() function.

Visual FoxPro returns error 1526 for all errors against a remote data source. The fifth element of the array returned by AERROR() contains the remote data source-specific error.

#define MB_OKBUTTON 0
#define MB_STOPSIGNICON 16
LOCAL hConn
hConn = SQLConnect("ODBCNorthwind", "falseuser", "")
IF (hConn < 0)
  LOCAL ARRAY laError[1]
  AERROR(laError)
  MESSAGEBOX( laError[2], ;
    MB_OKBUTTON + MB_STOPSIGNICON, ;
    "Error " + TRANSFORM(laError[5]))
ENDIF

Disconnecting From SQL Server

It is very important that a connection be released when it is no longer needed by the application because connections consume valuable resources on the server, and the number of connections may be limited by licensing constraints.

You break the connection to the remote data source using the SQLDisconnect() function. SQLDisconnect() takes one parameter, the connection handle created by a call to either SQLConnect() or SQLStringConnect(). SQLDisconnect() returns a 1 if the connection was correctly terminated and a negative value if an error occurred.

The following example establishes a connection to SQL Server, and then drops the connection:

LOCAL hConn,lnResult
*hConn = SQLStringConnect("Driver=SQL Server;Server=<SQL2000>;"+ ;
UID=sa;PWD=;Database=Northwind")
hConn = SQLConnect("ODBCNorthwind", "sa", "")
IF (hConn > 0)
  MESSAGEBOX("Connection has done")
  lnResult = SQLDisconnect(hConn)
  IF lnResult < 0
    MESSAGEBOX("Disconnect failed")
  ENDIF && lnResult < 0
ENDIF && hConn > 0

If the parameter supplied to SQLDisconnect() is not a valid connection handle, Visual FoxPro will return a run-time error (#1466). Currently there is no way to determine whether a connection handle is valid without attempting to use it.

To disconnect all SQL pass through connections, you can pass a value of zero to SQLDisconnect().

–xOx–

♣ Sewa Server disini “Terbaik dan Handal”

♣ e-Books

  • Databases
  • Programming

♣ Calendar

September 2003
M T W T F S S
« Jun   Oct »
1234567
891011121314
15161718192021
22232425262728
2930  

♣ Tag Cloud

Apache Asah Otak ASP Clipper Contoh Program Contoh Script DBF Facebook Fenomena Halo Hari Raya HDD Himbauan Internet Islam Isra' Mi'raj Kebiasaan Kristen Linux Macro Excel Matahari Maulid Modem Motivasi MS. Access Ms.Excel Ms. SQL my Family Pemahaman Pengalaman Pribadi Perbandingan Petunjuk Tehnis Ramadhan Sedekah Sifat Manusia Tahun Baru Themes Tips dan Trick Translate VB Application Visual Basic Visual FoxPro Windows Windows Server World Cup xHarbour

♣ Recent Posts

  • Maulid Nabi Muhammad SAW (12 Rabiul Awal)
  • Selamat Natal Menurut Al-Qur’an
  • Selamat Atas Peringatan Kelahiran Isa Al-Masih Putra Maryam
  • Menyambut 1 Muharram 1433 Hijriyah
  • Orang Pendengki Hakikatnya Telah Menyiksa Dirinya Sendiri
  • Jangan Perkuat Temanmu, Bila Suatu Saat Menjadi Musuh!
  • Selamat Hari Raya Idul Adha 1432 H
  • Selamat Hari Raya Idul Fitri 1432 H
  • Marhaban Yaa Ramadhan
  • Dahsyatnya Sedekah

♣ Recent Comments

Millati Indah on Kupas Tuntas: Fenomena “…
hamba allah on Selamat Natal Menurut Al-…
wawans on Menu “Sharing and Securit…
Immawan Buchori on Install Modem Huawei E1553 di …
mathew on Install Modem Huawei E1553 di …
Immawan Buchori on Selamat Natal Menurut Al-…
mardiantonnton on Selamat Natal Menurut Al-…
Ali on Sebuah Renungan tentang K…
Immawan Buchori on VB: Ambil Data Excel dengan DA…
travelumbroh on VB: Ambil Data Excel dengan DA…

♣ Archives

Top Posts

  • Kupas Tuntas: Fenomena "Halo" Matahari
  • VB: Cari Data dalam DataGrid
  • Menu “Sharing and Security” Hilang
  • Visual Basic 2008 Samples
  • VB: ComboBox didalam DBGrid
  • Import Database Access ke SQL Server (UpSizing)
  • Dahsyatnya Sedekah
  • VB: Round Integer (Updated)
  • Peradaban Islam: Masa Lalu Nan Cemerlang
  • VB: Control TextBox Khusus Angka

Authors

Category Cloud

Alam Database e-Book Hardware Hikayat Jejaring Sosial Keagamaan Microsoft Office Network Operating System Pemrogramman Permainan Personal Security / Anti-Virus Tools Web / Server Wordpress

Meta

  • Register
  • Log in
  • Entries RSS
  • Comments RSS
  • WordPress.com

Blog at WordPress.com. Theme: Chateau by Ignacio Ricci.