[RESOLVED] [2008] Smaller code
Please someone help me to make this code smaller.
Imagine how much code I would have when var1 = 100.
Please!
Code:
Private Sub BackgroundWorker3_DoWork(ByVal sender As System.Object, ByVal e As System.ComponentModel.DoWorkEventArgs) Handles BackgroundWorker3.DoWork
Dim myfile = My.Computer.FileSystem.OpenTextFieldParser(tempdir & updatefile_list)
Dim myfile2 = My.Computer.FileSystem.OpenTextFieldParser(tempdir & updatelist_explorer)
var1 = myfile.ReadLine()
If var1 = 1 Then
var2 = myfile2.ReadLine()
jou2 = myfile.ReadLine()
ElseIf var1 = 2 Then
var2 = myfile2.ReadLine()
var3 = myfile2.ReadLine()
jou2 = myfile.ReadLine()
jou3 = myfile.ReadLine()
ElseIf var1 = 3 Then
var2 = myfile2.ReadLine()
var3 = myfile2.ReadLine()
var4 = myfile2.ReadLine()
jou2 = myfile.ReadLine()
jou3 = myfile.ReadLine()
jou4 = myfile.ReadLine()
' and so on
End If
End Sub
Re: [RESOLVED] [2008] Smaller code
I would only recommend changing vbNewLine to Environment.NewLine
Re: [RESOLVED] [2008] Smaller code
smaller code :D
vb Code:
Dim Lines As String() = IO.File.ReadAllLines(pathToFile)
For i As Integer = 0 To Lines.GetUpperBound(0)
'Do something with each line here
Next
Re: [RESOLVED] [2008] Smaller code
why not this?
vb Code:
Dim lines() As String = io.file.readalllines(text_file)
Re: [RESOLVED] [2008] Smaller code
MaximilianMayrhofer and what is the difference between those two?
Re: [RESOLVED] [2008] Smaller code
Environment.NewLine is .net code and vbNewLine is legacy code
Re: [RESOLVED] [2008] Smaller code
Thanks gnaver, but I dont need to do something with each line, I just need to save each line and then use it in something other.
Thanks a lot .paul.! Even better code, lol, but gnaver's first line of code is almost the same as yours so that means you're both are thinking the same, just gnaver thought about more things what I could do and thanks for that again gnaver! :P Rated both of you!
Thanks .paul. for the answer!
Rated MaximilianMayrhofer also! :P