Khamis, 22 Disember 2016

Projek 1 : Arduino - Kawalan Servo, LED, Buzzer dengan aplikasi vb6

Kawalan Servo, LED, Buzzer dengan aplikasi vb6.

(A) Keperluan Peralatan dan Perisian :-
- 1 unit Arduino Uno
- 1 unit Led
- 6 wayar jumper
- 1 unit Buzzer
- 1 unit Servo
- Perisian Microsoft VB6
- Perisian Arduino IDE

(B) Dilampirkan aturcara  Arduino IDE :-

#define echoPin 7 // Echo Pin
Servo myservo;
int pos=0;
int led = 13;
int peizoPin = 8;
String incoming;

void setup()
  pinMode(led, OUTPUT);// Penggunaan LED
  pinMode(echoPin, INPUT);// Penggunaan Servo

void loop()
  if(Serial.available() > 0)
    incoming = Serial.readString();
    if(incoming == "Led ON")
      // turn LED on:
      digitalWrite(led, HIGH);
      Serial.println("LED is ON....");
    else if(incoming == "Led OFF")
      // turn LED off:
      digitalWrite(led, LOW);
      Serial.println("LED turning OFF.......");

(C)Antaramuka Kawalan Projek :-

(i) VB6.

(ii) Rekabentuk pemasangan (breadboard).

(D) Kod aturcara Microsoft VB6  seperti berikut :-

Dim onn As String, off As String

Private Sub cmdconnect_Click()

ArduinoUno.RThreshold = 3

ArduinoUno.Settings = "9600,n,8,1"

ArduinoUno.PortOpen = True

ArduinoUno.DTREnable = False

Text1.Text = ""

Shape1.FillColor = vbRed
cmdconnect.Caption = "Port Opened!"
cmdconnect.Enabled = False
cmdon.Enabled = True
cmdexit.Enabled = True
cmdoff.Enabled = False
End Sub

Private Sub cmdexit_Click()
off = "Led OFF"
ArduinoUno.Output = off
'ArduinoUno.PortOpen = False
End Sub

Private Sub cmdoff_Click()
off = "Led OFF"
ArduinoUno.Output = off
Shape1.FillColor = vbRed
ReceivedData 'call function retrieve data from arduino
cmdon.Enabled = True
cmdoff.Enabled = False
End Sub

Private Sub cmdon_Click()
onn = "Led ON"
ArduinoUno.Output = onn
Shape1.FillColor = vbGreen
ReceivedData 'call function retrieve data from arduino
cmdon.Enabled = False
cmdoff.Enabled = True
End Sub

Sub RetrieveDataOLD()
  Dim strInput As String
  Text1.Text = ""
  strInput = Text1.Text
  With ArduinoUno
    'test for incoming event
    Select Case .CommEvent
      Case comEvReceive
        'display incoming event data to displaying textbox
        strInput = .Input
        Dim str As Variant
        str = Split(strInput, "|")
        Text1.SelText = str(0)
    End Select
  End With
tmrReceivedData.Enabled = False
End Sub

Private Sub Command1_Click()
tmrReceivedData.Enabled = True
End Sub

Sub ReceivedData()
End Sub

Sub tmrReceivedData_Timer()
tmrReceivedData.Enabled = True
End Sub

*Sebarang cadangan atau penambahbaikan boleh berhubung dengan email ini

Khamis, 25 Oktober 2012

Periksa HPhone dan Android Specs betul ke tidak?

Kepada sesiapa yg nk nk beli tablet pc, hp android yg brand ke or china ke.. saya cadgkan agar anda pasti specs yg diberikn adalah betul. utk mengetahui maklumat lain spt processor n sbgainya anda boleh la download apps ini iaitu Quick System Infor Pro di .. ia membantu anda utk tahu specs selain daripada anda tgk di dalm android tu kt settings-->RAM / Storage / About Phone.. tapi anda thu processornya.. saya dh guna benda nie smasa kejadian bebaru ini..emm ia membantu.

Nk tahu Original ke tidak ..daptkn no IMEI (International Mobile Equipment Identity) / no siri dgn cara masukan/dial *#06# terus kuar..cer try.. pastu nk semak pula boleh send sms no IMEI tu kepada 3200 utk ketahui manufacture dn sebagainya..ATAU  trace di

Jumaat, 19 Oktober 2012

How to copy Outlook mail message into excel using VBA or Macros

* First paste the below mentioned code in the outlook module.
  1. Click on Tools~~>Rules and Alerts
  2. Click on "New Rule"
  3. Click on "start from a blank rule"
  4. Select "Check messages When they arrive"
  5. Under conditions, click on "with specific words in the subject"
  6. Click on "specific words" under rules description.
  7. Type the word that you want to check in the dialog box that pops up and click on "add".
  8. Click "Ok" and click next
  9. Select "move it to specified folder" and also select "run a script" in the same box
  10. In the box below, specify the specific folder and also the script (the macro that you have in module) to run.
  11. Click on finish and you are done.
When the new email arrives not only will the email move to the folder that you specify but data from it will be exported to Excel as well.
Const xlUp As Long = -4162
Sub ExportToExcel(MyMail As MailItem)
    Dim strID As String, olNS As Outlook.Namespace
    Dim olMail As Outlook.MailItem
    Dim strFileName As String

    '~~> Excel Variables
    Dim oXLApp As Object, oXLwb As Object, oXLws As Object
    Dim lRow As Long

    strID = MyMail.EntryID
    Set olNS = Application.GetNamespace("MAPI")
    Set olMail = olNS.GetItemFromID(strID)

    '~~> Establish an EXCEL application object
    On Error Resume Next
    Set oXLApp = GetObject(, "Excel.Application")

    '~~> If not found then create new instance
    If Err.Number <> 0 Then
        Set oXLApp = CreateObject("Excel.Application")
    End If
    On Error GoTo 0

    '~~> Show Excel
    oXLApp.Visible = True

    '~~> Open the relevant file
    Set oXLwb = oXLApp.Workbooks.Open("C:\Sample.xls")

    '~~> Set the relevant output sheet. Change as applicable
    Set oXLws = oXLwb.Sheets("Sheet1")

    lRow = oXLws.Range("A" & oXLApp.Rows.Count).End(xlUp).Row + 1

    '~~> Write to outlook
    With oXLws
        '~~> Code here to output data from email to Excel File
        '~~> For example
        .Range("A" & lRow).Value = olMail.Subject
        .Range("B" & lRow).Value = olMail.SenderName
    End With

    '~~> Close and Clean up Excel
    oXLwb.Close (True)
    Set oXLws = Nothing
    Set oXLwb = Nothing
    Set oXLApp = Nothing

    Set olMail = Nothing
    Set olNS = Nothing
End Sub
To extract the contents from your email body, you can split it using SPLIT() and then parsing out the relevant information from it. See this example
Dim MyAr() As String

MyAr = Split(olMail.body, vbCrLf)
For i = LBound(MyAr) To LBound(MyAr)
    '~~> This will give you the contents of your email
    '~~> on separate lines
    Debug.Print MyAr(i)
Next i

"How do I extract data from Outlook emails to Excel workbooks?" For example, two questions up on [outlook-vba] the same question was asked on 13 August. That question references a variation from December that I attempted to answer.
For the December question, I went overboard with a two part answer. The first part was a series of teaching macros that explored the Outlook folder structure and wrote data to text files or Excel workbooks. The second part discussed how to design the extraction process. For this question Siddarth has provided an excellent, succinct answer and then a follow-up to help with the next stage.
What the questioner of every variation appears unable to understand is that showing us what the data looks like on the screen does not tell us what the text or html body looks like. This answer is an attempt to get past that problem.
The macro below is more complicated than Siddarth’s but a lot simpler that those I included in my December answer. There is more that could be added but I think this is enough to start with.
The macro creates a new Excel workbook and outputs selected properties of every email in Inbox to create this worksheet:
Example of worksheet created by macro
Near the top of the macro there is a comment containing eight hashes (#). The statement below that comment must be changed because it identifies the folder in which the Excel workbook will be created.
All other comments containing hashes suggest amendments to adapt the macro to your requirements.
How are the emails from which data is to be extracted identified? Is it the sender, the subject, a string within the body or all of these? The comments provide some help in eliminating uninteresting emails. If I understand the question correctly, an interesting email will have Subject = "Task Completed".
The comments provide no help in extracting data from interesting emails but the worksheet shows both the text and html versions of the email body if they are present. My idea is that you can see what the macro will see and start designing the extraction process.
This is not shown in the screen image above but the macro outputs two versions on the text body. The first version is unchanged which means tab, carriage return, line feed are obeyed and any non-break spaces look like spaces. In the second version, I have replaced these codes with the strings [TB], [CR], [LF] and [NBSP] so they are visible. If my understanding is correct, I would expect to see the following within the second text body:
Activity[TAB]Count[CR][LF]Open[TAB]35[CR][LF]HCQA[TAB]42[CR][LF]HCQC[TAB]60[CR][LF]HAbst[TAB]50 45 5 2 2 1[CR][LF] and so on
Extracting the values from the original of this string should not be difficult.
I would try amending my macro to output the extracted values in addition to the email’s properties. Only when I have successfully achieved this change would I attempt to write the extracted data to an existing workbook. I would also move processed emails to a different folder. I have shown where these changes must be made but give no further help. I will respond to a supplementary question if you get to the point where you need this information.
Good luck.
Option ExplicitPublic Sub SaveEmailDetails()

  ' This macro creates a new Excel workbook and writes to it details
  ' of every email in the Inbox.

  Dim ExcelWkBk As Excel.Workbook
  Dim FileName As String
  Dim FolderTgt As MAPIFolder
  Dim HtmlBody As String
  Dim InterestingItem As Boolean
  Dim InxItemCrnt As Long
  Dim PathName As String
  Dim ReceivedTime As Date
  Dim RowCrnt As Long
  Dim SenderEmailAddress As String
  Dim SenderName As String
  Dim Subject As String
  Dim TextBody As String
  Dim xlApp As Excel.Application

  ' The Excel workbook will be created in this folder.
  ' ######## Replace "C:\DataArea\Play" with the name of a folder on your disc.
  PathName = "C:\DataArea\Play"

  ' This creates a unique filename.
  ' #### If you want to update an existing workbook, set FileName to its name
  FileName = Format(Now(), "yymmdd hhmmss") & ".xls"

  ' Open own copy of Excel
  Set xlApp = Application.CreateObject("Excel.Application")
  With xlApp
    .Visible = True         ' This slows your macro but helps during debugging
    .ScreenUpdating = False ' Reduces flash and increases speed
    ' Create a new workbook
    ' #### If updating an existing workbook, replace with an
    ' #### Open workbook statement.
    Set ExcelWkBk = xlApp.Workbooks.Add
    With ExcelWkBk
      ' #### None of this code will be useful if you are adding
      ' #### to an existing workbook.  However, it demonstrates a
      ' #### variety of useful statements.
      .Worksheets("Sheet1").Name = "Inbox"    ' Rename first worksheet
      With .Worksheets("Inbox")
        ' Create header line
        With .Cells(1, "A")
          .Value = "Field"
          .Font.Bold = True
        End With
        With .Cells(1, "B")
          .Value = "Value"
          .Font.Bold = True
        End With
        .Columns("A").ColumnWidth = 18
        .Columns("B").ColumnWidth = 150
      End With
    End With
    RowCrnt = 2
  End With

  ' FolderTgt is the folder I am going to search.  This statement says
  ' I want to seach the Inbox.  The value "olFolderInbox" can be replaced
  ' to allow any of the standard folders to be searched.  I have a routine
  ' that will find other folders which I will share if it would be useful.
  Set FolderTgt = CreateObject("Outlook.Application"). _

  ' This examines the emails in reverse order. I will explain why later.
  For InxItemCrnt = FolderTgt.Items.Count To 1 Step -1
    With FolderTgt.Items.Item(InxItemCrnt)
      ' A folder can contain several types of item: mail items, meeting items,
      ' contacts, etc.  I am only interested in mail items.
      If .Class = olMail Then
        ' Save selected properties to variables
        ReceivedTime = .ReceivedTime
        Subject = .Subject
        SenderName = .SenderName
        SenderEmailAddress = .SenderEmailAddress
        TextBody = .Body
        HtmlBody = .HtmlBody
        InterestingItem = True
        InterestingItem = False
      End If
    End With
    ' The most used properties of the email have been loaded to variables but
    ' there are many more properies.  Press F2.  Scroll down classes until
    ' you find MailItem.  Look through the members and note the name of
    ' any properties that look useful.  Look them up using VB Help.

    ' #### You need to add code here to eliminate uninteresting items.
    ' #### For example:
    'If SenderEmailAddress <> "" Then
    '  InterestingItem = False
    'End If
    'If InStr(Subject, "Accounts payable") = 0 Then
    '  InterestingItem = False
    'End If

    ' #### If the item is still thought to be interesting I
    ' #### suggest extracting the required data to variables here.

    ' #### You should consider moving processed emails to another
    ' #### folder.  The emails are being processed in reverse order
    ' #### to allow this removal of an email from the Inbox without
    ' #### effecting the index numbers of unprocessed emails.

    If InterestingItem Then
      With ExcelWkBk
        With .Worksheets("Inbox")
          ' #### This code creates a dividing row and then
          ' #### outputs a property per row.  Again it demonstrates
          ' #### statements that are likely to be useful in the final
          ' #### version
          ' Create dividing row between emails
          .Rows(RowCrnt).RowHeight = 5
          .Range(.Cells(RowCrnt, "A"), .Cells(RowCrnt, "B")) _
                                      .Interior.Color = RGB(0, 255, 0)
          RowCrnt = RowCrnt + 1
          .Cells(RowCrnt, "A").Value = "Sender name"
          .Cells(RowCrnt, "B").Value = SenderName
          RowCrnt = RowCrnt + 1
          .Cells(RowCrnt, "A").Value = "Sender email address"
          .Cells(RowCrnt, "B").Value = SenderEmailAddress
          RowCrnt = RowCrnt + 1
          .Cells(RowCrnt, "A").Value = "Received time"
          With .Cells(RowCrnt, "B")
            .NumberFormat = "@"
            .Value = Format(ReceivedTime, "mmmm d, yyyy h:mm")
          End With
          RowCrnt = RowCrnt + 1
          .Cells(RowCrnt, "A").Value = "Subject"
          .Cells(RowCrnt, "B").Value = Subject
          RowCrnt = RowCrnt + 1
          If TextBody <> "" Then
            With .Cells(RowCrnt, "A")
              .Value = "text body"
              .VerticalAlignment = xlTop
            End With
            With .Cells(RowCrnt, "B")
              ' The maximum size of a cell 32,767
              .Value = Mid(TextBody, 1, 32700)
              .WrapText = True
            End With
            RowCrnt = RowCrnt + 1
            With .Cells(RowCrnt, "A")
              .Value = "text body"
              .VerticalAlignment = xlTop
            End With
            TextBody = Replace(TextBody, Chr(160), "[NBSP]")
            TextBody = Replace(TextBody, vbCr, "[CR]")
            TextBody = Replace(TextBody, vbLf, "[LF]")
            TextBody = Replace(TextBody, vbTab, "[TB]")
            With .Cells(RowCrnt, "B")
              ' The maximum size of a cell 32,767
              .Value = Mid(TextBody, 1, 32700)
              .WrapText = True
            End With
            RowCrnt = RowCrnt + 1
          End If

          If HtmlBody <> "" Then
            With .Cells(RowCrnt, "A")
              .Value = "Html body"
              .VerticalAlignment = xlTop
            End With
            With .Cells(RowCrnt, "B")
              .Value = Mid(HtmlBody, 1, 32700)
              .WrapText = True
            End With
            RowCrnt = RowCrnt + 1
          End If
        End With
      End With
    End If

  With xlApp
    With ExcelWkBk
      ' Write new workbook to disc
      If Right(PathName, 1) <> "\" Then
        PathName = PathName & "\"
      End If
      .SaveAs FileName:=PathName & FileName
    End With
    .Quit   ' Close our copy of Excel
  End With

  Set xlApp = Nothing       ' Clear reference to Excel
End Sub