Function most count

Function most count
Posted on August 13, 2007 by ghafi

Function is told is a logistic where numeral mengkonvert as sentence. Logistic example to be told aught in day-to-day life is: invoice, slip setor is savings, and other as it.

 

Function is told may tell simple's enough but crazily deep its algorithm. Since function was told to utilize language phrase those are utilized. to sample coding hereunder utilizes indonesian, for english language or the other language, please modif source whatever available hereunder.

 

Following samples coding that my for at crystal report 8.5:

stringVar array angka := ["Nol", "Satu", "Dua", "Tiga", "Empat", "Lima", "Enam", "Tujuh", "Delapan", "Sembilan", "Se"];
stringVar array satuan := ["belas", "puluh", "ratus", "ribu", "juta", "milyar", "triliun", "billiun"];
stringvar nil1;
stringvar nil2;
numbervar b;
stringvar a;
stringvar strtblg;
stringvar array matrix := ["","","","","","","","","","",""];
numbervar i;
numbervar j;
booleanvar nol;
b:=1;
a:=”";
nil2:=”";
strtblg = “”;
nil1:= “”;
for i := 2 to len(totext(Sum ({@totalall}, {ado.kode cc fad})))-3  do
(
  if mid(totext(Sum ({@totalall}, {ado.kode cc fad})),i,1) = “,” then
    nil1 := nil1
  else
    nil1 := nil1 & mid(totext(Sum({@totalall}, {ado.kode cc fad})),i,1);
);
nil2 := totext(nil1);
if len(nil2) >= 22 then
  strtblg = “”
else
(
    for i := len(nil1) to 1 step -1 do
    (  
        if len(nil1) = 4 then
        (
            matrix[b] := right(nil2,4);
            b:=b+1;
            i:=i-3;
            if len(nil2) – 4 >=1 then
                nil2 := left(nil2, len(nil2) – 4)
            else
                nil2:=nil2;
        )
        else
        (
            matrix[b] := right(nil2,3);
            b:=b+1;
            i:=i-2;
            if len(nil2) – 3 >=1 then
                nil2 := left(nil2, len(nil2) – 3)
            else
                nil2:=nil2;
           
        );
    );
    strtblg := “”;
    for j := b – 1 to 1 step -1 do
    (
        nil2:=matrix[j];
        nol:= false;
        for i := 1 to len(matrix[j]) do
        (
            a := mid(matrix[j],i,1);
            if a = “1″ then
            (
                if tonumber(mid(nil2,1,1))=0 then
                (
                    if i = 1 then nol := true;                 
                );
                if mid(matrix[j],i+1,1)= “1″ and len(nil2) = 2 then
                (  
                    strtblg := strtblg & angka[11] & satuan[1] & ” “;
                    i := len(matrix[j]) + 1;
                )
                else if mid(matrix[j],i+1,1)= “0″ and len(nil2) = 2 then
                (
                    strtblg := strtblg & angka[11] & satuan[2] & ” “;
                    i := len(matrix[j]) + 1;                    
                )
                else if len(nil2) = 1 then
                (
                    strtblg := strtblg & angka[tonumber(a)+1] & ” “;
                    0;
                )
                else if tonumber(mid(matrix[j],i+1,1)) > 1 and len(nil2) =  2 then
                (
                    strtblg := strtblg & angka[tonumber(mid(matrix[j],i+1,1))+1] & ” ” & satuan[1] & ” “;
                    i := len(matrix[j]) +1;
                )
                else
                (
                    strtblg := strtblg & angka[11] & satuan[len(nil2)] & ” “;
                    0;
                );
            )
            else
            ( 
                if tonumber(mid(nil2,1,1)) = 0 then
                (
                    if i = 1 then nol := true; 
                )
                else if len(nil2) = 1 then
                (
                    strtblg := strtblg & angka[tonumber(a)+1] & ” “;
                    nol := false;
                )
                else
                (
                    strtblg := strtblg & angka[tonumber(a)+1] & ” ” & satuan[len(nil2)-1+1] & ” “;
                    nol := false;
                );
                0;
            );
        
          if i <= len(matrix[j]) then nil2 := right(nil2,len(matrix[j])-i);
        );
      if j >= 2 and nol = false  then strtblg := strtblg & satuan[j+2] & ” “;
    );
);  
strtblg & “Rupiah.”;   

