I am new to VB. I read a book and follow its code
Public Class Form1
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
Dim Wrap As String
Wrap = Chr(13) & Chr(10)
Dim i As Integer
For i = 1 To 4
PictureBox1.Image = System.Drawing.Image.FromFile("C:\face0" & i & ".ico")
MsgBox("Click for next face")
Next
End Sub
End Class
It Works. However, I try to adjust the code to make Wrap become a variable available to the whole form1. I do the following, but it does NOT work. Why?
Public Class Form1
Dim Wrap As String
Wrap = Chr(13) & Chr(10)
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
Dim i As Integer
For i = 1 To 4
PictureBox1.Image = System.Drawing.Image.FromFile("C:\face0" & i & ".ico")
MsgBox("Click for next face")
Next
End Sub
End Class
You can’t have arbitrary pieces of code at class level.
Wrap = Chr(13) & Chr(10)is an arbitrary piece of code.If you want to assign a value to a variable, do so with an initializer:
Better yet, use
ControlChars.CrLfwhich is a predefined constant for same.