Can't write to text file

huhhuhhuh

Active member
Joined
Feb 28, 2006
Messages
42
Programming Experience
Beginner
Dim strconf As String = "config.txt"
strcont = "Settings"
writefile(strcont, strconf)
If Setting1() = 1 Then
strcont = "Setting=True"
writefile(strcont, strconf)

I'm calling a function to write into a text file. The first statement gets written but the statement in the if block and all subsequent if blocks for that matter don't get written. Am I doing something wrong?
 
Hard to tell without seeing your writefile code. And put the code in code boxes, will you..
 
VB.NET:
Public Function writefile(ByVal strcontins As String, ByVal strdest As String)
Dim towrite As String = Environment.NewLine & strcontins
Dim destination As String = strdest
Dim myfilestream As New FileStream(destination, FileMode.OpenOrCreate, FileAccess.Write)
Dim writestream As New StreamWriter(myfilestream)
writestream.BaseStream.Seek(0, SeekOrigin.End)
writestream.WriteLine(towrite)
writestream.Close()
myfilestream.Close()
End Function

this is my write function. It works perfectly except when I'm trying to write anything within if if block. Example from previous code, Settings got written without a hitch, but Setting=1 in the if block doesn't work. The same goes for all writes in subsequent if blocks.
 
writefile method looks fine (except it doesn't return anything so it's not a function method but a sub method)

so what's the "Setting1()" you use in If statement ?
 
VB.NET:
Public Function Setting() As Integer
Return Global.setting
End Function

It returns the value of the setting property of the global class
 
Back
Top