Creating Reports in VB.NET using Crystal Reports with Xml data Definitions

Abstract

This article explains how to extract data into a Crystal Report created outside a VB.net project using xml data definitions and data sets.

Introduction

This requirement was a part of a main VB.net project, where we wanted to develop reports using crystal reports using field definitions. As we took a great deal of effort in arriving at a solution, and information available in the C# corner helped us to a great extent, we decided to submit this code for the benefit of the fellow programmers.

In this project,
  • The report is formatted outside the project via Crystal Reports (the .rpt file).

  • The data to the report is extracted from a field definition file created as a .xsd extension (as compatible with ADO.Net).

  • The report is called and displayed through a form using the crystal report viewer.
The example overview

We have taken the Authors table in the pubs database where au_id, au_lname, au_fname will be printed on the report.

The main requirement is to create the Xml schema file with .xsd extension and bind the data to the .rpt file.
The example handles this in one form with two buttons: The XSD Button to create the .xsd field definition file and the VIEW button to generate the report.
So here is the step by step procedure to arrive at this.
1. Create the .xsd field definitions file depending on the data that we want to extract from a database.
Insert the following code in the click event of  XSD  button, to create the .xsd file. In our example this file is called the 'sampledatadef.xsd'. This is created in c:\.
By inserting the following code into the start form of your project and clicking the XSD button, you will see the sampledatadef.xsd created in the root directory of your c:\.

' References used
Imports System
Imports System.Drawing
Imports System.Collections
Imports System.ComponentModel
Imports System.Windows.Forms
Imports System.Data
Imports System.Data.SqlClient

' These are auto generated
Private button1 As System.Windows.Forms.Button
Private button2 As System.Windows.Forms.Button
Private components As System.ComponentModel.Container = Nothing
'''
''' This is to generate the field definition file
''' This code needs to be executed, only when there had been a change to the
''' Data fields that are to be extracted.
'''


Private Sub button1_Click(ByVal sender As Object, ByVal e As System.EventArgs)
Dim
mcon_pub As SqlConnection
Dim mda_fld As SqlDataAdapter
' Remember to change data source as applicable.
Dim constr As String = "Data source =SERVER;Initial catalog=pubs;User ID=sa;password="
Dim sqlstmt As String = "select au_id, au_lname, au_fname from Authors"
Dim ds_fldDef As DataSet = New DataSet()
mcon_pub =
New SqlConnection(constr)
mda_fld =
New SqlDataAdapter(sqlstmt,mcon_pub)
ds_fldDef =
New DataSet()
mda_fld.Fill(ds_fldDef)
ds_fldDef.WriteXmlSchema("c:\sampledatadef.xsd")
MessageBox.Show ("Field Definitions Written Successfully")
End Sub

Private
Sub button2_Click(ByVal sender As Object, ByVal e As System.EventArgs)
Dim
mfrm_view As ViewReport = New ViewReport()
mfrm_view.Show()
End Sub

2. Now create the .rpt file in crystal reports using the .xsd field definitions file.

You need to select 'Create new Connections' and take option - Field Defintions. Select the ADO.NET option. In the dialogue box you will be asked to enter the xsd file name. Select the path and click the 'Finish' button.
We have named this report as crystalsample.rpt (saved in c:\).
If the ADO.Net option is not available, you will have to add new components to the installed crystal reports using 'Add/Remove' programs option and include the necessary component to the Crystal Reports installation.
3. Generate the class to hold the data set for the .xsd datadefiniton

This is an important step. The .xsd definitions do not recognize the datasets generated through the normal DataSet class. The report will be displayed only with the headings, if this step is not accomplished!!! (This was a weird experience to us).
This is done though executing the following command through the command prompt tool of the Visual Studio .Net Tools.
xsd.exe /d /l:VB sampledatadef.xsd
(The /d directive tells the tool to generate DataSets, /l specifies the language to use)
This command generates the DataSet class compatible with the .xsd file you created in the path in which you executed the command. The name of the source file will be sampledatadef.cs.
4. Now add this class to your project.

In the source file, the name of the class will be generated as 'NewDataSet'. Rename this name to a name that you desire in the source file. We have named it as ds_SampleDataSet.
5. Now generate the code to extract the data from field definition

In our example we have used a new form for this, which is loaded with the click event of the VIEW button.
This is done in an easy set of steps.
  1. Define a dataset of the newly generated type. In this example

    Private mydataset As ds_sampledataset = New ds_sampledataset()

  2. Fill this dataset with the identical data fields that you created for the xsd definition file. In this example they are au_id, au_lname, au_fname of Authors.

  3. Open a new ReportDocument type class and call the .rpt file you created into it. (Make sure that the necessary references are added to the project - CrystalDecisions.CrystalReports.Engine and CrystalDecisions.Shared )
The form to load the report is named as ViewReport and the CrystalReportViewer is added to the form.
The essential coding to the form goes as follows:

' References used
Imports System
Imports System.Drawing
Imports System.Collections
Imports System.ComponentModel
Imports System.Windows.Forms
Imports System.Data
Imports System.Xml
Imports System.Data.SqlClient
Imports CrystalDecisions.CrystalReports.Engine
Imports CrystalDecisions.Shared

' private variables defined
Private mcon_pub As SqlConnection
Private mda_Rpt As SqlDataAdapter
Private ds_xml As ds_SampleDataSet = New ds_SampleDataSet()
' These are auto generated
Private crystalReportViewer1 As CrystalDecisions.Windows.Forms.CrystalReportViewer
Private components As System.ComponentModel.Container = Nothing

'''
''' Connects to the database and extracts data into the new dataset type class
'''

