I
Identity80
Guest
Hello !
I am very beginner, and need some help.
I "translate" one VB6 program to VB.NET ,and somewhere i have one fail.
Theerror message :" the value cannot be null".
Please who can help me, save me.
Sorry for my bad English, i write from Europe.
Option Explicit On
Public Class Form1
Private Declare Function SetPixel Lib "gdi32" (ByVal hdc As Long, ByVal X As Long, ByVal Y As Long) As Long
Structure t3Dcoord
Dim X As Double
Dim Y As Double
Dim Z As Double
End Structure
Dim fps As Integer
Dim fpsValue As Integer
Dim M() As t3Dcoord 'our main array. We'll adjust the size later
Dim Temp() As t3Dcoord 'a temporary array we use when drawing
Dim Cam As t3Dcoord 'our camera
Private Sub Form1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown
If e.KeyCode = Keys.Escape Then ' Case vbKeyEsc
End
End If
If e.KeyCode = Keys.Up Then 'Case vbKeyUp
Cam.Y = Cam.Y - 10 'move up
End If
If e.KeyCode = Keys.Down Then 'Case vbKeyDown
Cam.Y = Cam.Y + 10 'move down
End If
If e.KeyCode = Keys.Left Then 'Case vbKeyLeft
Cam.X = Cam.X - 10 'move left
End If
If e.KeyCode = Keys.Right Then 'Case vbKeyRight
Cam.X = Cam.X + 10 'move right
End If
If e.KeyCode = Keys.PageUp Then 'Case vbKeyPageUp
Cam.Z = Cam.Z + 10 'move in
End If
If e.KeyCode = Keys.PageDown Then 'Case vbKeyPageDown
Cam.Z = Cam.Z - 10 'move out
End If
' End Select
End Sub
Private Sub Form_Load()
Randomize()
Me.Top = 40
Me.Left = 40
BackColor = Color.White
Cam.X = 0
Cam.Y = 0
Cam.Z = 0
Call Createdots()
End Sub
Private Sub Createdots()
Dim i As Integer
For i = 0 To 5000
ReDim Preserve M(i)
M(i).X = (Rnd() * 1000) - 500
M(i).Z = (Rnd() * 1000) - 500
Next
ReDim Temp(UBound(M))
End Sub
Private Sub Mainloop()
Dim img As Image = PictureBox1.BackgroundImage
Dim bmp As Bitmap = CType(img, Bitmap)
Dim x As Integer
Dim y As Integer
Dim i As Integer
Do
For i = 0 To UBound(M) ' <--- i have the fail here (M)? value always 0
Temp(i).X = M(i).X - Cam.X
Temp(i).Y = M(i).Y - Cam.Y
Temp(i).Z = M(i).Z - Cam.Z
On Error Resume Next 'cuts out overflow errors
If Temp(i).Z > 0 Then
'This is the code that prepares the dots for putting on the screen
'All you do is divide the x by z and the y by z
'See no complex maths involved at all
Temp(i).X = Temp(i).X / Temp(i).Z
Temp(i).Y = Temp(i).Y / Temp(i).Z
bmp.SetPixel(Temp(i).X, Temp(i).Y, Color.Red)
PictureBox1.Invalidate()
End If
Next
Loop
End Sub
'all this does is start the main loop once the program has loaded
Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
fpsValue = fps 'put the number of frames from this second into a safe place
fps = 0 'reset the fps
End Sub
Private Sub Timer2_Tick(sender As Object, e As EventArgs) Handles Timer2.Tick
Call Mainloop() 'cal the main loop
Me.Enabled = False 'stop the timer now thats its done its job
End Sub
End Class
Continue reading...
I am very beginner, and need some help.
I "translate" one VB6 program to VB.NET ,and somewhere i have one fail.
Theerror message :" the value cannot be null".
Please who can help me, save me.
Sorry for my bad English, i write from Europe.
Option Explicit On
Public Class Form1
Private Declare Function SetPixel Lib "gdi32" (ByVal hdc As Long, ByVal X As Long, ByVal Y As Long) As Long
Structure t3Dcoord
Dim X As Double
Dim Y As Double
Dim Z As Double
End Structure
Dim fps As Integer
Dim fpsValue As Integer
Dim M() As t3Dcoord 'our main array. We'll adjust the size later
Dim Temp() As t3Dcoord 'a temporary array we use when drawing
Dim Cam As t3Dcoord 'our camera
Private Sub Form1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown
If e.KeyCode = Keys.Escape Then ' Case vbKeyEsc
End
End If
If e.KeyCode = Keys.Up Then 'Case vbKeyUp
Cam.Y = Cam.Y - 10 'move up
End If
If e.KeyCode = Keys.Down Then 'Case vbKeyDown
Cam.Y = Cam.Y + 10 'move down
End If
If e.KeyCode = Keys.Left Then 'Case vbKeyLeft
Cam.X = Cam.X - 10 'move left
End If
If e.KeyCode = Keys.Right Then 'Case vbKeyRight
Cam.X = Cam.X + 10 'move right
End If
If e.KeyCode = Keys.PageUp Then 'Case vbKeyPageUp
Cam.Z = Cam.Z + 10 'move in
End If
If e.KeyCode = Keys.PageDown Then 'Case vbKeyPageDown
Cam.Z = Cam.Z - 10 'move out
End If
' End Select
End Sub
Private Sub Form_Load()
Randomize()
Me.Top = 40
Me.Left = 40
BackColor = Color.White
Cam.X = 0
Cam.Y = 0
Cam.Z = 0
Call Createdots()
End Sub
Private Sub Createdots()
Dim i As Integer
For i = 0 To 5000
ReDim Preserve M(i)
M(i).X = (Rnd() * 1000) - 500
M(i).Z = (Rnd() * 1000) - 500
Next
ReDim Temp(UBound(M))
End Sub
Private Sub Mainloop()
Dim img As Image = PictureBox1.BackgroundImage
Dim bmp As Bitmap = CType(img, Bitmap)
Dim x As Integer
Dim y As Integer
Dim i As Integer
Do
For i = 0 To UBound(M) ' <--- i have the fail here (M)? value always 0
Temp(i).X = M(i).X - Cam.X
Temp(i).Y = M(i).Y - Cam.Y
Temp(i).Z = M(i).Z - Cam.Z
On Error Resume Next 'cuts out overflow errors
If Temp(i).Z > 0 Then
'This is the code that prepares the dots for putting on the screen
'All you do is divide the x by z and the y by z
'See no complex maths involved at all
Temp(i).X = Temp(i).X / Temp(i).Z
Temp(i).Y = Temp(i).Y / Temp(i).Z
bmp.SetPixel(Temp(i).X, Temp(i).Y, Color.Red)
PictureBox1.Invalidate()
End If
Next
Loop
End Sub
'all this does is start the main loop once the program has loaded
Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
fpsValue = fps 'put the number of frames from this second into a safe place
fps = 0 'reset the fps
End Sub
Private Sub Timer2_Tick(sender As Object, e As EventArgs) Handles Timer2.Tick
Call Mainloop() 'cal the main loop
Me.Enabled = False 'stop the timer now thats its done its job
End Sub
End Class
Continue reading...