|
The variable A should be a string type. Also your String.Format statement is incorrect, but also unnecessary. Try
Dim tempStr As String
tempStr = TextBox1.Text
TextBox1.Text = TextBox2.Text
TextBox2.Text = tempStr
|
|
|
|
|
This might be a little late but still good for educational value.
All the suggestions are perfectly correct and easy to read when inspecting the code.
However there is one other way of doing this without declaring any additional variables like:
Dim txtA as string
Dim txtB as string
Each control has a "Tag" property that you can use to store any type of text.
Therefore you can write the following code without declaring any additional variables.
In your "Form_Load"
txtA.Tag = txtA.text
txtB.Tag = txtB.text
In the Button_Click event of the Swop Button you write:
txtA.text = txtB.Tag
txtB.text = txtB.Tag
The "Tag" property has many uses, this is but one possible use to keep from declaring too many variables for silly little tasks while you have other places to store relevant data.
Regard,
Tino
"Plan your work, Work your plan"
|
|
|
|
|
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") >>>>>>>> the program is running i can import test.csv file but in c: drive i want any .csv file import to the program ("c://*.csv) command is not runnig. pls help can u give me an example??
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
|
|
|
|
|
sensizbenlik wrote: can u give me an example
If you had gone and looked at the DirectoryInfo Class[^] just like you was told to here[^] you would have found the DirectoryInfo.GetFiles[^] method that provides you an example for what you want to do.
|
|
|
|
|
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.
|
|
|
|
|