|
The following properties are being used within the class, however when they are called from within a private sub within the class itself, intXPositions and intYPositions show a value of zero, even when the value has been set.
public class mainForm
...
Private Sub frmMain_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
'Initialize plateau.
Dim myPlateau As Plateau = Plateau.Instance
myPlateau.XPositions = 1001 ' x = 0 to x = 1000
myPlateau.YPositions = 1001 ' y = 0 to y = 1000
dtgPositions.DataSource = myPlateau.dsPlateauPosition
dtgPositions.DataMember = "PlateauPositions"
Me.Text = "done"
End Sub
...
Public Class Plateau
...
Private intXPositions As Integer
Public Property XPositions() As Integer
Get
Return intXPositions
End Get
Set(ByVal Value As Integer)
intXPositions = Value
End Set
End Property
Private intYPositions As Integer
Public Property YPositions() As Integer
Get
Return intYPositions
End Get
Set(ByVal Value As Integer)
intYPositions = Value
End Set
End Property
...
Private Sub initDataSource()
'Create PlateauPostions, a working dataset that retains information about
'positions occupied on the grid.
Dim dtPlateauPositions As New DataTable("PlateauPositions")
'define attributes
With dtPlateauPositions
.Columns.Add("xPosition", System.Type.GetType("System.Int32"))
.Columns.Add("yPosition", System.Type.GetType("System.Int32"))
.Columns.Add("occupied", System.Type.GetType("System.Boolean"))
End With
'enforce composite primary key
Dim colPrimaryKey(1) As DataColumn
colPrimaryKey(0) = New DataColumn("xPosition")
colPrimaryKey(1) = New DataColumn("yPosition")
'create dataset
dsPlateauPosition.Tables.Add(dtPlateauPositions)
'initialize positions as not occupied
Dim rowNew As DataRow = dtPlateauPositions.NewRow()
Dim intXCount, intYCount As Integer
For intXCount = 0 To intXPositions 'value is 0 when it is expected to be 1001
For intYCount = 0 To intYPositions 'value is 0 when it is expected to be 1001
rowNew.Item("xPosition") = intXCount
rowNew.Item("yPosition") = intYCount
rowNew.Item("occupied") = False
dtPlateauPositions.Rows.Add(rowNew)
Next intYCount
Next intXCount
End Sub
...
Jon
|
|
|
|
|
It's hard to say, as you haven't included enough of the code to follow it. You don't have any Instance , dsPlateauPosition or PlateauPositions properties in the class, and you never call the initDataSource method.
I see one problem in the code, though. You only create one DataRow object, so you would be adding the same data row to the table 1004004 times.
---
b { font-weight: normal; }
|
|
|
|
|
True, I actually excluded parts of the code intentionally (remarked with ...). I have updated the code to create a new row each time (see below), but the data set is still not being updated with rows.
Imports Rover
Public Class Plateau
'Singleton class. Must use Instance to initialize.
Private Sub New()
initDataSource()
End Sub
Public Shared ReadOnly Instance As Plateau = New Plateau
Private intXPositions As Integer
Public Property XPositions() As Integer
Get
Return intXPositions
End Get
Set(ByVal Value As Integer)
intXPositions = Value
End Set
End Property
Private intYPositions As Integer
Public Property YPositions() As Integer
Get
Return intYPositions
End Get
Set(ByVal Value As Integer)
intYPositions = Value
End Set
End Property
Public ReadOnly dsPlateauPosition As New DataSet("PlateauPositions")
Public Function isOccupied(ByVal Location As Coordinate) As Boolean
End Function
Public Function setOccupied(ByVal Location As Coordinate) As Boolean
End Function
Public Function clearOccupied(ByVal Location As Coordinate) As Boolean
End Function
Private Sub initDataSource()
'Create PlateauPostions, a working dataset that retains information about
'positions occupied on the grid.
Dim dtPlateauPositions As New DataTable("PlateauPositions")
'define attributes
With dtPlateauPositions
.Columns.Add("xPosition", System.Type.GetType("System.Int32"))
.Columns.Add("yPosition", System.Type.GetType("System.Int32"))
.Columns.Add("occupied", System.Type.GetType("System.Boolean"))
End With
'enforce composite primary key
Dim colPrimaryKey(1) As DataColumn
colPrimaryKey(0) = New DataColumn("xPosition")
colPrimaryKey(1) = New DataColumn("yPosition")
'create dataset
dsPlateauPosition.Tables.Add(dtPlateauPositions)
'initialize positions as not occupied
Dim rowNew As DataRow
Dim intXCount, intYCount As Integer
For intXCount = 0 To intXPositions - 1
For intYCount = 0 To intYPositions - 1
rowNew.Item("xPosition") = intXCount
rowNew.Item("yPosition") = intYCount
rowNew.Item("occupied") = False
rowNew = dtPlateauPositions.NewRow() 'updated!
dtPlateauPositions.Rows.Add(rowNew)
Next intYCount
Next intXCount
End Sub
End Class
Jon
|
|
|
|
|
That's better, now one can see what the problem is.
How could the intXPositions and intYPositions values used in the initDataSource method ever be anything other than zero? The object has to be created before you can set the properties, and the initDataSource method is called when the object is created. At the time you set the values of the properties it's too late for them to be used in the intDataSource method.
Now you create a data row for each row, but you create it after you have put the fields in the row, which means that you lose the reference to the row that contains the fields. What you will be adding to the table is an empty row. Also, as you don't create any row before the loop, you will be trying to add fields to a row that doesn't exist the first time. Create the row first, then add the fields to it.
---
b { font-weight: normal; }
|
|
|
|
|
oops
Jon
|
|
|
|
|
hi
i want to worked my program in network.i use from access database in my program.please help me or introduce sample code
thanks
|
|
|
|
|
Help you with what? The description you provided doesn't make any sense.
Are you asking how to connect to an Access database on another machine?
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
yes i want to connect to an Access database on another machine
thanks
|
|
|
|
|
Since Access is entirely file based, you have to setup Windows networking properly. This involves setting up a share on the server that is going to host the Access file, then setting up appropriate rights, user ID's, and assigning permissions.
Google for "Windows networking basics" for more information.
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
hi
i am working on vb 6.0.i nstall my project on several machine its working. but on one machine which dont have access data base driver it gives error "Data Source name not defined and default driver specified" can anybody help me how i know the driver info of the client and how i install them on machine if driver not availablr.
Thanks
|
|
|
|
|
You'll have to install a version of MDAC at the least. You can find it here[^].
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
I have a pretty simply project that I'd like to deploy. I tried using the publish wizard. It published OK, but I can't install the resulting files. I get this error:
tia.
OPERATION PROGRESS STATUS
* [9/29/2006 11:29:42 PM] : Activation of C:\Mydocs\Program Files\Trade Director\Install\CS_Director_1_0_0_0.application has started.
ERROR DETAILS
Following errors were detected during this operation.
* [9/29/2006 11:29:42 PM] System.Runtime.InteropServices.COMException
- The referenced assembly is not installed on your system. (Exception from HRESULT: 0x800736B3)
- Source: System.Deployment
|
|
|
|
|
Your application is trying to use a COM-based component that is not installed on the machine. Whatever that component is, it has to be installed before your app will run. If you don't know what it is, you might be able to find out by looking in the References folder of your app's source project.
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
Well, I'm going a little nuts. I have this app which is written in vb.net (2003). My problem is that you can not shut down windows when this app is loaded. This app sits in the system tray and the form visible property is set to false. You have to close down the app and then you can shutdown windows. I've been searching for days and found WndProc. I tried this. It will terminate the app, but will not shut down windows. It looks like the end session message is not being passed along. The code is below. Does anybody have any ideas? It would be much appreciated.
Private Const WM_ENDSESSION As Integer = &H16
Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)
If m.Msg = WM_ENDSESSION Then
bolWinShutDown = True
Application.Exit()
End If
MyBase.WndProc(m)
End Sub
Private Sub frmLanPopupExMain_Closing(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles MyBase.Closing
If bolWinShutDown = True then
e.Cancel = False
Else
e.Cancel = True
Me.Visible = False
End Sub
Thanks,
Dick Bellnier
|
|
|
|
|
You don't have to override WndProc to do this.
Does your app spawn any threads? This is probably the most common cause of this problem. Any threads have to be terminated before your app closes, unless the threads are tagged as Background threads.
Another is some people decide to handle the Form Close event so they can minize their form to the System Tray. But, it's usually not done properly because they forget that this event fires during Windows shutdown to close your application.
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
Hi,
I'm new here and it has been several years since I've done any serious VB coding. I used to do a lot of VB6 development and have not really touched it in about 8 years. .NET is brand new to me as well.
I need to create a quickie application either in VB6 or preferably VB.NET that does the following:
Reads through a directory of .XLS files reads the contents of 2 cells and renames the file based on the contents of those 2 cells.
In the old day's I'd have whipped this out in a couple of hours, but I've discovered that I've forgotten a lot of my VB syntax etc...
Can any one help by providing me a sample to get me started?
Thanks
Craig
|
|
|
|
|
hi
i am developing a project in which i have a main form in which i open another form with the main form still in the background. on making changes on this new form and clicking the save button this form closes and again the main form is visible but the changes made just does not reflect. how to reflect the changes?
Praveen Kumar
|
|
|
|
|
Is this a Windows application or a web application?
---
b { font-weight: normal; }
|
|
|
|
|
When you return focus to the main form the FormLoad event does not fire. What you probably want to do is put all (or most) of the code that is currently in your FormLoad event handler and move it into a public subroutine. When you close the second form, first have it call this new public subroutine to reload the main form's data before returning to the main screen.
Hope this helps.
|
|
|
|
|
i've looked and tried fixin this problem until i'm ready to pull my hair out. hopefully someone has the answer.
i want a combo box to display names from a table. the table has 2 fields (CoordinatorID and Coordinator). the id field is sequential.
when i run the program, the combobox works but assigns the place in the combobox as index instead of the CoordinatorID as the index (see code below). if i don't sort the list (removing "ORDER BY coordinator") it works fine, but i have to have it sorted for the end user.
what am i doing wrong? any help greatly appreciated,
thanks, chris
Public Sub FillCBO()
rs1.Open "SELECT * FROM tblCoordinator ORDER BY coordinator", Conn, adOpenStatic
If rs1.EOF = False Then
rs1.MoveFirst
Do
cboCoordinator.AddItem rs1.Fields("Coordinator")
cboCoordinator.ItemData(cboCoordinator.NewIndex) = rs1!CoordinatorID
rs1.MoveNext
Loop Until rs1.EOF = True
End If
rs1.Close
Set rs1 = Nothing
End Sub
|
|
|
|
|
AFAIK, the combobox will show items in the order passed in, unless you have the sorted property set to true.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
HI all
i wanna to create an application that must use functions in another computers.my application is ntier.and the dataaccess layer is in another computer that implemets an interface with name IDataAccess ,in the client application (UI) i must use DataAccess 's functions that referece them with new so i have to use Client Activator .and i dont want to use proxy.
Is there anybody that can help me
regards
Maryam82
|
|
|
|
|
I have a datatable that I have retrieved from a database (w00t!)
now I am trying to add a column to this datatable, but the add command only allows me to add a datacolumn to the end of the datatable collection
I want to add my new datacolumn to the start of the datatable (or potentially at any index ) and I haven't been able to figure out how to do this.
Any hints?
Thanks in Advance,
Jason
|
|
|
|
|
You can't add a column at any index you want. Anything you add will always be appended to the end. Besides, a DataTable object has no visible component, so it doesn't matter where the column is appended... Why do you want to do this?
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
I'm setting it as my datagrid datasource.
I'm reading data from several sources in my database. Based on the type of data I'm reading (whether it is Contact data or Business data etc) I wanted to add an icon column to my datagrid. This works fine, except the icon is the last column in my datagrid, I want it to be the first.
I assumed that I would do this at the datatable level, not at the datagrid level.
Jason
|
|
|
|