I need to make an application that will show in a file which button I pressed. I added this in VB6 in the K8055_VB_NET.vbproj
Private Sub CheckBox1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox1.CheckedChanged
Dim i As Integer
For i = 1 To 5
If cbi(i).Checked = True Then
Dim FILE_NAME As String = "D:\Mod\FILE.txt"
Dim objWriter As New System.IO.StreamWriter(FILE_NAME)
objWriter.Write(i)
objWriter.Close()
Else
Dim FILE_NAME As String = "D:\Mod\FILE.txt"
Dim objWriter As New System.IO.StreamWriter(FILE_NAME)
objWriter.Write("Nu button has been pressed")
objWriter.Close()
End If
Next
End Sub
End Class
I get this after I run it
See Exception.InnerException for details. The error is: Object reference not set to an instance of an object.
I am new to this so there is a huge change I went to wrong way about this
Your added code seems to work.
I tested it adding CheckBox4 to the form. (- The CheckBox1 is already used.)
I think you like to create a single file where to put the data… ?
If yes, then you should create the file outside the FOR - NEXT loop.
I modified the code:
Private Sub CheckBox4_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox4.CheckedChanged
Dim i As Integer
Dim FILE_NAME As String = "FILE.txt"
Dim objWriter As New System.IO.StreamWriter(FILE_NAME)
For i = 1 To 5
If cbi(i).Checked = True Then
objWriter.WriteLine(CStr(i) + " is pressed")
Else
objWriter.WriteLine(CStr(i) + " is not pressed")
End If
Next
objWriter.Close()
End Sub
Here is an example of the content of the FILE.txt:
1 is not pressed
2 is pressed
3 is not pressed
4 is pressed
5 is not pressed
It seems that you are using the very old version of the example software and the K8055D.DLL.
Here is the link to download the latest software package for the K8055: velleman.eu/downloads/files/ … rsion4.zip
The package includes new K8055D.DLL and several sample projects written in various programming languages.
Pleas read the “README.TXT” and the “K8055 & VM110 Getting Started.pdf”.
In my example code the file is created and filled according to the button state when you click the CheckBox4.
You may also add a button to the form and assign the code to it.
Then pressing the button will create the file and fill it with the data.