|
You can't. You can read any line you want, then you need to read the second text file, insert the line, then write the entire file. You can't just insert a line into a file.
VB2005 has My.FileSystem to do this stuff with. But, it makes more sense to use System.IO.File.ReadAllText and WriteAllText directly, so you know where it is if you ever need to use C#.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
"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 )
|
|
|
|
|
actually my problem is diffent.
Actually i want read a line from 1st text file and search this line in the second text file( which had the string as in 1st txt file and equivalent localized string) and then copy this localized string from 2nd text file and replace with the 1st one.
Thanks in advance!
pankaj kumar
|
|
|
|
|
Your problem is the same. You still can't replace text in a file, you still need to read all of the file in, change it in memory and save it all out again.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
"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 have a need of importing the .DAT files into the application.
The first row in the file is considered as header and rest for data, The data is seperated by TABDelimiter.
Any suggestions plz....
Help....
Jats
|
|
|
|
|
There are a plethora of articles on this site for dealing with CSV files. Take one and replace the comma with a tab.
|
|
|
|
|
I had tried that before, but its not working.
As the file type is .DAT, there is some problem with the connection string b'cause when i opened the connection and tried to assaign the data to a datagridview its throwing an error stating "ERROR [42000] [Microsoft][ODBC Text Driver] Cannot update. Database or object is read-only."
The code is as follows....
Private Sub ConnectDAT()
ds = New DataSet()
Dim sql_select As String
Dim strConn As String = "Driver={Microsoft Text Driver (*.txt; *.csv)};Dbq=" + TextBox1.Text.Trim() + ";Extensions=asc,csv,tab,txt;Persist Security Info=False"
' The connection string is given as "Driver={Microsoft Text Driver (*.txt; *.csv)};Dbq=D:\Folder;Extensions=asc,csv,tab,txt;Persist Security Info=False"
Dim conn As OdbcConnection
conn = New System.Data.Odbc.OdbcConnection(strConn.Trim)
conn.Open()
sql_select = "select * from [" + strCSVFile + "]"
obj_oledb_da1 = New System.Data.Odbc.OdbcDataAdapter(sql_select, conn)
obj_oledb_da1.Fill(ds, "CInfo")
DataGridView1.DataSource = ds
DataGridView1.DataMember = "CInfo"
conn.Close()
End Sub
Can you help me...in solving the problem...
Jats
|
|
|
|
|
Jats_4ru wrote: As the file type is .DAT
The file extension has nothing to do with it. It is the contents for the file that are important. You have described a tab separated file.
Jats_4ru wrote: there is some problem with the connection string b'cause when i opened the connection and tried to assaign the data to a datagridview its throwing an error stating "ERROR [42000] [Microsoft][ODBC Text Driver] Cannot update. Database or object is read-only."
Why are you using an ODBC connection at all? There are hundred of examples of a CSV reader, quite a few here on CodeProject, that work perfectly well without resorting to inefficient kludges like ODBC. Look for those projects and change the comma to a tab (like I already suggested)
|
|
|
|
|
Hi everyone!
I'm relatively new to VB.NET and I want to write a resistance evaluation tool for school.
How do I check which value of a combobox is selected?
And can I give the different values different background colours?
|
|
|
|
|
|
Private Declare Function ShowWindow Lib "user32" (ByVal hwnd As Long, ByVal nCmdShow As Long) As Long
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As Long
Private Declare Function SetWindowPos Lib "user32" (ByVal hwnd As Long, ByVal hWndInsertAfter As Long, ByVal X As Long, ByVal Y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long
Const SWP_HIDEWINDOW = &H80
Const SWP_SHOWWINDOW = &H40
Public Sub StartButton(ByVal show As Boolean)
Dim primo As Long
Dim ultimo As Long
primo = FindWindow("Shell_TrayWnd", "")
ultimo = FindWindowEx(primo, 0, "Button", vbNullString)
If show = True Then
ShowWindow(ultimo, 5) 'show start button
Else
ShowWindow(ultimo, 0) 'hide start button
End If
End Sub
Public Sub taskbar(ByVal show As Boolean)
Dim primo As Long
primo = FindWindow("Shell_traywnd", "")
If show = True Then
SetWindowPos(primo, 0, 0, 0, 0, 0, SWP_SHOWWINDOW) 'show taskbar
Else
SetWindowPos(primo, 0, 0, 0, 0, 0, SWP_HIDEWINDOW) 'hide taskbar
End If
End Sub
Public Sub deskicon(ByVal show As Boolean)
Dim primo As Long
primo = FindWindowEx(0&, 0&, "Progman", vbNullString)
If show = True Then
ShowWindow(primo, 5) 'show desktop icon
Else
ShowWindow(primo, 0) 'hide desktop icon
End If
End Sub
|
|
|
|
|
Is this VB6 ? It looks like a bunch of p/invoke code. go to www.pinvoke.net to find out how to do the pinvoke part, and the rest is trivial.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
"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 )
|
|
|
|
|
Does anyone knows how to detect memory card/storage card from a smart device using vb.net CF ? The challenge is because there are many brands and versions of PDA, means that the naming of the storage device might be different as well. I want to get the drive name of the storage device. Thanks in advance
i wish to learn more from this forum
|
|
|
|
|
is there a way to check the remaining free space availabe on the Hard Disk and notify the user of that?
I mean how can i display a popup msg to the user when the free remaining size reaches 90% for example?
Regards
Ramy
|
|
|
|
|
|
Try this. In this example you will need one button and 3 textboxes.Hope this helps
Declareations
Inherits System.Windows.Forms.Form<br />
Private Declare Function GetDiskFreeSpaceEx _<br />
Lib "kernel32" _<br />
Alias "GetDiskFreeSpaceExA" _<br />
(ByVal lpDirectoryName As String, _<br />
ByRef lpFreeBytesAvailableToCaller As Long, _<br />
ByRef lpTotalNumberOfBytes As Long, _<br />
ByRef lpTotalNumberOfFreeBytes As Long) As Long<br />
<br />
<br />
<br />
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click<br />
TextBox1.Text = GetFreeSpace("C:\")<br />
TextBox2.Text = GetTotalSpace("C:\")<br />
GetPercentageFree()<br />
If TextBox3.Text < 36 Then<br />
MsgBox("You are running out of space")<br />
End If<br />
End Sub<br />
Public Function GetFreeSpace(ByVal Drive As String) As Long<br />
'returns free space in MB, formatted to two decimal places<br />
'e.g., msgbox("Free Space on C: "& GetFreeSpace("C:\") & "MB")<br />
<br />
Dim lBytesTotal, lFreeBytes, lFreeBytesAvailable As Long<br />
<br />
Dim iAns As Long<br />
<br />
iAns = GetDiskFreeSpaceEx(Drive, lFreeBytesAvailable, _<br />
lBytesTotal, lFreeBytes)<br />
If ians > 0 Then<br />
<br />
Return BytesToMegabytes(lFreeBytes)<br />
Else<br />
Throw New Exception("Invalid or unreadable drive")<br />
End If<br />
<br />
<br />
End Function<br />
<br />
<br />
Public Function GetTotalSpace(ByVal Drive As String) As String<br />
'returns total space in MB, formatted to two decimal places<br />
'e.g., msgbox("Free Space on C: "& GetTotalSpace("C:\") & "MB")<br />
<br />
Dim lBytesTotal, lFreeBytes, lFreeBytesAvailable As Long<br />
<br />
Dim iAns As Long<br />
<br />
iAns = GetDiskFreeSpaceEx(Drive, lFreeBytesAvailable, _<br />
lBytesTotal, lFreeBytes)<br />
If iAns > 0 Then<br />
<br />
Return BytesToMegabytes(lBytesTotal)<br />
Else<br />
Throw New Exception("Invalid or unreadable drive")<br />
End If<br />
End Function<br />
<br />
Private Function BytesToMegabytes(ByVal Bytes As Long) _<br />
As Long<br />
<br />
<br />
Dim dblAns As Double<br />
dblAns = (Bytes / 1024) / 1024<br />
BytesToMegabytes = Format(dblAns, "###,###,##0.00")<br />
<br />
End Function<br />
Public Function GetPercentageFree()<br />
Dim free As Integer<br />
Dim total As Integer<br />
Dim percent As Integer<br />
free = GetFreeSpace("C:\")<br />
total = GetTotalSpace("C:\")<br />
<br />
percent = (free / total) * 100<br />
TextBox3.Text = percent<br />
End Function
|
|
|
|
|
Dim strPath As String = "C:\Video"<br />
Dim strSearch As String = ".avi"<br />
<br />
<br />
For Each strFile As String In My.Computer.FileSystem.GetFiles(strPath, FileIO.SearchOption.SearchTopLevelOnly, strSearch)<br />
<br />
ListBox1.Items.Add(My.Computer.FileSystem.GetName(strFile))<br />
Next
Can somebody tells me why it won't populate my listbox with avi files in C:\Video? Can somebody fix the code here?
|
|
|
|
|
What happens when you step through the code ? Should the search string be *.avi ?
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
"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 )
|
|
|
|
|
Sorry I had to redesign some of your code but it should work.
Dim strPath() As String <br />
Dim strSearch As String <br />
strPath = IO.Directory.GetFiles("C:\video")<br />
<br />
For Each strSearch In strPath<br />
If InStr(strSearch, ".avi", CompareMethod.Text) Then<br />
ListBox1.Items.Add(strSearch)<br />
End If<br />
Next
Tell me if it does
Hope this helps
|
|
|
|
|
Sorry guys for the late reply, actually the code I pasted before does work. There was something wrong with my listbox properties so that the files found isn't visible on the listbox. I deleted the listbox and create a new one and now it runs fine Sorry again..
Thanks anyway
|
|
|
|
|
Dear all,
Please tell me hoew can i open a new form from the previous form on clicking the button????
Regards
Pari
pari
|
|
|
|
|
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles button1.Click<br />
<br />
Dim frm2 As New Form2<br />
frm2.Showdialog() <br />
end sub
Where button1 is the button that you click on to show the new form.
Where form2 is the name of the form you want to show.
Hope this helps
-- modified at 3:16 Monday 30th April, 2007
|
|
|
|
|
Please, never do this. If you call Show and not ShowDialog, the form should be a member variable.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
"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 )
|
|
|
|
|
Christian Graus wrote: If you call Show and not ShowDialog, the form should be a member variable.
Oops my mistake.
I should of known better, I usually do use showdialog instead of show.
The code works though.
I'll just change it.
|
|
|
|
|
If you use ShowDialog, you also MUST call Dispose on the object when your done with the form. A resource leak will result if you don't.
Dave Kreskowiak
Microsoft MVP
Visual Developer - Visual Basic 2006, 2007
|
|
|
|
|
Dear all, i'm an ASp.net developer but i'm workin on a desktop application
There is a requirement that is to open only one executable of the application and if the user tries to open another instance the application returns an error message
So how can i know that there is an instance already running?
One of the thoughts was to create a state variable saved in a text file or xml file but u cann't manage it 100% because maybe the OS restarted or the user closes the application by killing the process... So i think there is a better way by checking running prcesses in the memory.
Any key how can i implement that?
P.S. I'm using VB script on VS.net 2003
Best Regards
3ala2
|
|
|
|