|
Do some research, you have been given the pointers to where to look. No one is going to write your code for you...
Here is some pseudo code. Split the parsing code into a new method.
get the directory info
for each of the fileinfo in the directoryinfo
pass the fileinfo to the parsing function.
Now go write your code.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
hello
Dim parser As New FileIO.TextFieldParser("c://test.csv")
i can import a csv file like this code
but
i want to import all csv files in c: driver to database
Dim parser As New FileIO.TextFieldParser("c://*.csv")is not working
pls help
|
|
|
|
|
|
 thanks for replying i look the web site but icant do . .
i have a project. a machine system always reports in csv file to c: folder.but every time it reports different csv file .so i have to take from c: all csv files that s my code
Imports System.IO
Imports System.IO.File
Imports System.Data
Imports System.Data.SqlClient
Public Class Form1
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim table As New DataTable
table.Columns.Add("ZipCode")
table.Columns.Add("State")
table.Columns.Add("City")
Dim parser As New FileIO.TextFieldParser("C//:test.csv") (in here i want from visualbasic that it has to search csv files in c: and paste into to program)
parser.Delimiters = New String() {";"}
parser.HasFieldsEnclosedInQuotes = True
parser.TrimWhiteSpace = True
parser.ReadLine()
Do Until parser.EndOfData = True
table.Rows.Add(parser.ReadFields())
Loop
Dim Sql As String = "INSERT INTO tblZipCode (ZipCode,State,City) VALUES (@ZipCode,@State,@City)"
Dim SqlconnectionString As String = "Data Source=(localdb)\Projects;Initial Catalog=srkn;Integrated Security=True;Connect Timeout=15;Encrypt=False;TrustServerCertificate=False;"
Using connection As New SqlClient.SqlConnection(SqlconnectionString)
Dim cmd As New SqlClient.SqlCommand(Sql, connection) ' create command objects and add parameters
With cmd.Parameters
.Add("@ZipCode", SqlDbType.VarChar, 15, "ZipCode")
.Add("@State", SqlDbType.VarChar, 20, "State")
.Add("@City", SqlDbType.VarChar, 30, "City")
End With
Dim adapter As New SqlClient.SqlDataAdapter()
adapter.InsertCommand = cmd
'--Update the original SQL table from the datatable
Dim iRowsInserted As Int32 = _
adapter.Update(table)
End Using
End Sub
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
End Sub
End Class
|
|
|
|
|
You have worked out how to loop through the parsed data now apply that to the directory's files. User System.IO.DirectoryInfo and get all the files in the folder and put this (and the rest of the processing) insode that loop.
sensizbenlik wrote: Dim parser As New FileIO.TextFieldParser("C//:test.csv") (in here i want from visualbasic that it has to search csv files in c: and paste into to program)
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
pls give an example on my code via User System.IO.DirectoryInfo.
|
|
|
|
|
|
Hello Guys,
I need to logout user while closing all open forms and reopen the login form.
I did the following:
(Main Form)
Private Sub btnLogout_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLogout.Click
LoginForm.Close()
LoginForm.Dispose()
LoginForm = Nothing
ModuleLoad.LoginForm_Load()
End Sub
(Login Form)
Private Sub LoginForm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'Close all the forms but Login form
For i As Integer = My.Application.OpenForms.Count - 1 To 0 Step -1
If My.Application.OpenForms.Item(i) IsNot Me Then
My.Application.OpenForms.Item(i).Close()
End If
Next i
Exit sub
---------------------------------------------------------------
I get an error on ModuleLoad.LoginForm_Load() stating LoginForm_Load() is not a member of System.ModuleHandle..
I tried a number of declarations , no luck..
Guy me on this one.
Thanks
|
|
|
|
|
What code is executed in the ModuleLoad? And can you show us how the Program-entry point?
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Thanks for reply,
That is my problem..
I have put this code:
<ComVisibleAttribute(True)>
Public Structure ModuleHandle
Share Sub LoginForm_Load()
End Sub
End Structure
--------
I want the loginForm to reload so the user can login
Thanks again
|
|
|
|
|
waner michaud wrote: I want the loginForm to reload so the user can login If the main-form closes, (as in, "all forms"), the application closes.
That raises another problem; how does one close your application? By closing the loginform? If yes, then the login-form would be the mainform, hidden when someone logs in, closes if someone cancels the login.
Alternatively, you can control the exit of the application by adding an explicit entry point (or does the IDE generate one nowadays?) Add a module like below;
Module Module1
Sub Main()
Using loginForm As New LoginForm()
While loginForm.ShowDialog() <> DialogResult.Cancel
Using mainForm As New MainForm()
MainForm.ShowDialog()
End Using
End While
End Using
End Sub
End Module Next, open the projects' properties (right click in solution explorer, or using the main menu), go to tab "Application" and play a bit with the "Shutdown mode" setting. Uncheck "Enable application framework", and change the "Startup object" (on the same tab, was called "Startup form" before the uncheck) to "Module1".
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Hello again,
Thanks for your response.
I have an exit button that closes the application completely. But what I want is to log out button that will log out the current user and allow a new user to log in.
Basically that's what I want to accomplish.
Thanks again
|
|
|
|
|
That's what the example does, albeit you'll need to modify your own app.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Hello all i am new to this language and i have ported my code from vb6 to vb.net and getting this issue.
I am getting the error in this code line=
mvarTimer = frmMain.Controls.Add("VB.Timer", strTemp)
I dont understand how to fix this issue ,i am helpless
Any one here please help me i will be thankful to you
<pre> Public Function fnInitializeTimer() As Object
Dim strTemp As String
'we need unique name for timer hence appended the number of control to the name
'UPGRADE_WARNING: Controls method Controls.Count has a new behavior. Click for more: 'ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?keyword="6BA9B8D2-2A32-4B6E-8D36-44949974A5B4"'
strTemp = "Timer" & frmMain.Controls.Count() + 1
'Initialize the timer variable
'UPGRADE_ISSUE: Controls method Controls.Add was not upgraded. Click for more: 'ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?keyword="CC4C7EC0-C903-48FC-ACCC-81861D12DA4A"'
'mvarTimer = frmMain.Controls.Add("VB.Timer", strTemp)
mvarTimer = frmMain.Controls.Add("VB.Timer", strTemp)
mvarTimer.Enabled = False
End Function
|
|
|
|
|
|
If you've got this many errors it can be considered a barometer of how badly the original code was written.
The best way to solve this problem is to scrap it all and rewrite. That way, you're not forcing VB.NET to try and emulate the bad behavior of VB6 and the code written in it.
|
|
|
|
|
Hello guys i have converted one old vb6 code to vb .net and i getting the above mentioned error. Please help me i don't know about this. I will be thankful to you!
here is the code which is showing the error
frmMain.listStringReplace.Items.Item(nItemIdex).SubItems.Add(1, , strStringToBeReplaced)
frmMain.listStringReplace.Items.Item(nItemIdex).SubItems.Add(2, , strImagePath)
If frmMain.optReplace.Checked = True Then
frmMain.listStringReplace.Items.Item(nItemIdex).SubItems.Add(3, , "Replace")
ElseIf frmMain.optAppend.Checked = True Then
<big>frmMain.listStringReplace.Items.Item(nItemIdex).SubItems.Add(3, , "Append")</big>
ElseIf frmMain.optPrePend.Checked = True Then
frmMain.listStringReplace.Items.Item(nItemIdex).SubItems.Add(3, , "Prepend")
End If
|
|
|
|
|
|
Thanks for the reply but can you please suggest me few lines of code as i have visited that page but still not able to correct my error
|
|
|
|
|
Look at your call to Add and you can see that it tries to use 3 parameters SubItems.Add(1, , strStringToBeReplaced) , even though the second one is missing. Now look at the documentation and you can see that there is no overload of the Add method that takes this number. You can use one of
Add(ListViewItem.ListViewSubItem)
Add(String)
Add(String, Color, Color, Font)
If your call does not match one of these methods then the compiler will reject it.
|
|
|
|
|
|
Hi All,
Please find my code below to read the output of two independent temperatures streams.
The form now works well but I cannot close the form when I use the button btnDisconnect_Click at the bottom of the code. The only way I can stop the code is by the stop debugging.
Please can you help
Thank you in advance
Nevjc
Imports System.Drawing.Drawing2D
Imports System.IO.Ports
Public Class Form1
Dim bmp1 As Bitmap = New Bitmap(165, 550)
Dim temperature1 As Double = 10
Dim temperature2 As Double = 10
Dim WithEvents sp As New SerialPort
Private Sub pictherm1_Paint(ByVal sender As System.Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles pictherm1.Paint
Dim g As Graphics = e.Graphics
g.Clear(Color.White)
If temperature1 > 100 Then temperature1 = 100
g.FillRectangle(Brushes.Green, 48, 525 - CInt(temperature1 * 5), 10, CInt(temperature1 * 5))
If temperature2 > 100 Then temperature2 = 100
g.FillRectangle(Brushes.Green, 108, 525 - CInt(temperature2 * 5), 10, CInt(temperature2 * 5))
g.DrawLine(Pens.Black, 60, 525, 60, 25)
g.DrawLine(Pens.Black, 105, 525, 105, 25)
For i As Integer = 25 To 525 Step 5
g.DrawLine(Pens.Black, 50, i, 60, i)
g.DrawLine(Pens.Black, 105, i, 115, i)
Next
Dim f As Font = New Font("Verdana", 10, FontStyle.Regular)
Dim scale As Integer
For i As Integer = 525 To 25 Step -25
g.DrawLine(Pens.Black, 45, i, 60, i)
g.DrawLine(Pens.Black, 105, i, 120, i)
scale = (525 - i) / 5
g.DrawString(Str(scale), f, Brushes.Black, 65, i - 8)
Next
End Sub
Private Sub btnConnect_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnConnect.Click
Try
sp.BaudRate = "9600"
sp.PortName = "COM5"
sp.Open()
If sp.IsOpen Then
btnConnect.Visible = False
btnDisconnect.Visible = True
End If
Catch
sp.Close()
End Try
End Sub
Private Sub Form1_FormClosing(ByVal sender As System.Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles MyBase.FormClosing
If sp.IsOpen() Then
MessageBox.Show("Disconnect before closing")
e.Cancel = True
End If
End Sub
Delegate Sub myMethodDelegate1(ByVal [text] As String)
Dim myDelegate1 As New myMethodDelegate1(AddressOf ProcessReading1)
Private Sub SerialPort_DataReceived1(ByVal sender As Object, ByVal e As System.IO.Ports.SerialDataReceivedEventArgs) Handles sp.DataReceived
Dim str1 As String = sp.ReadLine()
Dim firststr As String = Mid(str1, 1, 4)
Invoke(myDelegate1, firststr)
End Sub
Sub ProcessReading1(ByVal input As String)
If IsNumeric(input) Then
temperature1 = CDbl(input)
lblLeft.Text = CDbl(temperature1)
pictherm1.Refresh()
End If
End Sub
Delegate Sub myMethodDelegate2(ByVal [text] As String)
Dim myDelegate2 As New myMethodDelegate2(AddressOf ProcessReading2)
Private Sub SerialPort_DataReceived2(ByVal sender As Object, ByVal e As System.IO.Ports.SerialDataReceivedEventArgs) Handles sp.DataReceived
Dim str2 As String = sp.ReadLine()
Dim secondstr As String = Mid(str2, 6, 5)
Invoke(myDelegate2, secondstr)
End Sub
Sub ProcessReading2(ByVal input As String)
If IsNumeric(input) Then
temperature2 = CDbl(input)
lblRight.Text = CDbl(temperature2)
lblTotal.Text = CDbl(temperature1 + temperature2)
lblDiff.Text = CDbl(temperature1 - temperature2)
pictherm1.Refresh()
End If
End Sub
Private Sub btnDisconnect_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDisconnect.Click
Try
sp.Close()
btnConnect.Visible = True
btnDisconnect.Visible = False
Exit Sub
Catch
MessageBox.Show("Some kind of problem.")
End Try
End Sub
End Class
|
|
|
|
|
What about this.Close(); or Application.Exit(); ?
|
|
|
|
|
Hi Berhard,
Thankyou for the suggestion. Both those work when you have just opened the form but as soon as you start reading the serial port they dont work. It appears that the infomation from the serial port is holding the form open.
Any other suggestions?
Regards
Nevjc
|
|
|
|
|
I would try the following modifications to the DataReceived event handlers
Private Sub SerialPort_DataReceived1(ByVal sender As Object, ByVal e As System.IO.Ports.SerialDataReceivedEventArgs) Handles sp.DataReceived
Try
Dim str1 As String = sp.ReadLine()
Dim firststr As String = Mid(str1, 1, 4)
Invoke(myDelegate1, firststr)
BeginInvoke(myDelegate1, firststr)
Catch ioex As IOException
System.Diagnostics.Debug.Print("IOException {0}", ioex.Message)
EndTry
End Sub
If ReadLine is blocked waiting for data then issuing a Close request on the SerialPort will cause an IOException to be thrown with the message "Serial port is Closed". I don't know if that will be causing a problem but the Try.. Catch will let you see what's happening.
Replacing Invoke with BeginInvoke can only do good as it will allow the UI thread to invoke the delegate when it is not busy. If the problem is a deadlock then this change will definitely help.
Alan.
|
|
|
|
|