|
bizjosh wrote:
how to do i read data from .txt file
The File class.
bizjosh wrote:
pass the data i.e (xx,yy,zz) into my vb .net program
If you know the file format, then you can use Convert.ToXXX to change strings to other types.
bizjosh wrote:
display the data in tables
Put it in an arraylist and use a datagrid.
Christian
I have several lifelong friends that are New Yorkers but I have always gravitated toward the weirdo's. - Richard Stringer
|
|
|
|
|
Dim reader as new System.IO.Streamreader(full file path)
'This is a serial reader, so once you iterate, you cannot go to the previous line unless you reopen the file and iterate to the patricular line number
'Say you want to read your data which is in the format xx,yy,zz
Dim str as String
Dim split_str() as String 'Dynamic String Array
str = reader.readLine() 'Assuming your data is in the first line of the file
split_str = str.split(',')
'You will get an array which made by tokenizing string using "," as the delimiter. Now split_str(0) = xx, split_str(1) = yy, split_str(2) = zz. You can further parse them to the required format that you want for further prcessing.
'Do not forget
reader.close()
Go to MSDN.com and verify the syntax for String.split(args[]). The context is the same but the delimiter might be a char or string or ASCII code, you might wanna verify that. I think that should help you get started on reading text files.
|
|
|
|
|
I'm not sure i understand 100% what you are wanting to do, but if you want to read .txt (.csv, etc) file and place the data in a data grid, this is one way to do it.
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim data_table As New DataTable("Contacts")
' Define the columns.
data_table.Columns.Add("Last Name", GetType(String))
data_table.Columns.Add("First Name", GetType(String))
data_table.Columns.Add("Phone Number", GetType(String))
data_table.Columns.Add("Email Address", GetType(String))
' Create some data.
AddTableRow(data_table, "Jackson", "Jennie", "787-878-8263", "JennieJackson@nowhere.com")
AddTableRow(data_table, "Kevlar", "Kurt", "872-348-7263", "kurtk@militant.com")
AddTableRow(data_table, "Llama", "Linda", "", "lllama@weaver.com")
AddTableRow(data_table, "Mandrake", "Marcus", "398-787-4764", "marcus@marcusrocks.com")
' Bind the DataTable to the DataGrid.
dgContacts.DataSource = data_table
End Sub
Private Sub AddTableRow(ByVal data_table As DataTable, ByVal last_name As String, ByVal first_name As String, ByVal phone_number As String, ByVal email_address As String)
Dim data_row As DataRow
data_row = data_table.NewRow()
data_row.Item("Last Name") = last_name
data_row.Item("First Name") = first_name
data_row.Item("Phone Number") = phone_number
data_row.Item("Email Address") = email_address
data_table.Rows.Add(data_row)
End Sub
If you are using a datagrid you have to give it some fieldname info and that is what the first section (Define the columns) is for.
If this isn't what you are looking for, then there is a way you can use a SQL Text Driver and process your .txt file with an SQL table. Let me know if you think that would work better and I will show you that code.
|
|
|
|
|
In .Net When you Load the Recordset to datatable.If you set source of data to controls like listbox or combobox some times the datas are not viewed instead of In control we see the form of System.Data.DataRowView(It happenes only in sometime not all time )but we can avoid it through dataview
For example
dim dt as datatable
Adapter.Fill(dt)
ComboBox.Datasource = dt
ComboBox.DisplayMember="Column1"
ComboBox.ValueMember = "Column2" // In my case Display member displays record well but problem in Valuemember only i got as system.Data.DataRowView
you can avoid this in DirectCasting of DatarowView
Otherwise
dim dv as dataview = dt.DefaultView
ComboBox.Datasource = dv
ComboBox.DisplayMember="Column1"
ComboBox.ValueMember = "Column2" // Now works fine
Otherwise you can directly give as
ComboBox.Datasource = dt.Defaultview
ComboBox.DisplayMember="Column1"
ComboBox.ValueMember = "Column2" // Now works fine
I dont know why its happened,If anybody knows ,Let inform here
Rugfy
|
|
|
|
|
Hi,
I have created a Windows UserControl. This Control hosts a PropertyGrid and a Button control. The UserControl
project also includes a class called "TestClass" and a custom TypeConvertor class called "DDConv".
When the user clicks on the Button control, the application assigns an instance of "TestClass" to the PropertyGrid.
The "TestClass" has a property called "CustProp" and it has an TypeConverter attribute assigned to
the "CustProp" property. The TypeConvertor points to the "DDConv" class.
The PropertyGrid in the UserControl displays a DropDown against the "CustProp" property when the UserControl is
hosted in a windows application.
When the UserControl is hosted in Internet Explorer, the PropertyGrid does NOT SHOW any DropDown for the "CustProp"
property.
NOTE: I test the UserControl in Internet Explorer from a virtual directory on my machine. I have set "FullTrust" for
the "LocalIntranet_Zone" on my machine.
I want the PropertyGrid to display the DropDown in Internet Explorer - can someone help me in figuring out how to
acheive the same?
<br />
'TestClass.vb<br />
Public Class TestClass<br />
Dim _name As String<br />
Dim _ddProp As String<br />
<br />
Public Property Name() As String<br />
Get<br />
Return _name<br />
End Get<br />
Set(ByVal Value As String)<br />
_name = Value<br />
End Set<br />
End Property<br />
<br />
<System.ComponentModel.TypeConverter(GetType(DDConv))> _<br />
Public Property CustProp() As String<br />
Get<br />
Return _ddProp<br />
End Get<br />
Set(ByVal Value As String)<br />
_ddProp = Value<br />
End Set<br />
End Property<br />
<br />
End Class<br />
<br />
'DDConv.vb<br />
Public Class DDConv<br />
Inherits System.ComponentModel.StringConverter<br />
<br />
Dim _values As String()<br />
Dim _restrictToList As Boolean<br />
<br />
Public Sub New()<br />
_values = New String() {"Yes", "No"}<br />
End Sub<br />
<br />
Public Overloads Overrides Function GetStandardValuesSupported(ByVal context As _<br />
System.ComponentModel.ITypeDescriptorContext) As Boolean<br />
<br />
Return True<br />
End Function<br />
<br />
Public Overloads Overrides Function GetStandardValues(ByVal context As System.ComponentModel.ITypeDescriptorContext) _<br />
As System.ComponentModel.TypeConverter.StandardValuesCollection<br />
<br />
Return New StandardValuesCollection(_values)<br />
<br />
End Function<br />
<br />
Public Overloads Overrides Function GetStandardValuesExclusive(ByVal context As _ <br />
System.ComponentModel.ITypeDescriptorContext) As Boolean<br />
<br />
Return _restrictToList<br />
End Function<br />
End Class<br />
Thanks & Regards,
Dhwanil Shah
dhwanil.shah@patni.com
|
|
|
|
|
Hi,
I "discovered" what was wrong with this - somehow IE was "looking" for the dll which had the TypeConverter - even when that was the DLL which exposed the UserControl that IE was hosting.
When the PropertyGrid tried to use a custom type converter - it tried to create an instance of a class from its fully qualified assembly name. While trying to create this instance, IE (or .NET Framework or PropertyGrid) tried to download the required DLL (again). IIS on the server kept on returning 401 (for whatever reason). That was the reason the TypeConverters were not working. I discovered all this by monitoring the requests and responses between IE and IIS (I used the Fiddler tool from Microsoft - available at http://www.fiddlertool.com)
While trying to resolve another problem in the application - I read Paul Wilsons blog at http://weblogs.asp.net/pwilson/archive/2003/05/30/8037.aspx. In that Tim Clamp gave refrence regarding how to make IE / .NET Framework understand how to locate and download the assemblies. Based on that, I was able to give IE / .NET Framework absolute location for the .DLL that was being hosted by IE.
Refrences -
1. WinForm UserControls in Internet Explorer
http://weblogs.asp.net/pwilson/archive/2003/05/30/8037.aspx
2. PRB: Runtime Probe Causes a Delay When You Load a Windows Forms Control in Internet Explorer
http://support.microsoft.com/default.aspx?scid=kb;en-us;814668
Regards,
Dhwanil Shah
|
|
|
|
|
hello,
my application asks the user to enter a few words and the application arrange these words to create a 15x 15 crossword puzzle .
do you know any alogrithm that can help me to arrange the words in a way that gets the best result
|
|
|
|
|
|
I have a web system which will display a crystal report for clients. It is written in Visual Studio 2003,VB.Net and Crystal Report which comes with VS2003, running on Windows 2000. It works very well. Now we moved to Windows XP and I cannot run the report again at design time. There is no change to my code. I got the following error: The LoadSaveReportException: Load Report Error. I searched all answers through the web. It seems that the LoadSaveReportException is thrown when the report engine cannot open the report file. Is there any difference between Windows 2000 and Windows XP? How to resolve it?
Thanks.
Bing Chen
|
|
|
|
|
I am trying run a solenoid/motor using vb.net out the lpt port. I know that I have to use windows api, but do not know how to figure out to use the api. Can any one help?
|
|
|
|
|
google inpout.dll or NTPort.
Christian
I have several lifelong friends that are New Yorkers but I have always gravitated toward the weirdo's. - Richard Stringer
|
|
|
|
|
Hi,
How can I make Control Array in VB.net.
Like
TextBox1(0)
TextBox1(1)
TextBox1(2)
TextBox1(3)
TextBox1(4)
Thanks !
|
|
|
|
|
You don't. Control arrays are a thing of the past.
You can mimic them by using the Handles caluse of the event signature though. Thsi allows multiple controls to send thier events all to a common event handler.
Private Sub Button1_Click(ByVal sender As System.Object,_
ByVal e As System.EventArgs)_
Handles Button1.Click, Button2.Click, Button3.Click
Select Case DirectCast(sender, Button).Name
Case "Button1"
MessageBox.Show("Button1!")
Case "Button2"
MessageBox.Show("Button2!")
Case "Button3"
MessageBox.Show("Button3!")
Case Else
End Select
End Sub
George Carlin wrote:
"Don't sweat the petty things, and don't pet the sweaty things."
Jörgen Sigvardsson wrote:
If the physicists find a universal theory describing the laws of universe, I'm sure the a**hole constant will be an integral part of that theory.
My Blog[^]
|
|
|
|
|
'I have an example that can help you.
'Sorry, my english is bad !
'This is the file "Form1.vb"
Public Class Form1
Inherits System.Windows.Forms.Form
#Region " Windows Form Designer generated code "
Public Sub New()
MyBase.New()
'This call is required by the Windows Form Designer.
InitializeComponent()
'Add any initialization after the InitializeComponent() call
End Sub
'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer
'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
Friend WithEvents Button1 As System.Windows.Forms.Button
<system.diagnostics.debuggerstepthrough()> Private Sub InitializeComponent()
Me.Button1 = New System.Windows.Forms.Button
Me.SuspendLayout()
'
'Button1
'
Me.Button1.Location = New System.Drawing.Point(24, 320)
Me.Button1.Name = "Button1"
Me.Button1.Size = New System.Drawing.Size(80, 24)
Me.Button1.TabIndex = 0
Me.Button1.Text = "Button1"
'
'Form1
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(400, 357)
Me.Controls.Add(Me.Button1)
Me.Name = "Form1"
Me.Text = "Form1"
Me.ResumeLayout(False)
End Sub
#End Region
Private Sub Form1_Activated(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Activated
' MsgBox("OK")
' Dim V(0) As Windows.Forms.Button
'With V(0)
'.Size = New System.Drawing.Size(152, 24)
'.Location = New System.Drawing.Point(64, 216)
'End With
End Sub
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
' Dim tb(2) As TextBox
For n As Integer = 0 To 2
''Crea le caselle ditesto richieste
tb(n) = New TextBox
tb(n).Size = New System.Drawing.Size(400, 30)
tb(n).Location = New System.Drawing.Point(59, 40 + n * 40)
''Questo identifica il controllo TextBox
tb(n).Name = CStr(n + 1)
tb(n).Tag = CStr(n + 1)
tb(n).Text = CStr(n + 1)
''Viene aggiunto il controllo alla lista controlli
Me.Controls.Add(tb(n))
''Crea i gestori d''evento
'AddHandler tb.KeyPress, AddressOf TextBox_KeyPress
AddHandler tb(n).TextChanged, AddressOf TextBox_TextChanged
'AddHandler tb.MouseEnter, AddressOf TextBox_MouseEnter
'AddHandler tb.MouseLeave, AddressOf TextBox_MouseLeave
Next
End Sub
Private Sub TextBox_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs)
Dim s As String
s = sender.tag
CiSono(s)
End Sub
End Class
'This is the file "Module1.vb"
Module Module1
Public tb(2) As TextBox
Public Sub CiSono(ByRef s As String)
MsgBox(s)
End Sub
End Module
|
|
|
|
|
hello!
any know how to color the items of a combobox?
thanks
wilson
|
|
|
|
|
You have to handle the DrawItem event of the ComboBox:
DrawItemEventArgs[^]
The example is for a ListBox, but the theory is exactly the same.
Hope this helps
Tom
|
|
|
|
|
thanks tom.
i'm beginner in vb.net and in the sample i don't understant where put the code...
please help me.
thanks
wilson
|
|
|
|
|
Hi all,
Can anybody let me know how to change the column name of datagrid.
It displays the same name as per in table.
I want to change it.
let Emp_Code is the column name in table and I want the column name as Employee Code to be displayed.
Please help.
Suman Singh
|
|
|
|
|
It is possible through SQL query. Use 'ALias' command of sql.
example
select 'FirstName'=au_fname,'LastName'=au_lname from authors
use this query, hope you understand it.
au_fname and au_lname are column names, where as 'First Name' and 'Last Name' are fake names.
bye
EsHbAn BaHaDuR
|
|
|
|
|
I attach a text box on form. user has to enter date in that text box. How can i set the format mask for date like dd:mm:yyyy
EsHbAn BaHaDuR
|
|
|
|
|
The standard TextBox control doesn't support masked editing. You have to use the old ActiveX MaskedEdit control for this. A reference for which you can find here[^] on MSDN.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Here's instruction for including the control in your project: [^]
Are you familiar with the MaskedEdit control in VB6? It's just about the same. If you aren't familiar, then you can Google it or look further on vbcity.com, just remember you are looking for VB6 instructions, not VB.NET.
|
|
|
|
|
I want to select some data from database and display it in DATAGRID control, how can i use it without using "Data Adapter" and "DataSET" objects
EsHbAn BaHaDuR
|
|
|
|
|
I don't think you can do it without the two, if you are using database.
Please wait for another reply.
|
|
|
|
|
How else are you going to get the data out of the database?
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|