Saturday, September 15, 2012

SMS Sending Using AT commands

Introduction


AT commands are instructions used to control a modem. AT is the abbreviation of ATtention. Every command line starts with "AT" or "at". That's why modem commands are called AT commands.

AT commands with a GSM/GPRS MODEM or mobile phone can be used to access following information and services:
  
1.      SMS services.
2.      MMS services.
3.      Data and Voice link over mobile network
4.      Information and configuration pertaining to mobile device or MODEM and SIM card.
5.      Fax services.

Below is a sample vb.net code using AT commands in sending SMS:

1. Create a form and name it frmsms.
















2. Add 2 textbox then name it txtnumber and txtmsg.

3. Add button and name it btnsend.

4. Doubleclick the frmsms form then paste the code below:

SerialPort1.PortName = "COM16"             'set gsm modem port
SerialPort1.BaudRate = 9600                     ' set gsm modem BaudRate
SerialPort1.Parity = Parity.None
SerialPort1.StopBits = StopBits.One
SerialPort1.DataBits = 8
SerialPort1.Handshake = Handshake.RequestToSend
SerialPort1.DtrEnable = True
SerialPort1.RtsEnable = True
SerialPort1.NewLine = vbCrLf
SerialPort1.Open()

Then find the Public Class frmsms line then paste this code above it:

Imports System.IO.Ports


5. Double click the btnsend then paste the code below:


 Dim message As String
 message = txtmsg.Text

If SerialPort1.IsOpen() Then
  SerialPort1.Write("AT" & vbCrLf)
  SerialPort1.Write("AT+CMGF=1" & vbCrLf)
  SerialPort1.Write("AT+CMGS=" & Chr(34) & txtnumber.Text & Chr(34) & vbCrLf)
  SerialPort1.Write(message & Chr(26))
  MsgBox("Sent")
Else
  MsgBox("Port not available")
End If


Here is the full code:

Imports System.IO.Ports

Public Class frmsms

    Dim SerialPort1 As New System.IO.Ports.SerialPort()

    Private Sub frmsms_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        SerialPort1.PortName = "COM16"             'set gsm modem port
        SerialPort1.BaudRate = 9600                     ' set gsm modem BaudRate
        SerialPort1.Parity = Parity.None
        SerialPort1.StopBits = StopBits.One
        SerialPort1.DataBits = 8
        SerialPort1.Handshake = Handshake.RequestToSend
        SerialPort1.DtrEnable = True
        SerialPort1.RtsEnable = True
        SerialPort1.NewLine = vbCrLf
        SerialPort1.Open()

    End Sub

    Private Sub btnsend_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnsend.Click

        Dim message As String
        message = txtmsg.Text

        If SerialPort1.IsOpen() Then
            SerialPort1.Write("AT" & vbCrLf)
            SerialPort1.Write("AT+CMGF=1" & vbCrLf)
            SerialPort1.Write("AT+CMGS=" & Chr(34) & txtnumber.Text & Chr(34) & vbCrLf)
            SerialPort1.Write(message & Chr(26))
            MsgBox("Sent")
        Else
            MsgBox("Port not available")
        End If

    End Sub

If you encountered error or you can't send sms, make sure that you have a device like GSM/GPRS MODEM or mobile phone connected to your pc. Also make sure that your PortName and BaudRate  is correct.

Saturday, September 24, 2011

It's a simple insert code using php, mysql and wamp

1. First you need to create user directory inside the C:\wamp64\www.

2. Second you need to create connect.php file inside the C:\wamp64\www\user directory for your connection to your database and paste this code below:

<?php
$dbServer="localhost";
$dbUser="root";
$dbUserPwd="";
$dbName="humanresource";

$dbLink =mysql_connect($dbServer,$dbUser,$dbUserPwd) or die(mysql_error());
mysql_select_db($dbName,$dbLink);
?>


3. Third you need to create index.php file inside the C:\wamp64\www\user directory for your form and insert code. Paste this code below:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Insert record</title>
</head>
<body>
<form name="form1" method="post" action="index.php">
<table width="296" border="0" cellpadding="0" cellspacing="0">
<tbody>
<tr>
<td>Name:</td>
<td><input name="name" type="text" id="name" size="20" maxlength="10"></td>
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
<td>Address</td>
<td><input name="address" type="text" id="address" size="20" maxlength="10"></td>
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
<td><input name="submit" type="submit" id="submit" value="Save"></td>
<td>
<?php
include("connect.php");
if(isset($_POST['save']))
{
$name=$_POST['name'];
$address=$_POST['address'];
if($name=="" || $address=="")
{
echo'<font style="font-family:Tahoma;font-size:11px;color:#990000">&nbsp;&nbsp;Please input all fields</font>';
}
else
{     
$result = "INSERT INTO `tbl_test` (`name`, `address`) VALUES ('$name', '$address')" ;
$rs2 = mysql_query($result) or die("Invalid Query <br>$result");
echo'<font style="font-family:Tahoma;font-size:11px;color:#990000">&nbsp;&nbsp;Successfully inserted</font>';
}
}
?>
</td>
</tr>
</tbody>
</table>
</form>
</body>
</html>

