Books

This is E Book of Computer Program, and I hope that it will help you with your study and don’t forget to give the comment and click like this website. We will upload source code and other programs with Computer Science Students and the one who wants to learn Computer Program by themselves.

M-S ACCESS PROGRAMMING 

JAVA PROGRAMMING

HTML & CSS

JAVA SCRIPT

PHP & MYSQL

JOOMLA

VB.NET

C++ PROGRAMMING

ASP & VB SCRIPT

OTHER BASIC COMPUTER

How to create query form in vb6?

ere in this discussion we will be creating a very simple query form in VB6. this will help you have a very quick query on you data inside you own system. You don’t have to open you MySql query manager ang query data there. Anyway, let’s proceed….

  1. On Form Load:
  2. Private Sub Form_Load()
  3. If drvrTXT.Text = “” Then
  4. drvrTXT.Text = “MySQL ODBC 5.1 Driver”
  5. End If
  6. configLBL.caption = “[Default Config]” & vbNewLine _
  7. & “DRIVER=” & ReadIniValue(App.path & “\Config.ini”, “DEFAULT”, “DRIVER”) & vbNewLine _
  8. & “HOST=” & ReadIniValue(App.path & “\Config.ini”, “DEFAULT”, “HOST”) & vbNewLine _
  9. & “DBNAME=” & ReadIniValue(App.path & “\Config.ini”, “DEFAULT”, “DBNAME”) & vbNewLine _
  10. & “UID=” & ReadIniValue(App.path & “\Config.ini”, “DEFAULT”, “UID”) & vbNewLine _
  11. & “PWD=” & ReadIniValue(App.path & “\Config.ini”, “DEFAULT”, “PWD”)
  12. End Sub

***Connect Button Code***

  1. Private Sub testCMD_Click()
  2. Call DBConnect.testconnectDB —> [Below is the DBConnect Codes]
  3. End Sub

***DBConnect Codes (Module File)***

  1. Option Explicit
  2. Dim conn As New ADODB.Connection
  3. Dim rs As New ADODB.Recordset
  4. Dim TempUserLog As String
  5. Public Function testconnectDB()
  6. Dim conn As ADODB.Connection
  7. Set conn = New ADODB.Connection
  8. conn.connectionString = ConnectionStringModule.connectionString
  9. With conn
  10. On Error GoTo errorhandler
  11. .Open
  12. MsgBox “Connection Successful”, vbInformation + vbOKOnly, “Admin: DBConnect Module – testconnectDB”
  13. .Close
  14. End With
  15. Exit Function
  16. errorhandler:
  17. MsgBox Err.Description, vbCritical, “Admin: DBConnect Module – testconnectDB”
  18. End Function
  19. Public Sub Login()
  20. Dim conn As ADODB.Connection
  21. Set conn = New ADODB.Connection
  22. conn.connectionString = ConnectionStringModule.connectionString
  23. With conn
  24. On Error GoTo errorhandler
  25. .Open
  26. With rs
  27. .Open (“Select * from user”), conn, adOpenDynamic, adLockOptimistic
  28. .MoveFirst
  29. .Find “uname='” & frmLogIn.txtUserName & “‘”
  30. If .EOF Then
  31. If frmLogIn.txtUserName = “admin” And frmLogIn.txtPassword = “@dm1n” Then
  32. TempUserLog = frmLogIn.txtUserName
  33. With [You Menu Validate]
  34. . [You Menu Validate](0).Enabled = True
  35. . [You Menu Validate](1).Enabled = True
  36. . [You Menu Validate](2).Enabled = True
  37. . [You Menu Validate](3).Enabled = True
  38. . [You Menu Validate](4).Enabled = True
  39. . [You Menu Validate](5).Enabled = True
  40. . [You Menu Validate](6).Enabled = True
  41. . [You Menu Validate](7).Enabled = True
  42. End With
  43. .Close
  44. conn.Close
  45. [You Menu Validate].Enabled = True
  46. Unload frmLogIn
  47. Exit Sub
  48. Else
  49. ‘===============================
  50. frmLogIn.lblAccess = “Access Denied”
  51. MsgBox “Invalid Username”, vbInformation + vbOKOnly, “Admin: DBConnect Module – Login”
  52. frmLogIn.txtUserName.SetFocus
  53. SendKeys “{Home}+{End}”
  54. End If
  55. Else
  56. .Find “password='” & frmLogIn.txtPassword & “‘”
  57. If .EOF Then
  58. ‘================================
  59. frmLogIn.lblAccess = “Access Denied”
  60. MsgBox “Invalid Password”, vbInformation + vbOKOnly, “MCRP Admin: DBConnect Module – Login”
  61. frmLogIn.txtPassword.SetFocus
  62. SendKeys “{Home}+{End}”
  63. Else
  64. .Find “inactive='” & 0 & “‘”
  65. If .EOF Then
  66. MsgBox “Acount Status: Inactive”, vbInformation + vbOKOnly, “Admin: DBConnect Module – Login”
  67. Else
  68. ‘====================================
  69. frmLogIn.lblAccess = “Access Denied”
  70. ‘MsgBox “Acount Status: Active”, vbInformation + vbOKOnly, “Admin: DBConnect Module – Login”
  71. TempUserLog = frmLogIn.txtUserName
  72. Unload frmLogIn
  73. frmTip.Show
  74. End If
  75. End If
  76. End If
  77. .Close
  78. End With
  79. .Close
  80. End With
  81. Exit Sub
  82. errorhandler:
  83. MsgBox Err.Description, vbInformation + vbOKOnly, “Admin: DBConnect Module – Login: Error”
  84. End Sub
  85. Public Static Function UserLog() As String
  86. UserLog = TempUserLog
  87. End Function

