Get free Visual basic 2010 source codes. Learn Visual Basic 2010 using this website.
Showing posts with label Functions. Show all posts
Showing posts with label Functions. Show all posts
Friday, October 14, 2011
Thursday, September 15, 2011
Sunday, September 11, 2011
Monday, August 1, 2011
Export Listview to CSV
If you want to export the Listview Data to CSV in Visual Basic 2010 use the function bellow:
Function ExportListview2Excel(ByVal lstview As ListView) As Boolean
Dim csvFileContents As New System.Text.StringBuilder
Dim CurrLine As String = String.Empty
For columnIndex As Int32 = 0 To lstview.Columns.Count - 1
CurrLine &= (String.Format("{0};", lstview.Columns(columnIndex).Text))
Next
csvFileContents.AppendLine(CurrLine.Substring(0, CurrLine.Length - 1))
CurrLine = String.Empty
For Each item As ListViewItem In lstview.Items
For Each subItem As ListViewItem.ListViewSubItem In item.SubItems
CurrLine &= (String.Format("{0};", subItem.Text))
Next
csvFileContents.AppendLine(CurrLine.Substring(0, CurrLine.Length - 1))
CurrLine = String.Empty
Next
Dim Sys As New System.IO.StreamWriter("C:\Test.csv")
Sys.WriteLine(csvFileContents.ToString)
Sys.Flush()
Sys.Dispose()
End Function
Function ExportListview2Excel(ByVal lstview As ListView) As Boolean
Dim csvFileContents As New System.Text.StringBuilder
Dim CurrLine As String = String.Empty
For columnIndex As Int32 = 0 To lstview.Columns.Count - 1
CurrLine &= (String.Format("{0};", lstview.Columns(columnIndex).Text))
Next
csvFileContents.AppendLine(CurrLine.Substring(0, CurrLine.Length - 1))
CurrLine = String.Empty
For Each item As ListViewItem In lstview.Items
For Each subItem As ListViewItem.ListViewSubItem In item.SubItems
CurrLine &= (String.Format("{0};", subItem.Text))
Next
csvFileContents.AppendLine(CurrLine.Substring(0, CurrLine.Length - 1))
CurrLine = String.Empty
Next
Dim Sys As New System.IO.StreamWriter("C:\Test.csv")
Sys.WriteLine(csvFileContents.ToString)
Sys.Flush()
Sys.Dispose()
End Function
Sunday, May 15, 2011
Calculate the Line Length in TextBox
Calculating the line length in textbox while you write is very easy. You have to put this code into the textbox event textchanged. To do not make mistakes i give you the code with the event.
Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged
For Each line As String In TextBox1.Lines
Label1.Text = line.Length
Next
End Sub
Friday, May 13, 2011
Clear data from all TextBoxes in the Form
If you want to clear the data from all textboxes in the form just with one click, in one button enter the code bellow:
Dim tbox As Control
For Each tbox In Me.Controls
If TypeOf tbox Is TextBox Then
tbox.Text = Nothing
End If
Next
Wednesday, May 11, 2011
Now
Return encoded value representing the current date and time!
Label1.Text = Now
TimeString
Set or return the current time from the system clock!
Label1.Text = TimeString
Label1.Text = TimeString
DateString
Set or return the current date from the system clock!
Label1.Text = DateString
Int - integer
Create integer number!
Label1.Text = CStr(Int(Rnd() * 10)) ' pick numbers
RND - random
Create random numbers!
Label1.Text = CStr(Int(Rnd() * 10)) ' pick numbers
CStr - Convert to string
Label1.Text = CStr(Int(Rnd() * 10)) ' pick numbers
Subscribe to:
Posts (Atom)