How to print the text from textbox in Crystal Report
1st Step: Create Design
Ø Drag a label onto the form and change
the label TEXT in properties.
o
For
Number:
§ 2. => Change the label text into “Last Name”
§ 6. => Change the label text into “First Name”
§ 8. => Change the label text into “Middle Name”
§ 3. => Change the label text into “Month”
§ 5. => Change the label text into “Day”
§ 10 => Change the label text into “Year”
§ 21 => Change the label text into “Name”
§ 20 => Change the label text into “Birth Date”
§ 19 => Change the label text into “Address”
§ 14 => Change the label text into “Gender”
Ø Drag a textbox onto the form and
change the textbox NAME in properties.
o
For
Number:
§ 4. => Change the textbox name into “txtFName”
§ 7. => Change the textbox name into “txtLName”
§ 9. => Change the textbox name into “txtMName”
Ø Drag a combo box onto the form and
change the combo box NAME in properties.
o
For
Number:
§ 17. => Change the textbox name into “cmbMonth”
§ 16. => Change the textbox name into “cmbDay”
§ 13. => Change the textbox name into “cmbYear”
§ 11. => Change the textbox name into “cmbGender”
Ø Drag a button onto the form and
change the button NAME and TEXT in properties.
o
For
Number:
§ 18.
·
Change
the button name into “btnClear”
·
Change
the button text into “Clear”
§ 12.
·
Change
the button name into “btnPrint”
·
Change
the button text into “Print”
2nd Step: Add Crystal Report
Ø Steps on how to Add a Crystal Report.
Click Here
3rd Step: Create Crystal Report Design
Ø Add text Object and change the Text or Name
o
Right
Click => Insert => TextObject
Ø For Number:
o
1.
=> Change the text into “Student Information”
o
2.
=> Change the text into “Name”
o
3.
=> Change the name into “ctxtName”
o
4.
=> Change the text into “Birth Date”
o
5.
=> Change the name into “ctxtBirthDate”
o
6.
=> Change the text into “Gender”
o
7.
=> Change the name into “ctxtGender”
o
8.
=> Change the name into “Address”
o
9.
=> Change the name into “ctxtAddress”
4th Step: Start Coding
Ø Code for form1
Public Class frmForm
Private Sub
btnPrint_Click(ByVal sender As System.Object, ByVal
e As System.EventArgs) Handles
btnPrint.Click
frmReport.ShowDialog()
End Sub
Private Sub
btnClear_Click(ByVal sender As System.Object, ByVal
e As System.EventArgs) Handles
btnClear.Click
txtAddress.Clear()
txtFName.Clear()
txtLName.Clear()
txtMName.Clear()
cmbDay.Text = ""
cmbGender.Text
= "SELECT"
cmbMonth.Text =
""
cmbYear.Text = ""
End Sub
End Class
Ø Code for Report Form
//Add
Explicit On ,Click here to know what is Explicit On.
Option Explicit On
//Imports crystal
report
Imports
CrystalDecisions.CrystalReports.Engine
Public Class frmReport
//create a variable name for the report
Document. Name the report document as rptstudent.
Dim
rptstudent As New
ReportDocument
//create a variable name for the path of
Crystal report
Dim
reportpath As String
Private Sub Report_Load(ByVal
sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
loadReports()
End Sub
Sub
loadReports()
//Create Try Catch Statement for the error desplay
Try
//Create a variable name for the
TextObject of Crystal Report
//cName,cBirthDAte,cAddress and cGender is
a variable name of the textobject in Crystal Report
Dim
cName, cBirthDate, cAddress, cGender As
CrystalDecisions.CrystalReports.Engine.TextObject
reportpath =
Application.StartupPath & "\CrystalReport"
& "\Print.rpt"
rptstudent.Load(reportpath)
//ctxtName,ctxtBirthDate,
and ctxtGender it is a name of the textObject in Crystal Report
cName = rptstudent.ReportDefinition.Sections(1).ReportObjects("ctxtName")
Dim
MName As String
= Microsoft.VisualBasic.Left(frmForm.txtMName.Text, 1)
cName.Text = frmForm.txtLName.Text
& Space(1) & "," &
Space(1) & frmForm.txtFName.Text & Space(2) & MName & "."
cBirthDate =
rptstudent.ReportDefinition.Sections(1).ReportObjects("ctxtBirthDate")
cBirthDate.Text =
frmForm.cmbMonth.Text & "/"
& frmForm.cmbDay.Text & "/"
& frmForm.cmbYear.Text
cGender = rptstudent.ReportDefinition.Sections(1).ReportObjects("ctxtGender")
cGender.Text =
frmForm.cmbGender.Text
cAddress =
rptstudent.ReportDefinition.Sections(1).ReportObjects("ctxtAddress")
cAddress.Text =
frmForm.txtAddress.Text
CrystalReportViewer1.ReportSource =
rptstudent
CrystalReportViewer1.Refresh()
Catch
ex As Exception
MsgBox("DATA
ERROR" & ex.Message, MsgBoxStyle.Information)
End Try
End Sub
End Class
5th Step: Run the Program.
Ø Click to start Debugging Button (F5).
Code:
Public Class Form1
Dim n1000,
n500, n200, n100, n50, n20, n10, n5, n1 As String
Private Sub btnDenominate_Click(ByVal
sender As System.Object, ByVal e As
System.EventArgs) Handles btnDenominate.Click
n1000 = txtInputValue.Text \ 1000
n500 = (txtInputValue.Text Mod 1000) \ 500
n200 = ((txtInputValue.Text Mod 1000) Mod 500) \
200
n100 = (((txtInputValue.Text Mod 1000) Mod 500) Mod 200) \ 100
n50 = ((((txtInputValue.Text Mod 1000) Mod 500) Mod 200) Mod 100) \
50
n20 = (((((txtInputValue.Text Mod 1000) Mod 500) Mod 200) Mod 100) Mod 50) \ 20
n10 = ((((((txtInputValue.Text Mod 1000) Mod 500) Mod 200) Mod 100) Mod 50) Mod 20) \ 10
n5 = (((((((txtInputValue.Text Mod 1000) Mod 500) Mod 200) Mod 100) Mod 50) Mod 20) Mod 10) \ 5
n1 = ((((((((txtInputValue.Text Mod 1000) Mod 500) Mod 200) Mod 100) Mod 50) Mod 20) Mod 10) Mod 5) \ 1
txtResult.Text = " 1000 : " & n1000 & vbNewLine
& "
500 : " & n500 & vbNewLine & " 200 :
" & n200 & vbNewLine & " 100 : " & n100 &
vbNewLine & " 50 : " & n50 &
vbNewLine & " 20 : " & n20 &
vbNewLine & " 10 : " & n10 &
vbNewLine & " 5 : " & n5 &
vbNewLine & " 1 : " & n1
End Sub
Private Sub Form1_Load(ByVal
sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
txtResult.Text = " 1000 : " & n1000 & vbNewLine
& "
500 : " & n500 & vbNewLine & " 200 :
" & n200 & vbNewLine & " 100 : " & n100 &
vbNewLine & " 50 : " & n50 &
vbNewLine & " 20 : " & n20 &
vbNewLine & " 10 : " & n10 &
vbNewLine & " 5 : " & n5 &
vbNewLine & " 1 : " & n1
End Sub
End Class
I was so happy to read this article. Thankyou so much for good article.
ReplyDeleteWordpress Training in Chennai
Wordpress Training in T Nagar
Wordpress Training in OMR
Wordpress Training in Velachery
Wordpress Training in Tambaram
Struts Training in Chennai
Spring Training in Chennai
Hibernate Training in Chennai