***Execute Button Code***

Note: this code requires Config.ini file in your system (My own idea, customize it to fit your’s)

  1. Private Sub execCMD_Click()
  2. If MsgBox(“Overwriting default configuration is not recommended.” & vbNewLine _
  3. & ” Would you like to continue anyway?”, vbCritical + vbOKCancel, “MCRP ADMIN”) = vbOK Then
  4. WriteIniValue App.path & “\Config.ini”, “DEFAULT”, “DRIVER”, drvrTXT.Text
  5. WriteIniValue App.path & “\Config.ini”, “DEFAULT”, “HOST”, hostTXT.Text
  6. WriteIniValue App.path & “\Config.ini”, “DEFAULT”, “DBNAME”, dbnameTXT.Text
  7. WriteIniValue App.path & “\Config.ini”, “DEFAULT”, “UID”, uidTXT.Text
  8. WriteIniValue App.path & “\Config.ini”, “DEFAULT”, “PWD”, pwdTXT.Text
  9. configLBL.caption = “[Default Config]” & vbNewLine _
  10. & “DRIVER=” & ReadIniValue(App.path & “\Config.ini”, “DEFAULT”, “DRIVER”) & vbNewLine _
  11. & “HOST=” & ReadIniValue(App.path & “\Config.ini”, “DEFAULT”, “HOST”) & vbNewLine _
  12. & “DBNAME=” & ReadIniValue(App.path & “\Config.ini”, “DEFAULT”, “DBNAME”) & vbNewLine _
  13. & “UID=” & ReadIniValue(App.path & “\Config.ini”, “DEFAULT”, “UID”) & vbNewLine _
  14. & “PWD=” & ReadIniValue(App.path & “\Config.ini”, “DEFAULT”, “PWD”)
  15. End If
  16. drvrTXT.Text = “”
  17. hostTXT.Text = “”
  18. dbnameTXT.Text = “”
  19. uidTXT.Text = “”
  20. pwdTXT.Text = “”
  21. End Sub

***Start Query Button***

  1. Private Sub cmdExec_Click()
  2. Dim sqlconn As New ADODB.Recordset
  3. Dim ctrl As Integer
  4. Dim ctrl1 As Double
  5. Call ConnModule.ConnOpen
  6. With sqlconn
  7. On Error GoTo errorhandler:
  8. If .State = adStateClosed Then
  9. .Open txtquery.Text, ConnModule.conn, adOpenDynamic, adLockOptimistic
  10. End If
  11. On Error GoTo errorhandler:
  12. MsgBox “Total Rows Affected… ” & .RecordCount, vbInformation + vbOKOnly, “MCRP – SQL Query Utility”
  13. End With
  14. Set MSHFlexGrid1.DataSource = sqlconn
  15. ctrl1 = MSHFlexGrid1.Width / MSHFlexGrid1.Cols
  16. If ctrl1 < 1200 Then
  17. ctrl1 = 1200
  18. End If
  19. For ctrl = 0 To MSHFlexGrid1.Cols
  20. MSHFlexGrid1.ColWidth(ctrl) = ctrl1
  21. Next ctrl
  22. Exit Sub
  23. errorhandler:
  24. MsgBox Err.Description
  25. End Sub

Save Radio Button Value Using PHP/Mysql

http://pagead2.googlesyndication.com/simgad/8706481895840916899

This Tutorial will teach you on how to save radio button value using PHP and MySQL.

To start this tutorial let’s follow the steps below.

Creating Our Database

