hi i am making a program (console aplication) in vb.net for computing which is holaday homework it converts tempritures Celsius into Fahrenheit and i have basicly made the conversion and made it to loop until user presses x but i need to get the results into a text file which i am finding difficult to do and every time i try i fail this is my code: Option Explicit On Imports System Imports System.IO Module Module1 Dim Celsius, Fahrenheit, sum As Single Sub Main() Do Dim strInput As String Console.Write("Celsius? ") strInput = Console.ReadLine() If UCase(strInput) = "X" Then Exit Do Else Celsius = CSng(strInput) sum = Celsius * 9 / 5 + 32 Console.WriteLine("Fahrenheit is " & sum) Console.WriteLine("") Console.WriteLine("to do another conversion press enter ") Console.WriteLine("to exit press enter then type x") Console.WriteLine("") Console.ReadKey() End If Loop End Sub End Module could someone give me an worked example thanks for any help
Maybe try this : Public Function SaveTextToFile(ByVal strData As String, _ ByVal FullPath As String, _ Optional ByVal ErrInfo As String = "") As Boolean Dim Contents As String Dim bAns As Boolean = False Dim objReader As StreamWriter Try objReader = New StreamWriter(FullPath) objReader.Write(strData) objReader.Close() bAns = True Catch Ex As Exception ErrInfo = Ex.Message End Try Return bAns End Function
iv tried and it dosnt like it when put the Dim Contents As String it comes up with an error and also where are you ment to put the directory of the file
You will have to be more wise that simply doing cut and paste on this. If you got compilation error, fix them The important code is this : Dim objReader As StreamWriter objReader = New StreamWriter(FullPath) objReader.Write(strData) objReader.Close() StrData is the string to write FullPath is the path to the file Have a nice day