Private Sub SetConnection()
Dim sqlstmt As String = "select au_id, au_lname, au_fname from Authors"
' Remember to change data source as applicable.
Dim constr As String = "Data source =SERVER;Initial catalog=pubs;User ID=sa;password="
mcon_pub =
New SqlConnection(constr)
mda_Rpt =
New SqlDataAdapter(sqlstmt,mcon_pub)
' Note that the data is filled into the new xml type
datasetmda_Rpt.Fill(ds_xml)
End Sub

Private
Sub SetReport()
Dim rpt As ReportDocument = New ReportDocument()
rpt.Load("C:\crystalsample.rpt")
rpt.Database.Tables(0).SetDataSource(ds_xml)
crystalReportViewer1.ReportSource = rpt
End Sub

'''
''' The load event of this form is named as Form1_Load
'''

Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs)
SetConnection()
SetReport()
End Sub

NOTE: THIS ARTICLE IS CONVERTED FROM C# TO VB.NET USING A CONVERSION TOOL. ORIGINAL ARTICLE CAN BE FOUND ON C# CORNER (WWW.C-SHARPCORNER.COM).

Comments in VB.NET

Comments can be used to document what the program does and what specific blocks or lines of code do. Since the Visual Basic compiler ignores comments, you can include them anywhere in a program without affecting your code.

How to comment?

A comment is preceded by an apostrophe. The code of line after the apostrophe is simply ignored by the compiler.
To code a comment, type an apostrophe followed by the comment. You can use this technique to add a comment on its own line or to add a comment after the code on a line.

Often when you code, you may want to comment out an entire block of code statements. Under normal circumstances, to do so you must Comment out each line individually.

Another way to comment out one or more lines of code to select the lines and click on the Comment or UnComment button in the Text Editor toolbar.

Shortcut: You can use Ctrl+C and Ctrl+U to Comment or Uncomment selected lines of text.

Tips to Comment your code
  • Use comments only for portions of code that are difficult to understand
  • Comments are used to help document what a program does and what the code with it does. Keep the comments simple and direct. Avoid ASCII art, jokes, poetry and hyper verbosity.
  • Make sure that your comments are correct and up-to-date. There is no point in commenting correctly on code if the comments are not changed with the code. Both code and comments must move in parallel, otherwise the comments will actually make life more difficult for developers who maintain your code.
  • During testing, you can comment out lines of code by coding an apostrophe before them. This is useful for testing new statements without deleting the old statement.
  • Align comments in consecutive lines

    For multiple lines of code with trailing comments, align the comments so they will be easy to read.

    Const level As Integer = 100                 ' The level mark is constant to 100 can't be changed

    Const
    turnaround As Decimal = 34.5       ' The turnaround is constant and can't be placed more

    Some developers use tabs to align comments, while others use spaces. Because tab stops can vary among editors and IDEs, the best approach is to use spaces.
  • Use paragraph comments

    If you comment is very long in line of text break into paragraph show it can be seen in a single view.

    Instead of writing like this:

    ' Author Puran Singh Mehra. Xyz Company. Created on 7th December 2008 12:23:34 P.M.


    Break into different lines like this:

    ' Author Puran Singh Mehra.
    ' Xyz Company.
    ' Created on 7th December 2008 12:23:34 P.M.

     
  • Consistent style of commenting

    Some people believe that comments should be written so that non-programmers can understand them. Others believe that comments should be directed at developers only.

    Comments are consistent and always targeted to the same audience. Comments should target to developers and non-developers.
  • Don't insult the reader's intelligence

    Avoid obvious comments such as:

    Dim
    age As Integer = 34
            If (age >= 18) Then     
    'if age is greater than 18 a person can vote
                Console.WriteLine("Can Vote")
            End
    If

    This wastes your time writing needless comments and distracts the reader with details that can be easily removed from the code.
     
  • Comment code while writing it

    Add comments while you write code and it's fresh in your memory. If you leave comments until the end, it will take you twice as long, if you do it at all. "I have no time to comment," "I'm in a hurry," and "The project is delayed" are all simply excuses to avoid documenting your code. Some developers believe you should write comments before code as a way to plan out your ultimate solution.

    For example:


    Private
    Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

           
    'On click of button check priopr that values are entered properly in order
           
    'Validate date for range and data types
           
    'ask before submitting values
            'make this entry in the database

     
            ' then you can follow your code

        End Sub

     
  • Write comments as if they were for you (in fact, they are)

    When it comes to commenting code, think not only about the developers who will maintain your code in the future, but also think about yourself. In the words of the great Phil Haack:

    "As soon as a line of code is laid on the screen, you're in maintenance mode on that piece of code."

    As a result, we ourselves will be the first beneficiaries (or victims) of our good (or bad) comments.
     
  • Write comment in a polite manner

    Avoid rude and harsh comments. You never know who may read these comments in the future: your boss, a customer, or the pathetically inept developer you just insulted. So maintain your respect and dignity.
     
  • The golden rule.

    Let the code speak for itself. You code should be written in such a way that everyone should easily understand it.

    For example:


    Dim
    str As String = "Puran Singh Mehra"
            Dim num As Integer = 36
            Dim binWriter As New BinaryWriter(File.OpenWrite("c:\myfile.dat"))
            binWriter.Write(str)
            binWriter.Write(num)
            binWriter.Close()
Conclusion

Hope the article would have helped you in understanding comments and their usage and importance in coding. Proper usage of comments makes your code easily to understand and improve performance.

Your feedback and constructive contributions are welcome. Please feel free to contact me for feedback or comments you may have about this article.

menampilkan data pd datagridview

ya udah tinggal dibuat pada saat klik pada menustrip panggil prosedur untuk menampilkan datanya, misal nampilin ke datagridview...

Code:

Imports System.Data
Imports System.Data.SqlClient

Private Sub ambildata()

Dim Connection As New SqlConnection( _
  "server=serverAddress;uid=username;pwd=password;database=database;")

Dim Adapter As New SqlDataAdapter("SELECT * FROM namatable WHERE namafield = '" & kriteria & "'", Connection)

Dim SourceDataSet As New DataSet()
Adapter.Fill(SourceDataSet)

GridControl1.DataSource = SourceDataSet.Tables(0)

End sub