First we are going to create our database which stores our data.

To create a database:

1. Open PHPMyAdmin.
2. Click Databases.
3. In the “Create new database” box, type “radio”.
4. The click Create button
5. Click SQL tab and paste the following code.

  1. CREATE TABLE IF NOT EXISTS `gender` (
  2. `id` int(11) NOT NULL AUTO_INCREMENT,
  3. `gender` varchar(10) NOT NULL,
  4. PRIMARY KEY (`id`)
  5. ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=6 ;

Creating Our Form

Next step is to create a form and save it as index.php. To create a form, open your HTML code editor and paste the code below after body tag.

  1. <?php $gender=$_GET[‘gender’]; ?>
  2. <form action=”save.php” method=”post”>
  3. Select Gender:<br />
  4. <label>
  5. <?php
  6. if ($gender==’male’)
  7. {
  8. echo ‘<input name=”gender” type=”radio” value=”male” checked=”checked” />’;
  9. }
  10. if ($gender==’female’)
  11. {
  12. echo ‘<input name=”gender” type=”radio” value=”male” />’;
  13. }
  14. ?>
  15. male
  16. </label>
  17. <br />
  18. <label>
  19. <?php
  20. if ($gender==’female’)
  21. {
  22. echo ‘<input name=”gender” type=”radio” value=”female” checked=”checked” />’;
  23. }
  24. if ($gender==’male’)
  25. {
  26. echo ‘<input name=”gender” type=”radio” value=”female” />’;
  27. }
  28. ?>
  29. female
  30. </label><br />
  31. <input name=”Save” type=”submit” value=”save” />
  32. </form>

Creating our Connection

Next step is to create a database connection and save it as “connection.php”. This file is used to connect our form to our database.

  1. <?php
  2. $mysql_hostname = “localhost”;
  3. $mysql_user = “root”;
  4. $mysql_password = “”;
  5. $mysql_database = “radio”;
  6. $prefix = “”;
  7. $bd = mysql_connect($mysql_hostname, $mysql_user, $mysql_password) or die(“Could not connect database”);
  8. mysql_select_db($mysql_database, $bd) or die(“Could not select database”);
  9. ?>

Writing Our Save Script

Next step is to create our save script and save it as save.php. This code is used to save the input data to our database.

  1. <?php
  2. session_start();
  3. include(‘connection.php’);
  4. $gender=$_POST[‘gender’];
  5. mysql_query(“INSERT INTO gender(gender)VALUES(‘$gender’)”);
  6. header(“location: index.php?gender=$gender”);
  7. mysql_close($con);
  8. ?>

Programming with RFID Reader

Im back again this time i will show how to use RFID Reader in VB6 Currently im developing Loadable E-Pass System for a confidential client and i want to share some of of codes regarding RFID and VB6. These is pretty straight forward i used MSCOMM (serial library in .NET) component in order to read /write buffer connected to PC’s serial/usb port. This is done by using the oncomm() event in order to read all the buffers send by the RFID interface without using the timer control.

Private Sub Form_Load()
On Error Resume Next

' Fire Rx Event Every Two Bytes
MSComm1.RThreshold = 2

' When Inputting Data, Input 2 Bytes at a time
MSComm1.InputLen = 2

' 2400 Baud, No Parity, 8 Data Bits, 1 Stop Bit
MSComm1.Settings = "2400,N,8,1"

' Make sure DTR line is low to prevent Stamp reset
MSComm1.DTREnable = False

' Open COM1
MSComm1.CommPort = 1
MSComm1.PortOpen = True

If MSComm1.PortOpen = False Then
MsgBox "RFID not Connected!! system will shutdown!!"
End

End If

End Sub

Private Sub Form_Unload(Cancel As Integer)
If MSComm1.PortOpen = True Then
MSComm1.PortOpen = False
End If

End Sub

Private Sub MSComm1_OnComm()
Dim sData As String
Dim lHighByte As Long
Dim lLowByte As Long
Dim lByte As Long

' If Rx Event then get data and process
If MSComm1.CommEvent = comEvReceive Then
    sData = MSComm1.Input ' Get data
    lHighByte = Asc(Mid$(sData, 1, 1)) ' get 1st byte
    lLowByte = Asc(Mid$(sData, 2, 1))  ' Get 2nd byte
    lByte = JoinHighLow(lHighByte, lLowByte)

    strnumber = CStr(lByte)

    ItemDatabase.txtID = strnumber

End If
End Sub

Private Function JoinHighLow(lHigh As Long, lLow As Long) As Long
JoinHighLow = (lHigh * &H100) Or lLow
End Function

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s