I need to print 2 invoice copies; one for the customer and one for the counter. I'm using Crystal Report 8 with Vb.Net 2005. Can anyone give me a direction for this?
I have tried this, but nothing happens. DT is my datatable
Dim x As New crptInvoice
x.SetDataSource(DT)
x.PrintToPrinter(2, True, 1, 2)
crptViewer.ReportSource = x
crptViewer.Refresh()
Use PrinttoPrinter to specify N Copies of report to print
rptDoc.PrintToPrinter(2, True, 1, 1)
which reads as:
2 = nCopies as integer
True = collated as Boolean
1 = StartpageN as integer
1 = EndpageN as Integer
also, your line
crptViewer.ReportSource = x
crptViewer.Refresh()
is used if you want your report to be viewed using a reportViewer hence the name crptViewer
while PrinttoPrinter automatically sends your report to the print queue
Related
So here is my situation. I have a DataGridView, which has two columns that I am trying to set up as DataGridViewComboBoxColumns called "Received" and "Backordered".
The point of these combo boxes is to create a drop down menu to select how many items are received/backordered when my company receives a shipment. This program will mainly be run on a touch screen setup with no mouse or keyboard, which is why I am opting to use Combo Boxes as opposed to just asking for general user input.
I am attempting to set up the DataGridView as follows:
'Setup of Combo Box Columns
'shipmentData is the name of the DataGridView
Dim receiveCol As New DataGridViewComboBoxColumn()
receiveCol.HeaderText = "Received"
receiveCol.Name = "Received"
shipmentData.Columns.Add(receiveCol)
Dim backorderCol As New DataGridViewComboBoxColumn()
backorderCol.HeaderText = "Backordered"
backorderCol.Name = "Backordered"
shipmentData.Columns.Add(backorderCol)
The above code is in the New() Sub for when the form is created. I am trying to load the data into the ComboBoxes as follows:
Dim rowNum As Integer = 0
For Each op As OrderPart In OrderData.GetPartList()
If op.AmountOrdered > 0 Then
shipmentData.Rows.Add()
shipmentData.Rows(rowNum).Cells("PartNumber").Value = op.PartNumber
shipmentData.Rows(rowNum).Cells("Description").Value = op.Description
shipmentData.Rows(rowNUm).Cells("Ordered").Value = op.AmountOrdered
For it As Integer = 0 To op.AmountOrdered
CType(shipmentData.Rows(rowNum).Cells("Received"), DataGridViewComboBoxCell).Items.Add(it)
CType(shipmentData.Rows(rowNum).Cells("Backordered"), DataGridViewComboBoxCell).Items.Add(it)
Next
rowNum = rowNum + 1
End If
Next
Now when I run the code, the ComboBoxes are created, and their data is added. However whenever I select a data value from the combo box list, and then try to move to another sell I get the following error:
System.ArgumentException: DataGridViewComboBoxCell value is not valid.
Why am I getting this error, and how do I fix it? I can't seem to figure out what it is I am doing wrong in my code.
Although I don't know why are adding incrementing numbers to your dropbox, but if you intend to do that, change your code to the following:
For it As Integer = 0 To op.AmountOrdered
CType(shipmentData.Rows(rowNum).Cells("Received"), DataGridViewComboBoxCell).Items.Add(it.ToString())
CType(shipmentData.Rows(rowNum).Cells("Backordered"), DataGridViewComboBoxCell).Items.Add(it.ToString())
Next
I have a collection of documents with different forms and need to store number of document forms in a list, the listtag would be the form name and the value how many occurances of that form was in the collection, like so:
Form Main = 20
Form Doc = 10
The following code is a start of what I am trying to do, but I need to increment the value of the element each time a new doc with an existing form take place
Dim frmList List As integer
Set ud = newdc.Getfirstdocument()
Do Until ud Is Nothing
frm = ud.Form(0)
If(IsElement(frmList(frm))) Then
frmList(frm) = 1 ' Need to increment this value with 1 if tag exist
Else
frmList(frm) = 1
End If
Set ud = newdc.Getnextdocument(ud)
Loop
if this is not possible using "lists", I need another solution
thanks
Thomas
Just write
frmList(frm) = frmList(frm) + 1
frmList(frm) gives you the current number for a form. Just increment it by one and set the new value.
I am creating a form where the input of one field is used for calculations in VBA to return a value that is inserted in another text field. I am fine up to here.
Problem is, dealing with Power numbers tend to get quite high, so my code divides Watts into Kilowatts or Megawatts depending on the value.
If the number is divided by 1,000 into kW, I would like the format of the field to be "#.##0,00 kW". If it is divided by 1,000,000 into Megawatts, the format should be "#.##0,00 MW".
Any suggestions on how to do this?
My code looks something like this (previous part is irrelevant):
Dim Module As String, Power As Integer, Technology As String, TechLong As String, NumberOfCells As Integer
Module = ActiveDocument.FormFields("ModType").Result
Power = Mid(Module, 4, 3)
Technology = Mid(Module, 9, 1)
NumberOfCells = Mid(Module, 10, 2)
' Project information
Dim NumModules As Long, ProjectSize As Long, PowerField As FormField
NumModules = ActiveDocument.FormFields("ModNum").Result
ProjectSize = NumModules * Power
Set PowerField = ActiveDocument.FormFields("TotalPower")
If ProjectSize < 1000000 Then
'Change W to kW
PowerField.Result = ProjectSize / 1000
Else
'Change W to MW
PowerField.Result = ProjectSize / 1000000
End If
Thanks!
My suggestion is to break the number and power label into two separate form fields. Deactivate the "Fillin enabled" property of the power label so that the user can't change it.
Even though the user can't change the content of the "label", your code can.
This approach allows you to leave the number formatting of the power amount field alone. Changing the number format setting using your code would mean unprotecting then re-protecting the form document. It's always better to avoid that step if at all possible.
So assuming the form field for the power label is named PowerLabel your code could look like this:
PowerLabel = ActiveDocument.Formfields("PowerLabel")
If ProjectSize < 1000000 Then
'Change W to kW
PowerField.Result = ProjectSize / 1000
PowerLabel.Result = "Kw"
Else
'Change W to MW
PowerField.Result = ProjectSize / 1000000
PowerLabel.Result = "Mw"
End If
Im modifying the question that I have already posted. My requirement is very simple.
DEFECT_ID LOG_TIME STATUS
1001 08/22/2012 12:03:34 Open
1001 08/22/2012 12:03:35 Pending
1001 08/23/2012 02:13:46 Fixed
1001 08/23/2012 22:34:37 TestReady
1001 08/24/2012 12:34:43 Pending
1001 08/24/2012 19:13:39 Retest
1001 08/25/2012 22:13:40 Reopen
1001 08/26/2012 10:03:41 Retest
1001 08/27/2012 11:13:42 Closed
The above mentioned format is my 'Source' data. There will be 100s of such defects. As you can see, all the above log date and statuses belong to one single Defect_ID(1001).My actual work is I have to copy the above data into a new sheet in format that helps me to calculate the time difference between the statuses. To your attention, there are 'Eight' defect statuses: Open, Pending,Review,TestReady,Fixed,Retest,Reopen,Closed.And these defect statuses can occur more than one time in a single defect(As shown in above example, 'Pending' occurs twice. But openand closed will occur only once). Similarly there can be upto 6times a status can repeat for a Defect.So I need an output like this, where the log dates will be fitted into the corresponding statuses :
*Defect_ID* Open Pending1 Pending2...Pending6 Fixed1...Fixed6 TestReady1..Testready6 Review1..Review6 Retest1..Retest6 REopen1..REopen6 Closed
Please let me know how to post pictures. if so I can show you how exactly I need the output through VBA. Please refer my other question: 'Copying values from one column that matches a ID to a new sheet by creating new columns for eeach values through EXCEL VBA', all I need in that is, I need new columns added up for every status that is repeating. so that all my values will be into one single row.
Here is some VBA that will do what you are looking for. (If I understand the requirements correctly). It may be a bit verbose, but should be easy to maintain. There is probably a more eloquent way of doing this.
Private Sub CreateOutputSheet()
Dim iLoop, iStartRow, iEndRow As Integer
Dim iPendingCount As Integer
Dim iFixedCount As Integer
'Base Col Numbers
Const colPending As Integer = 3
Const colColFixed As Integer = 9
'.....
Dim sDefectIdCurrent As String
Dim sDefectIdPrevious As String
Dim iTargetRow As Integer
Dim sCurrentStatus As String
Dim dCurrentTime As Date
sDefectIdPrevious = Sheets("Soure").Cells(intstartRow, 1)
sDefectIdCurrent = Sheets("Soure").Cells(intstartRow, 1)
For iLoop = iStartRow To iEndRow
sDefectIdCurrent = Sheets("Soure").Cells(iLoop, 1)
'Check the current problem
If sDefectIdCurrent <> sDefectIdPrevious Then 'Reset the col counters
iPendingCount = 0
iFixedCount = 0
'....
End If
sCurrentStatus = Sheets("Soure").Cells(iLoop, 3)
dCurrentTime = Sheets("Soure").Cells(iLoop, 2)
Select Case sCurrentStatus
Case "Open"
Sheets("Target").Cells(iTargetRow, 2) = dCurrentTime
Case "Pending"
iPendingCount = iPendingCount + 1
Sheets("Target").Cells(colPending + iPendingCount, 1) = dCurrentTime
Case "Fixed"
iFixedCount = iFixedCount + 1
Sheets("Target").Cells(colColFixed + iFixedCount, 1) = dCurrentTime
'...
Case "Closed"
Sheets("Target").Cells(iTargetRow, colClosedNo) = dCurrentTime
End Select
sDefectIdCurrent = Sheets("Soure").Cells(intstartRow, 1)
Next
End Sub
I am trying to work with taking in and parsing CSV files. Right now I have it taking in and producing something like this:
The program loads the csv and copies the data into an array as such:
ReDim strarray(num_rows, num_cols)
For x = 0 To num_rows
strline = strlines(x).Split(",")
For y = 0 To num_cols
strarray(x, y) = strline(y)
Next
Next
The CSV file data is very basic formatted with two columns and x number of rows:
212, 343
324, 232
etc. I guess my main problem is trying to perform calculations to all values in a specific column. To start I am just trying to figure out how to isolate the columns and found that by using MsgBox(strarray(x, num_cols)) it will msgbox everything in the second column twice. I just want to try and understand how I can perform a basic calculation like multiply every value in the first column by 2 and every value in the second column one by 3.
To start with: In VB arrays go from 0 to number of items minus 1. However you will have specify the maximum index, not the size:
Dim x As String() = new String(N-1) 'Where N is the number of items.
Dim y As String() = new String(MAX) 'Where MAX is the highest index.
And you have integer numbers. So you would have to declare:
Dim matrix As Integer(,) = new Integer(num_rows-1, num_cols-1)
And then fill it with:
For row As Integer = 0 To num_rows-1
Dim strline As String() = strlines(row).Split(",")
For col As Integer = 0 To num_cols-1
matrix(row, col) = Integer.Parse(strline(col))
Next
Next
Example calculation:
For row As Integer = 0 To num_rows-1
matrix(row,0) *= 2
matrix(row,1) *= 3
Next