Inverse Matrix of 2x2, 3x3, 4x4
Inverse Matrix of 2x2, 3x3, 4x4
Inverse Matrix of 2x2, 3x3, 4x4
If
where
Inverse matrix of NxN matrix
From the analogy of the above formulae, the computation time of inverse matrix of NxN
matrix will be O(N3N!). Computing inverse matrix with Gauss-Jordan method, the
method using LU decomposition, and the method using SVD, will take a computation
time of O(N3) (not confident). I will recommend not to use the formula for calculating
inverse matrix of NxN matrix which N >= 4.
Visual Basic Reading/Writing Text Files
Submitted by:
Yorkiebar
Saturday, September 7, 2013 - 09:31
Language:
Visual Basic
Visitors have accessed this post 677 times.
Introduction:
As you can see from the title, this is a tutorial on simply reading and writing Text Files. Let's begin.
Steps of Creation:
Step 1:
This will require one Import which is to enable us to read and write files. The Import is System.IO:
1. Imports System.IO
Step 2:
The design this program is going to need is to have one textbox to contain the file contents, another textbox
to store the current file path, one button to read a file and another to save the file. The naming of these are:
Textbox1 = Textbox containing file contents
Textbox2 = File Path
Button1 = Read
Button2 = Write
I would also recommend setting ReadOnly to True on textbox2 so the user can not edit the file path.
Step 3:
Now, on to the code!
First let's create the read code, double click on the read button to get our click event generated.
1. Class Form1
2. Private Sub Button1_Click(sender As Object, e As EventArgs)
Handles Button1.Click
3. Dim fo As New OpenFileDialog
4. fo.RestoreDirectory = True
5. fo.Filter = "txt files (*.txt)|*.txt"
6. fo.FilterIndex = 1
7. fo.ShowDialog()
8. If (fo.FileName = Nothing) Then
9. MsgBox("Error: No path selected")
10. Else
11. TextBox2.Text = fo.FileName
12. Using sr As New streamreader(fo.FileName)
13. TextBox1.Text = sr.readtoend()
14. End Using
15. End If
16. End Sub
17. End Class
As you can see we create a new variable called "fo" which is set to a New OpenFileDialog. Then we set
some properties of this dialog. The RestoreDirectory means whenever it opens the starting folder will be the
last visited directory from any Windows Explorer/Browser you have used. We then set the file types which
can be opened, I only used .txt but you can also set things like .csv, after that we set the default file type to
.txt (my only file type). We then display the dialog box to the user.
After the user selects a file to read we then check whether the file is set to nothing (If they closed the box)
and display an error message if there is no file selected. If there is a file selected we set the path to textbox2
and use a StreamReader with the path set to our selected file and read the file to our textbox1.
Step 4:
That's it for the reading part, now for the writing part:
Project Complete!
That's it! Below is the source code to the whole project along with a download in the code section, Thank
you!
1. Imports System.IO
2. Class Form1
3. Private Sub Button1_Click(sender As Object, e As EventArgs)
Handles Button1.Click
4. Dim fo As New OpenFileDialog
5. fo.RestoreDirectory = True
6. fo.Filter = "txt files (*.txt)|*.txt"
7. fo.FilterIndex = 1
8. fo.ShowDialog()
9. If (fo.FileName = Nothing) Then
10. MsgBox("Error: No path selected")
11. Else
12. TextBox2.Text = fo.FileName
13. Using sr As New streamreader(fo.FileName)
14. TextBox1.Text = sr.readtoend()
15. End Using
16. End If
17. End Sub
18.
19. Private Sub Button2_Click(sender As Object, e As EventArgs)
Handles Button2.Click
20. If (TextBox2.Text = Nothing) Then
21. Dim fs As New SaveFileDialog
22. fs.RestoreDirectory = True
23. fs.Filter = "txt files (*.txt)|*.txt"
24. fs.FilterIndex = 1
25. fs.ShowDialog()
26. If (fs.FileName = Nothing) Then
27. MsgBox("Error: No path selected")
28. Else
29. Using sw As New StreamWriter(fs.FileName)
30. sw.Write(TextBox1.Text)
31. End Using
32. End If
33. Else
34. Dim res = MsgBox("Do you want to save to the same
file?", MsgBoxStyle.YesNo, "Overwrite Read File?")
35. If (res = MsgBoxResult.Yes) Then
36. If
(My.Computer.FileSystem.FileExists(TextBox2.Text)) Then
37. Using sw As New StreamWriter(TextBox2.Text)
38. sw.Write(TextBox1.Text)
39. End Using
40. End If
41. Else
42. Dim fs As New SaveFileDialog
43. fs.RestoreDirectory = True
44. fs.Filter = "txt files (*.txt)|*.txt"
45. fs.FilterIndex = 1
46. fs.ShowDialog()
47. If (fs.FileName = Nothing) Then
48. MsgBox("Error: No path selected")
49. Else
50. Using sw As New StreamWriter(fs.FileName)
51. sw.Write(TextBox1.Text)
52. End Using
53. End If
54. End If
55. End If
56. End Sub
57. End Class
I want to open mis file, copy all the data and write into a text file.
My mis file.
M3;3395;44;0;1;;20090404;094144;8193;3;0;;;;
M3;3397;155;0;2;;20090404;105941;8193;3;0;;;;
M3;3396;160;0;1;;20090404;100825;8193;3;0;;;;
M3;3398;168;0;2;;20090404;110106;8193;3;0;;;;
so on...,
The above data should appear in a text file with same file name (1.txt).
iFileNo = FreeFile
Loop
Close #iFileNo
Loop
Close #iFileNo
file-io vb6
share|improve this question edited Jul 23 '12 at asked Sep 10 '09 at 11:32
10:59
Deanna Gopal
13.9k31346 2,3231566140
Well, if your
mis file stores
it's data as
text, you could
1 just copy the
file to 1.txt... :-)
Wim ten
Brink Sep 10
'09 at 11:39
There's
nothing in 1.txt
because
you're writing
1 to 2.txt...
Wim ten Brink
Sep 10 '09 at
15:12
add comment
4 Answers
active oldest votes
up vote It far easier to use the scripting runtime which is installed by default on Windows
7 down
vote
accepted Just go project Reference and check Microsoft Scripting Runtime and click OK.
Then you can use this code which is way better than the default file commands
Dim TS As TextStream
Set TS = FSO.OpenTextFile("C:\Clients\Converter\Clockings.mis",
ForReading)
Final = TS.ReadAll
Do Until TS.AtEndOfStream
TempS = TS.ReadLine
Final = Final & TempS & vbCrLf
Loop
TS.Close
TS.Write Final
TS.Close
Set TS = Nothing
As for what is wrong with your original code here you are reading each line of the text
file.
sFileText is a string variable so what it is happening that each time you read you just
replace the content of sFileText with the content of the line you just read.
So when you go to write it out all you are writing is the last line you read which is
probably a blank line.
iFileNo = FreeFile
Loop
Close #iFileNo
iFileNo = FreeFile 'Don't assume the last file number is free to use
Close #iFileNo
Note you don't need to do a loop to write. sFinal contains the complete text of the File
ready to be written at one shot. Note that input reads a LINE at a time so each line
appended to sFinal needs to have a CR and LF appended at the end to be written out
correctly on a MS Windows system. Other operating system may just need a LF
(Chr$(10)).
If you need to process the incoming data then you need to do something like this.
Dim C as Collection
Dim R as Collection
Dim I as Long
iFileNo = FreeFile
C.Add sFileText
Loop
Close #iFileNo
Process vTemp
Next sTemp
iFileNo = FreeFile
Next sTemp
Close #iFileNo
RS Conley
6,075826
Some user computers don't have FileSystemObject (I have experienced this). I think
overzealous IT departments sometimes trample on the scripting runtime for fear of viruses
MarkJ Sep 24 '09 at 9:35
Yes which is why you should include as part of your install. The sysop can then decide
whether to make an exception for the application. Or make your own version wrapping the
native function or wrap the .NET equivalent up. Both of which are overkill IMO. RS
Conley Sep 24 '09 at 12:10
add comment
iInputFile = FreeFile
iOutputFile = FreeFile
Loop
Close #iInputFile
Close #iOutputFile
C-Pound Guru
5,57021531
add comment
up FileCopy "1.mis", "1.txt"
vote 1
down share|improve this answer answered Sep 10
vote '09 at 11:40
Yossarian
8,1591651
Filecopy is working, Suppose i want to add something in a destination text file, How to make
code. Gopal Sep 10 '09 at 11:57
add comment
up An example of reading a file:
vote 1
down Dim sFileText as String
vote
Dim iFileNo as Integer
iFileNo = FreeFile
'change this filename to an existing file! (or run the example below
first)
'show the text (you will probably want to replace this line as
appropriate to your program!)
MsgBox sFileText
Loop
'close the file (if you dont do this, you wont be able to open it again!)
Close #iFileNo
iFileNo = FreeFile
'close the file (if you dont do this, you wont be able to open it again!)
Close #iFileNo
From Here
for other colums just create the range like "b1", "m10" etc.
Hope u got the point.
************************************************** *****
*******************************************
FileToWrite.Close
**************
B. Anant
#6 (permalink)
Hi Anant,
I have to read the data from a table in MSWORD. Then I have to execute a macro which takes
these inputs and generates a text file from it.
I am a newbie to VB usage .Can you tell me in steps as to how do
i make the VB script read the data from the MSWord Table.
Regards
Priya
Quote:
quote:Originally posted by Anantsharma
HI,
for other colums just create the range like "b1", "m10" etc.
Hope u got the point.
************************************************** *****
*******************************************
FileToWrite.Close
**************
B. Anant
Regards
Md Shariq.
Join this group
If you want to concatenate the text file then u will use split.
0
Dim FN As Long
Dim sSQL As String
FN = FreeFile
sSQL = "C:\MyText.txt"
Open sSQL For Output As FN
Print #FN, "THIS TEXT FILE CREATED FROM VB"
Print #FN, "CHECK FILE "
Close FN
Instead of "Output" u can use "Append" to insert text in the Same File.
If Output is used, then every time new file is created.
Regards
Veena
0
Regards,
Santosh Kadam
0
thank you,
*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*
Glenn A. Timbreza
MIS/Acctg. Staff
*NANBU PHILILIPPINES INC.*
eMail: email@removed
Tel: 046 437.2066
Fax: 046 437.2065
*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*
White Papers and Webcasts
Popular
will return "4" because the fourth character is the start of "put".
Usually, if I'm checking this, I will use something like
end if
The first value is where you want to start (almost always 1) , the second
is the string you want to search, third is the string you want to look
for, and fourth is the search method.