4. Now you need to access http://localhost/user/ or it's depen on your wamp setting to your browse.




5. Now enter your name and address then clicksave button. Now open your Mysql Database to check if your data was saved.

Tuesday, August 30, 2011

GLOW CODE is a code for vb.net buttons


1. Copy paste the code to your form.

2. Find the OK.MouseLeave, Cancel.MouseLeave then replace it with the button names of your form you want to glow.


#Region "GLOW CODE"

    Private Sub MouseEnterEvent(ByVal sender As Object, ByVal e As System.EventArgs) _
        Handles OK.MouseLeave, Cancel.MouseLeave

        ' A simple event handler that fires when the user's mouse arrow rolls
        ' over any of the buttons.  It passes the button's identity to the Glow sub.

        Dim ctrl As Control = CType(sender, Control)
        Glow(ctrl, True)

    End Sub

    Private Sub MouseLeaveEvent(ByVal sender As Object, ByVal e As System.EventArgs) _
    Handles OK.MouseLeave, Cancel.MouseLeave

        ' A simple event handler that fires when the user's mouse arrow leaves the
        ' area of any of the buttons.  It passes the button's identity to the Glow sub.

        Dim ctrl As Control = CType(sender, Control)
        Glow(ctrl, False)

    End Sub

    Private Sub Glow(ByVal ctrl As Control, ByVal Hovering As Boolean)

        Dim Sb_R, Sb_G, Sb_B As Int16 '           <--- RGB values for the starting backcolor
        Dim Sf_R, Sf_G, Sf_B As Int16 '           <--- RGB values for the starting forecolor
        Dim Eb_R, Eb_G, Eb_B As Int16 '           <--- RGB values for the ending backcolor
        Dim Ef_R, Ef_G, Ef_B As Int16 '           <--- RGB values for the ending forecolor

        Select Case Hovering  ' True for MouseEnter, False for MouseLeave
            Case True
                Sb_R = SystemColors.Control.R           ' Assign the variables the
                Sb_G = SystemColors.Control.G           ' appropriate values based
                Sb_B = SystemColors.Control.B           ' on system-defined colors
                '                                         for control and control
                Sf_R = SystemColors.ControlText.R       ' text.
                Sf_G = SystemColors.ControlText.G
                Sf_B = SystemColors.ControlText.B

                Eb_R = SystemColors.ActiveCaption.R     ' Assign the variables the
                Eb_G = SystemColors.ActiveCaption.G     ' appropriate values based
                Eb_B = SystemColors.ActiveCaption.B     ' on system-defined colors
                '                                         for the title bar and the
                Ef_R = SystemColors.ActiveCaptionText.R ' title bar's text.
                Ef_G = SystemColors.ActiveCaptionText.G
                Ef_B = SystemColors.ActiveCaptionText.B
            Case False
                Sb_R = SystemColors.ActiveCaption.R     ' Assign the variables the
                Sb_G = SystemColors.ActiveCaption.G     ' appropriate values based
                Sb_B = SystemColors.ActiveCaption.B     ' on system-defined colors
                '                                         for the title bar and the
                Sf_R = SystemColors.ActiveCaptionText.R ' title bar's text.
                Sf_G = SystemColors.ActiveCaptionText.G
                Sf_B = SystemColors.ActiveCaptionText.B

                Eb_R = SystemColors.Control.R           ' Assign the variables the
                Eb_G = SystemColors.Control.G           ' appropriate values based
                Eb_B = SystemColors.Control.B           ' on system-defined colors
                '                                         for control and control
                Ef_R = SystemColors.ControlText.R       ' text.
                Ef_G = SystemColors.ControlText.G
                Ef_B = SystemColors.ControlText.B
        End Select

        Dim b_RIncrement As Int16 = Round(((Eb_R - Sb_R) / 16), 0)      ' Find the increments that
        Dim b_GIncrement As Int16 = Round(((Eb_G - Sb_G) / 16), 0)      ' the RGB values will take;
        Dim b_BIncrement As Int16 = Round(((Eb_B - Sb_B) / 16), 0)      ' 1/16th of the difference
        '                                                                 between the start and end
        Dim f_RIncrement As Int16 = Round(((Ef_R - Sf_R) / 16), 0)      ' values, rounded to the
        Dim f_GIncrement As Int16 = Round(((Ef_G - Sf_G) / 16), 0)      ' nearest integer.
        Dim f_BIncrement As Int16 = Round(((Ef_B - Sf_B) / 16), 0)

        Dim bR As Int16 = Sb_R ' \
        Dim bG As Int16 = Sb_G '  }--  the RGB values for the backcolor as it changes.
        Dim bB As Int16 = Sb_B ' /

        Dim fR As Int16 = Sf_R ' \
        Dim fG As Int16 = Sf_G '  }--  the RGB values for the forecolor as it changes.
        Dim fB As Int16 = Sf_B ' /

        Dim count As Int16
        For count = 0 To 14
            bR += b_RIncrement          ' Add the appropriate increments to the
            bG += b_GIncrement          ' RGB values.  The result is a nifty
            bB += b_BIncrement          ' "cross-fade" effect.
            fR += f_RIncrement
            fG += f_GIncrement
            fB += f_BIncrement

            ctrl.BackColor = Color.FromArgb(bR, bG, bB)   ' Repaint the button using the
            ctrl.ForeColor = Color.FromArgb(fR, fG, fB)   ' current RGB values, and refresh
            ctrl.Refresh()                                ' the button.

            Threading.Thread.Sleep(30 - (count * 2))      ' Wait a certain number of milliseconds,
            '                                               which is a factor of the current count.
            '                                               I tweaked these numbers to get a decent
            '                                               effect; feel free to adjust these
            '                                               numbers to achieve an effect you like.
        Next
        Select Case Hovering
            Case True
                ctrl.BackColor = SystemColors.HighlightText          ' Finish the effect by painting
                ctrl.ForeColor = SystemColors.Highlight ' the control with it's final
            Case False                                              ' look, depending on whether
                ctrl.BackColor = SystemColors.Highlight               ' we're fading in or out.
                ctrl.ForeColor = SystemColors.HighlightText
        End Select
    End Sub
#End Region

Wednesday, July 20, 2011

Get ip code in vb and asp .net

vb.net


Dim sam As String 'System.Net.IPAddress
        'Dim comp As Object
        'Dim rtn As Boolean

        Dim sam1 As String
        With System.Net.Dns.GetHostEntry(System.Net.Dns.GetHostName())
            sam = .AddressList(0).ToString
            MsgBox(sam)
            sam1 = sam.ToString
        End With

asp.net

  Dim a As String
        Dim i As System.Net.IPHostEntry
        a = System.Net.Dns.GetHostName
        i = System.Net.Dns.GetHostEntry(a)
        Response.Write("The Name of Host is :" + i.HostName)
        Response.Write("----")
        For Each b As System.Net.IPAddress In i.AddressList
            Response.Write("The Ip Address of Host is" + b.ToString)
        Next

Tuesday, July 5, 2011

SQL INNER JOIN

strSQL = "SELECT tbl_stud.id, tbl_stud.name, tbl_stud.address, tbl_course.course FROM tbl_stud INNER JOIN tbl_course ON tbl_stud.id = tbl_course.id"
 DataGridView1.DataSource = objc.GetDataTable(strSQL, CommandType.Text)


SQL INNER JOIN Syntax

SELECT column_name(s)
FROM table_name1
INNER JOIN table_name2
ON table_name1.column_name=table_name2.column_name

Multiple datatables in crystal report


 Dataset2 has two datatables - tbl_stud and tbl_course


Dim daT1, daT2 As OleDbDataAdapter
Dim DataSet2 As DataSet
connection_open()

        strSQL = "SELECT * FROM tbl_stud"
        daT1 = New OleDbDataAdapter(strSQL, con)
        DataSet2 = New DataSet
        daT1.Fill(DataSet2, "tbl_stud")

        strSQL = "SELECT * FROM tbl_course"
        daT2 = New OleDbDataAdapter(strSQL, con)
        daT2.Fill(DataSet2, "tbl_course")

        Dim rpt As New CrystalReport1
        rpt.SetDataSource(DataSet2)
        Form5.CrystalReportViewer1.ReportSource = rpt

connection_close()

Monday, June 27, 2011

It is a simple code for asp.net that you can use for your login page


Imports System.Data.OleDb

Partial Class _Default
    Inherits System.Web.UI.Page
    Dim cn As New OleDbConnection
    Dim cmd As New OleDbCommand
    Dim dr As OleDbDataReader

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Try
            With cn
                If .State = Data.ConnectionState.Open Then .Close()
                .ConnectionString = "Provider=microsoft.jet.oledb.4.0;data source=" & Server.MapPath("data\asp.mdb")

                .Open()
                'MsgBox("connected")
            End With
        Catch ex As Exception
            MsgBox(ex.Message.ToString)
        End Try
    End Sub

Protected Sub btnLogin_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnLogin.Click

        If txtUsername.Text = "" Or txtPassword.Text = "" Then Exit Sub

        With cmd
            .CommandText = "Select * from tbluser Where username = '" & Trim(txtUsername.Text) & "' and password = '" & Trim(txtPassword.Text) & "' "
            .Connection = cn
            dr = .ExecuteReader
        End With


        If dr.HasRows Then
            'MsgBox("Welcome", MsgBoxStyle.Information, "Welcome")
            Session("name") = txtUsername.Text
            Response.Redirect("default2.aspx")
        Else
            'MsgBox("Access Denied", MsgBoxStyle.Exclamation, "Error")
            Label1.Text = ("Pangit ka! " & txtUsername.Text)
        End If
    End Sub

    Protected Sub btnCancel_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnCancel.Click

        txtPassword.Text = Nothing
        txtUsername.Text = Nothing

    End Sub
End Class