Hello, I am new to using Visual Studios.Net. I am trying to write a class using Visual Studios.Net in the Visual Basic section. Could someone tell me what I am doing wrong?
Module Module1
Public Class MyClassName
End Class
Sub New()
Dim intVariable As Integer
intVariable = 0
End Sub
Property Variable() As Integer
Get
Return Variable
End Get
Set(ByVal Value As Integer)
Variable = Value
End Set
End Property
MyClassName End Class
REM I don't really know if End MyClassName should be at the end.
REM book has End Class at the end.
REM But the programs still manages to run I think.
End Module
The End Class should not be at the top, but at the bottom with the REM statements. Incidentally, you can now use the ' character instead of REM to comment.
In VS using a module to write a class is a pointless way, when you can actually add your own class directly. To do this, go to Add New Item and choose Class. Give it a name, and accept. It should load up with code already set up. Simply add the methods to populate the class.
Thanks for the help.![]()
Yeah it is ok now. I am having problems activating my direct x controller though. I am reading a book called Gaming Programming for Teens. I believe that the author left out many important details about visual basic.
Yeah it should be. I just installed a graphics card geforce 7200 series. I past the test to see if it is obsolete. But since I am new to VB I don't really know who to initialize a device yet for direct X. Mainly I am just trying to write some code to form a window and changes its color to blue. I believe it has something to do with the adapters of the device or something of that nature.
You shouldn't need DirectX just to display a form! Use a simple Form object, and change its BackColor to Color.Blue, like so:
You can change any extra properties of the 'f' object before showing it, to make it look just the way you want it to.Code:Dim f As New Form() f.BackColor = Color.Blue f.Show()
It is that simple? Here is the command line that I am having problems with below:
REM Create the Direct3D device
device = New Direct3D.Device(adapterNumber, Direct3D.DeviceType.Hardware, Me, flags, params)
Here is the program below:
Imports Microsoft.DirectX
Public Class Form1
Inherits System.Windows.Forms.Form
#Region " Windows Form Designer generated code "
Public Sub New()
MyBase.New()
'This call is required by the Windows Form Designer.
InitializeComponent()
'Add any initialization after the InitializeComponent() call
End Sub
'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer
'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
Private Sub InitializeComponent()
'
'Form1
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(292, 266)
Me.Name = "Form1"
Me.Text = "Form1"
End Sub
#End Region
Dim device As Microsoft.DirectX.Direct3D.Device
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Me.Size = New Size(800, 600)
Me.Text = "DirectX Initialization Demo"
Me.SetStyle(ControlStyles.AllPaintingInWmPaint Or ControlStyles.Opaque, True)
REM the above statements resize the window of the form
REM set up the presentation parameters
Dim params As New Direct3D.PresentParameters
params.Windowed = True
params.SwapEffect = Direct3D.SwapEffect.Discard
params.AutoDepthStencilFormat = Direct3D.DepthFormat.D16
params.EnableAutoDepthStencil = True
params.BackBufferCount = 1
params.BackBufferCount = 800
params.BackBufferCount = 600
REM Check video card capabilities
Dim adapterNumber As Integer = Direct3D.Manager.Adapters.Default.Adapter
Dim flags As Direct3D.CreateFlags
flags = Direct3D.CreateFlags.HardwareVertexProcessing
flags += Direct3D.CreateFlags.PureDevice
Dim caps As Direct3D.Caps
caps = Direct3D.Manager.GetDeviceCaps(adapterNumber, Direct3D.DeviceType.Hardware)
If caps.DeviceCaps.SupportsHardwareTransformAndLight = False Or caps.DeviceCaps.SupportsPureDevice = False Then
MessageBox.Show("Your video card is obsolete.", "Hardware Problem")
End
End If
REM Create the Direct3D device
device = New Direct3D.Device(adapterNumber, Direct3D.DeviceType.Hardware, Me, flags, params)
End Sub
Protected Overrides Sub OnPaint(ByVal e As PaintEventArgs)
device.Clear(Direct3D.ClearFlags.Target + Direct3D.ClearFlags.ZBuffer, Color.Blue, 1.0, 0)
device.BeginScene()
device.EndScene()
device.Present()
Me.Invalidate()
End Sub
End Class
It is suppose to bring up a window and make the window blue.
BLIMEY! Oh, I see. I have just remembered you are writing games. Just displaying a blue window is easy using the standard .NET functions, but once you start writing complex games, there will be a point where this long code will overtake the normal .NET ones in terms of usability.
You see, the usual .NET framework is not designed to write games. This code might seem like a lot, but the more you try to draw to the screen, the easier it will seem.
If you want to use the standard .NET commands, you can install the XNA Game Library. This provides an extra set of tools for writing games, but your DirectX thingy looks fine, and I advise you to stick with the code it gives you - my example could not in a million years write a game!
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks