Blogger Widgets

Rabu, 16 November 2016

Excel & Word Automation Visual Basic

Penjelasan Program

  Program ini merupakan program yang bisa membantu para pengajar yang memiliki kewajiban untuk meng-input nilai dari siswa yang diajarnya, dan memudahkan pengajar untuk membuat data laporan nilai siswa dan membuat surat pemberitahuan kelulusan siswa. Program ini menggunakan koding Excel dan Word Automation untuk meng-otomasi program Visual Basic ke Ms. Excel & Ms.Word.

Berikut adalah cara penggunaan aplikasi :
  • ·        Pada saat program dijalankan, yang pertama kali keluar adalah form pengisian data siswa. Pengajar dapat mengisikan nama siswa,nomor siswa dan nilai siswa.
  • ·        Setelah data selesai diisi, pengajar harus menekan tombol hitung data untuk memproses nilai siswa.
  • ·        Di bagian paling bawah form, terdapat tombol “Baru”, “Surat Pemberitahuan”,”Lihat Data”,dan “Selesai”. Berikut penjelasan untuk tombol        :

Ø  Tombol “Baru” = Tombol ini berfungsi untuk membersihkan data yang tadi diisikan                                  dan membuat form siap diisi data baru.
   
Ø  Tombol “Surat Pemberitahuan” = Tombol ini berfungsi untuk membuat visual basic
   terhubung dengan Ms.Word untuk surat
   pemberitahuan kelulusan.
Ø  Tombol “Lihat Data” = Tombol ini berfungsi untuk membuat program yang ada di                                              visual basic terhubung dengan Ms.Excel untuk membantu 
                                                             membuat laporan data nilai siswa.
Ø  Tombol “ Selesai” = Tombol ini berfungsi jika pengajar sudah menyelesaikan tugasnya
        untuk meng-input nilai siswa.


 Dalam program ini saya tidak hanya menggunkan prgram Visual Basic sebagai mesin penghitung, tetapi juga memanfaatkan aplikasi Ms.Excel untuk menghitung akumulasi nilai siswa. Dengan menambahkan rumus pada sel-sel tertentu. Source Code dibawah, memungkinkan user untuk memasukan data siswa yang jumlahnya banyak.



Screen Shoot Hasil Running Program






                                               NB : Terdapat garis merah sebagai bookmark surat
Source Code

Imports Excel = Microsoft.Office.Interop.Excel
Imports Word = Microsoft.Office.Interop.Word
Public Class Form1

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Dim myExcelApp As New Excel.Application
        Dim myExcelBook As Excel.Workbook
        Dim row As Long
        Dim myExcelSheet As Excel.Worksheet

        myExcelApp.Visible = True
        myExcelBook = myExcelApp.Workbooks.Open("F:\ExcelWordAutomation\Book1.xlsx")
        myExcelSheet = myExcelBook.Sheets("Sheet1")
        row = myExcelSheet.Range("A" & myExcelSheet.Rows.Count).End(Excel.XlDirection.xlUp).Row

        myExcelApp.Range("A1").Value = "No."
        myExcelApp.Range("B1").Value = "Nama Mahasiswa"
        myExcelApp.Range("C1").Value = "NPM"
        myExcelApp.Range("D1").Value = "Jenis Kelamin"
        myExcelApp.Range("E1").Value = "Statistik"
        myExcelApp.Range("F1").Value = "Diskrit"
        myExcelApp.Range("G1").Value = "Matek"
        myExcelApp.Range("H1").Value = "Ekonomi"
        myExcelApp.Range("I1").Value = "Akuntansi"
        myExcelApp.Range("J1").Value = "Nilai Rata-Rata"
        myExcelApp.Range("K1").Value = "Grade"
        myExcelApp.Range("L1").Value = "Keterangan"

        myExcelApp.Range("A" & row + 1).Value = CStr(row)
        myExcelApp.Range("B" & row + 1).Value = txtNama.Text
        myExcelApp.Range("C" & row + 1).Value = txtNPM.Text
        myExcelApp.Range("D" & row + 1).Value = lblJK.Text
        myExcelApp.Range("E" & row + 1).Value = txtSta.Text
        myExcelApp.Range("F" & row + 1).Value = txtDis.Text
        myExcelApp.Range("G" & row + 1).Value = txtMat.Text
        myExcelApp.Range("H" & row + 1).Value = txtEko.Text
        myExcelApp.Range("I" & row + 1).Value = txtAkn.Text

        Me.txtNama.Text = ""
        Me.txtNPM.Text = ""
        Me.lblJK.Text = ""
        Me.txtSta.Text = ""
        Me.txtDis.Text = ""
        Me.txtMat.Text = ""
        Me.txtEko.Text = ""
        Me.txtAkn.Text = ""

        myExcelBook.SaveAs("F:\ExcelWordAutomation\Book1.xlsx")
        myExcelApp.Quit()
    End Sub

    Private Sub btnBaru_Click(sender As Object, e As EventArgs) Handles btnBaru.Click
        txtAkn.Text = ""
        txtDis.Text = ""
        txtEko.Text = ""
        txtMat.Text = ""
        txtNama.Text = ""
        txtNPM.Text = ""
        txtSta.Text = ""
        txtNama.Focus()
    End Sub

    Private Sub btnSelesai_Click(sender As Object, e As EventArgs) Handles btnSelesai.Click
        Me.Close()
    End Sub

    Private Sub rbtLaki_CheckedChanged(sender As Object, e As EventArgs) Handles rbtLaki.CheckedChanged
        lblJK.Text = rbtLaki.Text
    End Sub

    Private Sub rbtPer_CheckedChanged(sender As Object, e As EventArgs) Handles rbtPer.CheckedChanged
        lblJK.Text = rbtPer.Text
    End Sub

    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load

    End Sub

    Private Sub btnWord_Click(sender As Object, e As EventArgs) Handles btnWord.Click
        Dim myWordApp As New Word.Application
        Dim myWordDoc As New Word.Document

        myWordApp.Visible = True
        myWordDoc = myWordApp.Documents.Open("F:\ExcelWordAutomation\Word1.docx")

        myWordDoc.Bookmarks("Nama1").Select()
        myWordApp.Selection.Font.Name = "Times New Roman"
        myWordApp.Selection.Font.Size = 12
        myWordApp.Selection.TypeText(txtNama.Text)

        myWordDoc.Bookmarks("Nama2").Select()
        myWordApp.Selection.Font.Name = "Times New Roman"
        myWordApp.Selection.Font.Size = 12
        myWordApp.Selection.TypeText(txtNama.Text)

        myWordDoc.Bookmarks("NPM").Select()
        myWordApp.Selection.Font.Name = "Times New Roman"
        myWordApp.Selection.Font.Size = 12
        myWordApp.Selection.TypeText(txtNPM.Text)

        myWordDoc.Bookmarks("Ket").Select()
        myWordApp.Selection.Font.Name = "Bradley Hand ITC"
        myWordApp.Selection.Font.Size = 16
        myWordApp.Selection.Font.Bold = 1
        myWordApp.Selection.TypeText(lblKet.Text)

        myWordDoc.Bookmarks("Pred").Select()
        myWordApp.Selection.Font.Name = "Times New Roman"
        myWordApp.Selection.Font.Size = 12
        myWordApp.Selection.Font.Bold = 1
        myWordApp.Selection.TypeText(lblPred.Text)

        myWordDoc.Bookmarks("Pred2").Select()
        myWordApp.Selection.Font.Name = "Times New Roman"
        myWordApp.Selection.Font.Size = 12
        myWordApp.Selection.Font.Bold = 1
        myWordApp.Selection.TypeText(lblPred2.Text)

        myWordDoc.SaveAs("F:\ExcelWordAutomation\Word1.docx")
        myWordApp.Quit()

    End Sub

    Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
        lblRata.Text = (Val(txtAkn.Text) + Val(txtDis.Text) + Val(txtEko.Text) + Val(txtMat.Text) + Val(txtSta.Text)) / 5

        If (lblRata.Text >= 85) Then
            lblPred.Text = "A"
        ElseIf (lblRata.Text >= 75) Then
            lblPred.Text = "B"
        ElseIf lblRata.Text >= 60 Then
            lblPred.Text = "C"
        ElseIf lblRata.Text >= 55 Then
            lblPred.Text = "D"
        Else : lblPred.Text = "E"
        End If

        If (lblPred.Text = "A") Then
            lblKet.Text = "Lulus"
        ElseIf (lblPred.Text = "B") Then
            lblKet.Text = "Lulus"
        ElseIf (lblPred.Text = "C") Then
            lblKet.Text = "Lulus Bersyarat"
        Else : lblKet.Text = "Tidak Lulus"
        End If

        If (lblPred.Text = "A") Then
            lblPred2.Text = "Sangat Baik"
        ElseIf (lblPred.Text = "B") Then
            lblPred2.Text = "Baik"
        ElseIf (lblPred.Text = "C") Then
            lblPred2.Text = "Cukup"
        ElseIf (lblPred.Text = "D") Then
            lblPred2.Text = "Kurang"
        Else : lblPred2.Text = "Sangat Kurang"
        End If
    End Sub
End Class


Selasa, 07 Juni 2016

Program C++ Interaktif

Hallo Readers, posting lagi nih. Sekarang aku mau kalian lihat hasil tugas UAS Matkul Konsep Pemrograman punya aku. Semoga bermanfaat ya, jangan lupa cantumkan sumber kalau mau copy paste ya. See you on next post :)

Penjelasan Program

Program ini merupakan program interaktif yang memberikan kebebasan pada user untuk memilih masalah apa yang ingin dibahas berikut dengan penyelesaiannya. Dalam program ini saya menggunakan 4 materi bahasan yang telah dibahas, diantaranya : Struct, String, Class, dan Array. Berikut adalah algoritma program :
1.     Pada output awal saya menggunakan string untuk menginput nama pengguna.
2.     Setelah itu user diberi 3 pilihan masalah yang ingin diselesaikan, seperti program perhitungan fisika (kecepatan, jarak, waktu), program perhitungan nilai akhir, juga program pemanggilan data yang diperlukan.
3.     Jika user memilih problem pertama denganmemasukkan angka 1, maka akan muncul komponen-komponen perhitungan fisika. Dalam program ini saya menggunakan fungsi class yang merupakan metode untuk organisasi data dan fungsi dalam struktur yang sama.
4.  Jika user memilih problem kedua dengan memasukkan angka 2, maka akan muncul objek pelajaran dan user dituntut untuk memasukkan angka yang berhubungan dengan nilai yang mereka miliki pada objek pelajaran tertentu. Dalam program ini saya menggunakan fungsi struct merupakan kumpulan berbagai tipe data yang memiliki ukuran yang berbeda di kelompokan dalam satu deklarasi unik.
5.     Jika user memilih problem ketiga dengan memasukkan angka 3, maka akan muncul program pemanggilan data dan dilihat lalu dipanggil sesuai dengan angka baris dan kolom yang dimasukkan pengguna. Dalam program ini saya menggunakan fungsi array yang merupakan himpunan elemen (variable) dengan tipe yang sama dan disimpan secara berurutan dalam memory yang ditandai dengan memberikan index pada suatu nama variable.


Screen Shoot Hasil Running Program

Ini adalah dialog input, kalian harus memasukkan angka 1,2, atau 3 sesuai dengan pilihan pertanyaan,jika sudah selesai input tekan enter.



Jika kalian memasukkan angka 1 pada input awal, akan keluar output seperti ini    :



Jika kalian memasukkan angka 2 pada input awal, akan keluar output seperti ini    :



Jika kalian memasukkan angka 3 pada input awal, akan keluar output seperti ini    :





Source Code Program

// UASkp.cpp : Defines the entry point for the console application.
//

#include"stdafx.h"
#include<iostream>
using namespace std;

int billy[2][5] = { { 1, 3, 5, 7, 9 }, { 2, 4, 6, 8, 10 } };


class physic{
public:
       int velocity(int space, int time){
             int velocity = space / time;
             return velocity;
       }
       int space(int velocity, int time){
             int space = velocity*time;
             return space;
       }
       int time(int velocity, int space){
             int time = space / velocity;
             return time;
       }
}PhysicOperation;
struct HighScores{
       char Grade[5];
       int Math;
       int Chemistry;
       int Biology;
       int Physics;
       int English;
       float Final;
}Scores;

int _tmain(int argc, _TCHAR* argv[])
{
       cout<<"Welcome to My Program!!! Have a Nice Day :)";
       cout<<endl;
       cout<<endl;
       char widi[100];
       cout<<"What's Your Name? ";
       cin.getline(widi, 100);
       cout<<endl;
       cout<<"Hello "<<widi<<" Nice to Meet You :)"<<".\n";
       cout<<endl;
       cout<<endl;
       cout<<"What do you want to ask?";
       cout<<endl;
       cout<<"1. I can help your physics problem (velocity,time,space)";
       cout<<endl;
       cout<<"2. I can help to count your final scores";
       cout<<endl;
       cout<<"3. I can help to call the data that you need";
       cout<<endl;
       cout<<endl;
       int a;
       cout<<"Enter your question number : ";
       cin>> a;

       if (a <= 1){
             cout<<"Choose your problem";
             cout<<endl;
             cout<<"Count the Velocity : 1";
             cout<<endl;
             cout<<"Count the Space : 2";
             cout<<endl;
             cout<<"Count the Time ; 3";
             cout<<endl;
             cout<<endl;
             int choice;
             cout<<"Enter your Phisycs Problem : ";
             cin>> choice;
             cout<<endl;

             if (choice <= 1){
                    int s;
                    cout<<"Enter the Space : ";
                    cin>> s;
                    int t;
                    cout<<"Enter The Time (Hours) : ";
                    cin>> t;
                    int VelocityResult;
                    VelocityResult =PhysicOperation.velocity(s,t);
                    cout<<"Velocity : "<<VelocityResult<<endl;
                    cout<<"Thank you for coming!!! See you soon!!!!";
                    cout<<endl;

             }
             else if (choice <= 2){
                    int v;
                    cout<<"Enter the Velocity : ";
                    cin>> v;
                    int t;
                    cout<<"Enter the Time (Hours) : ";
                    cin>> t;
                    int SpaceResult;
                    SpaceResult = PhysicOperation.space(v, t);
                    cout<<"Space : "<<SpaceResult<<endl;
                    cout<<"Thank you for coming!!! See you soon!!!!";
                    cout<<endl;

             }
             else {
                    int s;
                    cout<<"Enter the Space : ";
                    cin>> s;
                    int v;
                    cout<<"Enter the Velocity : ";
                    cin>> v;
                    int TimeResult;
                    TimeResult = PhysicOperation.time(v, s);
                    cout<<"Time : "<<TimeResult<<endl;
                    cout<<"Thank you for coming!!! See you soon!!!!";
                    cout<<endl;
             }
       }
       else if (a <= 2){
             cout<<"Enter your Scores";
             cout<<endl;
             cout<<"Math Scores : ";
             cin>> (Scores.Math);
             cout<<endl;
             cout<<"Chemistry Scores : ";
             cin>> (Scores.Chemistry);
             cout<<endl;
             cout<<"Biology Scores : ";
             cin>> (Scores.Biology);
             cout<<endl;
             cout<<"Physics Scores : ";
             cin>> (Scores.Physics);
             cout<<endl;
             cout<<"English Scores : ";
             cin>> (Scores.English);
             cout<<endl;
             cout<<endl;

             int FinalScores;
             FinalScores = (Scores.Math * 20 / 100) + (Scores.Chemistry * 20 / 100) + (Scores.Biology * 20 / 100) + (Scores.Physics * 20 / 100) + (Scores.English * 20 / 100);
             cout<<"Final Score : "<<FinalScores;
             cout<<endl;

                           if (FinalScores>= 80){
                    cout<<"Grade = A";
             }
             else if (FinalScores>= 70){
                    cout<<"Grade = B";
             }
              else if (FinalScores>= 65){
                    cout<<"Grade = C";
             }
             else if (FinalScores>= 55){
                    cout<<"Grade = D";
             }
             else {
                    cout<<"Grade = E";
             }
             cout<<endl;

             if (FinalScores>= 65){
                    cout<<"Congratulation for Your High Grade";
             }
             else{
                    cout<<"I'm Sorry to Hear That, You Have Many Chances to Repair Your Grade";
             }
             cout<<endl;
             cout<<endl;
             cout<<"Thank you for coming!!! See you soon!!!!";
             cout<<endl;
       }
       else{
             cout<<" Data : {(row1){1,2,3,4,5},(row2){6,7,8,9,10}}";
             cout<<endl;
             int num1;
             cout<<"Enter Row :  ";
             cin>> num1;
             int num2;
             cout<<"Enter Column : ";
             cin>> num2;
             cout<<"Data : "<<billy[num1][num2];
             cout<<endl;
             cout<<endl;
             cout<<"Thank you for coming!!! See you soon!!!!";
             cout<<endl;



       }
       return 0;
}