'Making public after being Private - Visual Basic
Currently in the process of "self teaching" visual basic so apologies for the basic question
Maybe I am going about this the wrong way but I want to use btnTA_StartLog to create a file and activate Timer1 to log data in a specified interval. Problem being outlog is only defined in btnTA_startLog and not in the other 2 subs. How can I make the recently declared outlog public and accessible to the other subs?
Public Sub btnTA_StartLog_Click(sender As Object, e As EventArgs) Handles btnTA_StartLog.Click
Dim file As String = GetFileName(False, "csv", "Data Output")
Dim outlog As IO.StreamWriter = My.Computer.FileSystem.OpenTextFileWriter(file, True)
Timer1.Start()
btnTA_StartLog.Enabled = False
btbTA_LoggingStop.Enabled = True
End Sub
Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
outlog.WriteLine(CStr(DateTime.Now) & "," & CStr(txbTA_Delivered_ml.Text) & "," & CStr(MyTC.Data.Temperature))
End Sub
Private Sub btbTA_LoggingStop_Click(sender As Object, e As EventArgs) Handles btbTA_LoggingStop.Click
Timer1.Stop()
outlog.Close()
End Sub
Solution 1:[1]
not a vb.net person so I dont know the exact syntax but the rules are the same for c# which I do know.
Define outlog at the form level, ie outside any functions, in that way all functions can use it.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | pm100 |
