|
You can use “split” to split the string at desired character and then use mid to get the desired result
A sample code is written bellow.
You have to tweak the codes for exact requirements
Just create a Project on the form create a button named button1 and past the code in the form1 class
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim str_temp As String
Dim str_spliter As Object
str_temp = "F:\folder1\aaaa.exe"
str_spliter = Split(str_temp, "\")
MsgBox(Mid(str_spliter(2), 1, (Len(str_spliter(2)) - 4)))
End Sub
Good luck...
|
|
|
|
|
Hi I've got a datagrid bound and wish to print the details in black and white.
I've downloaded the datagridviewprintclass and the example code shows
dim frm as new frmPrint.
However, frmPrint is not a recognised type when I declare it.
Please help I've been trying to work this out for 3 days now
Nala
|
|
|
|
|
Your best source of information on that class is going to be whoever wrote it.
But, that line of code looks like it has nothign to do with that class. It's actually instantiating a new form, called frmPrint, which you haven't created in your project.
|
|
|
|
|
Hi Dave
Thanks alot for that. Have you any other ideas for printing contents of a datagrid. I understand it's quite complicated.
So far I've got the following code:
Private PrintFeeding As DataGridViewPrint
Private Sub btnPrint_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnPrint.Click
Dim fpr As New frmprint('COMING UP AS ERROR')
PrintFeeding = New DataGridViewPrint(PrintDocument1, dtgrdFeeding, True)
PrintDocument1.Print()
End Sub
Private Sub PrintDocument1_PrintPage(ByVal sender As Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage
e.HasMorePages = True
e.Cancel = True
End Sub
Private Sub btnPageSetup_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnPageSetup.Click
PageSetupDialog1.Document = PrintDocument1
PageSetupDialog1.ShowDialog()
End Sub
Private Sub btnPreview_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnPreview.Click
PrintFeeding = New DataGridViewPrint(PrintDocument1, dtgrdFeeding, True)
PrintPreviewDialog1.Document = PrintDocument1
PrintPreviewDialog1.ShowDialog()
End Sub
'(CODING IN EXAMPLE)'
'Private Sub btnPrint_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPrint.Click
' Dim fpr As New frmPrint()
' With fpr
' .Title = DataGridView1.CaptionText
' .ShowDialog()
' If .Result > 0 Then
' PrintGrid = New DataGridViewPrint(PrintDocument1, DataGridView1, .bBlackWhite)
' PrintGrid.PrintTitle = .bTitle
' PrintGrid.Title = .Title
' Select Case .Result
' Case 1 ' Print
' If PrintDialog1.ShowDialog() = DialogResult.OK Then PrintDocument1.Print()
' Case 2 ' Page Setup
' PageSetupDialog1.ShowDialog()
' Case 3 ' Preview
' PrintPreviewDialog1.Icon = fpr.Icon
' PrintPreviewDialog1.ShowDialog()
' End Select
' End If
' End With
'End Sub
Thanks
Nala
|
|
|
|
|
From the code you've posted, including the sample, it looks like you already having everything in place. That line of code that fails is instantiating a form that you don't have in your project. Since you rewrote the code, you don't even that line, so remove it.
|
|
|
|
|
I have a datagrid with textboxes below that are populated depending on whether a checkbox in column one is checked or not. My problem is that I want the first row to be selected as soon as the screen containing the grid is shown. Also, when switching to new row and changing check status results are not shown until I leave row and re-enter.
I am sure these are one in the same but not sure.
|
|
|
|
|
ggreekggod wrote: My problem is that I want the first row to be selected as soon as the screen containing the grid is shown.
DataGridView1.Rows(0).Selected = True
ggreekggod wrote: Also, when switching to new row and changing check status results are not shown until I leave row and re-enter.
That's because the value doesn't actually change until the cell commits the value from the control that it contains. The value in the control will not commit to the value at the cell level until the cell loses focus, either by going to another row, or by selecting the next cell in the row.
|
|
|
|
|
hi all
my code is well in all departments, but this code keeps on making nulls, even when i enter e.g "PVNTR" string that is converted auto by vb.net . here is my code. it keeps on adding nulls
Const PVNTR As Integer = 3
Const PVDIF As Integer = 2
Const Property_Category_ID As Integer = 1
Dim DIf As String = "PVDIF"
Dim PVo As String = "PV000"
Dim NTR As String = "PVNTR"
Select Case txtfunckey.Text.Substring(1, 5)
Case Is = DIf
newRow("PROP_CATEGORY_ID") = PVDIF
Case Is = PVo
newRow("PROP_CATEGORY_ID") = Property_Category_ID
Case Is = NTR
newRow("PROP_CATEGORY_ID") = PVNTR
Case Else
newRow("PROP_CATEGORY_ID") = DBNull.Value
End Select
PLease help
Vuyiswa Maseko,
Sorrow is Better than Laughter, it may Sudden your Face, but It sharpens your Understanding
VB.NET/SQL7/2000/2005
http://vuyiswamb.007ihost.com
http://Ecadre.007ihost.com
|
|
|
|
|
You should use Debug.write to find out what txtfunckey.Text.Substring(1, 5) really is
|
|
|
|
|
THANKS
Previously my code was like this
If txtfunckey.Text.Substring(1, 5).StartsWith("PV000") Then
newRow("PROP_CATEGORY_ID") = Property_Category_ID
Debug.Write(txtfunckey.Text.Substring(1, 5))
' Later Provision for PVNTR001
ElseIf txtfunckey.Text.Substring(1, 5) = "PVDIF" Then
newRow("PROP_CATEGORY_ID") = PVDIF
Debug.Write(txtfunckey.Text.Substring(1, 5))
ElseIf txtfunckey.Text.Substring(1, 5) = "PVNTR" Then
Debug.Write(txtfunckey.Text.Substring(1, 5))
newRow("PROP_CATEGORY_ID") = PVNTR
Else
MessageBox.Show("The was no Provision for this Functional, Ask Vuyiswa Add Provision for IT", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Information)
newRow("PROP_CATEGORY_ID") = DBNull.Value
Debug.Write(txtfunckey.Text.Substring(1, 5))
End If
so i decided to add case's , mybe the nested If's caused this . but i will try to Debug.
thanks
Vuyiswa Maseko,
Sorrow is Better than Laughter, it may Sudden your Face, but It sharpens your Understanding
VB.NET/SQL7/2000/2005
http://vuyiswamb.007ihost.com
http://Ecadre.007ihost.com
|
|
|
|
|
You are using txtfunckey.Text.Substring(1, 5).
If your string starts with the values you state above you will always leave out the first character of your comparison and you will be including what ever character comes next. If txtfunckey.text is 5 characters or shorter you will get a System.ArgumentOutOfRangeException
|
|
|
|
|
I've never seen a case block like that, is that VB.NET syntax ?
YOu should set a default. You should also trace through to see what the values are when you get a null ( add a default and set a breakpoint there is a good way to do this )
Christian Graus - Microsoft MVP - C++
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
I am writing data to a text file and have a field that repeats. I only need/want the first instance of the data. This is may sql statement:
mySelectQuery = " "
mySelectQuery = mySelectQuery & "SELECT ARInvoice.InvoiceNo, ARInvoice.MonthBegBal, ARInvoice.MonthActivity, ARInvoice.OriginalAmount,
mySelectQuery = mySelectQuery & "ARInvoice.InvoiceDate, ARCustomer.ID, ARInvoice.PONumber, ARInvoice.DueDate, ARTerms.Description, "
mySelectQuery = mySelectQuery & "ARInvoice.OurOrderNumber, ARInvoice.Type, ARInvoice.SalesTax1Amt, ARInvoice.SalesTax2Amt, "
mySelectQuery = mySelectQuery & "ARInvoice.SalesTax3Amt, ARInvoice.FreightCharges, ARInvoice.Status, ARCustomer.CurOpenCredits "
mySelectQuery = mySelectQuery & "FROM ARTerms RIGHT JOIN (ARCustomer INNER JOIN ARInvoice ON ARCustomer.SKARCustomer = ARInvoice.FKARCustomer) ON ARTerms.SKARTerms = ARInvoice.TermsCode "
mySelectQuery = mySelectQuery & "WHERE (((ARInvoice.Status)=0))Order By ARCUSTOMER.ID"
ARCustomer.CurOpenCredits is the field that repeats. So the results (I have condensed) of my text file look like:
27312 460640.89 6/18/2007 BLACKWARRIOR CT0603 7/18/2007 11839.14
26936 14721.37 1/29/2007 BLACKWARRIOR 8-1082 2/28/2007 11839.14
27313 5575.68 6/18/2007 BLACKWARRIOR CTD-1600 7/18/2007 11839.14
I would want it to be: (notice that the 11839.14 appears only one time instead of three times)
27312 460640.89 6/18/2007 BLACKWARRIOR CT0603 7/18/2007 11839.14
26936 14721.37 1/29/2007 BLACKWARRIOR 8-1082 2/28/2007
27313 5575.68 6/18/2007 BLACKWARRIOR CTD-1600 7/18/2007
My code to write to the file looks like:
While myReader.Read()
field(0) = myReader.Item(0)
field(1) = "Sage-Rolligon"
field(2) = Math.Round(Convert.ToDouble((myReader.Item(1) + myReader.Item(2))), 4).ToString("###0.00")
field(3) = Math.Round(Convert.ToDouble(myReader.Item(3)), 4).ToString("###0.00")
field(4) = myReader.Item(4)
field(5) = " "
field(6) = " "
field(7) = myReader.Item(5)
field(8) = myReader.Item(6)
field(9) = myReader.Item(7)
field(10) = Convert.ToString(myReader.Item(8))
field(11) = " "
field(12) = Convert.ToString(myReader.Item(9))
field(13) = " "
field(14) = myReader.Item(10)
field(15) = " "
field(16) = Date.Today
field(17) = Math.Round(Convert.ToDouble((myReader.Item(11) + myReader.Item(12) + myReader.Item(13))), 4).ToString("###0.00")
field(18) = Math.Round(Convert.ToDouble(myReader.Item(14)), 4).ToString("###0.00")
field(19) = " "
field(20) = " "
field(21) = myReader.Item(16)
If field(14) = "1" Then
field(14) = "I"
End If
objStreamWriter.WriteLine(String.Join(ControlChars.Tab, field))
End While
Thanks in advance for any assistance!
STEPHANIE
|
|
|
|
|
Well, you've got nothing in your While loop that tracks what the current value is. If the one you just read is the same as the value you're tracking, you just don't put anything in that field. If it's different, then you put that value in the field and make the new value to current tracking value.
|
|
|
|
|
I tried an if statement with no luck. Can you give me a little more info as to how to track what the current value is?
Thanks!
Stephanie
|
|
|
|
|
If trackingValue <> rowValue Then
field(whatever) = rowValue.ToString()
trackingValue = rowValue
Else
field(whatever) = ""
End If
|
|
|
|
|
I'm somewhat inexperienced/new in this area and while I totally understand the concept here, the execution is another story. This is what I understand. My value (in this case the "current open credit amount" is "held" or "stored" in myReader.Item(16). I'm setting the field(21) equal to myReader.Item(16) and then writing it the text file.
I know or think I know that I need to check what that value is and if it IS equal to the value in the "row" before then I want it print nothing in the text file. If it is NOT equal to the value in the "row" before then I want it to print as it is.
Please don't laugh... this is an excerpt of the code:
<br />
field(20) = " "<br />
Credits = myReader.Item(16)<br />
<br />
If credits <> rowvalue Then<br />
field(21) = rowvalue.ToString()<br />
credits = rowvalue<br />
<br />
Else<br />
field(21) = ""<br />
End If <br />
I get an
'System.NullReferenceException - Object reference not set to an instance of an object.' error. This happens when it actually encounters a number. Thank you for all of your help!!
Stephanie
|
|
|
|
|
On which line does this happen?? This exception pops up when you try to use an object that is actually Nothing instead of an instance of something.
|
|
|
|
|
On
credits = rowvalue.ToString()
I tried to set
rowvalue = String.Empty
It compiles with no errors. And, following the code it runs until it meets an actual number. And, then it throws the error. I read an article about the error that suggested using the rowvalue = string.empty. If I use this nothing writes to the text file.
Thanks!
Stephanie
|
|
|
|
|
I changed the code to
credits = myReader.Item(16)
If credits <> rowvalue Then
rowvalue = credits
field(21) = rowvalue.ToString()
Else
field(21) = ""
End If
And it appears to be working! I'm having to use sample data working from home, but will test with real data in the a.m.
Thanks for your help!!!
Stephanie
|
|
|
|
|
Im using a VB. net PL i just want to know how to customize gridview...tnx
sunshine
|
|
|
|
|
Any way you like. Do you want to change the column definitions, how it looks, if it shows edit/delete buttons, what those buttons call, or something else ?
All of these things are covered in MSDN and other articles, in detail that will help you a lot more than a forum post can hope to.
Christian Graus - Microsoft MVP - C++
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
OK. In which of the thousands of ways would you like to "customize" the DGV? Or should we just guess?
|
|
|
|
|
how can i change the color of the heading and how to change its font style
sunshine
|
|
|
|
|