|
Actually, a better way would be to provide a ReadOnly Property called "Type". You can have this Property return an Enum (if you know how many ClassTypes you will have) or just a String if you Like. You could then Override the Property in the Derived Classes so that they can Return what Type of Class they are as well.
I find that Enums are great! Especially if you are allowing other Developers to use your Classes (since they don't know what Types to expect, Enums help a lot!).
'Base Class
Public Class Animal
'Enum
Public Enum AnimalTypes
Animal
Dog
Cat
Bird
End Enum
Public Overridable ReadOnly Property Type() As String
Get
Return "Animal"
End Get
End Property
Public Overridable ReadOnly Property Type2() As AnimalTypes
Get
Return Animal
End Get
End Property
End Class
'Derived Class
Public Class Dog:Inherits Animal
Public Overrides ReadOnly Property Type() As String
Get
Return "Dog"
End Get
End Property
Public Overrides ReadOnly Property Type2() As AnimalTypes
Get
Return Dog
End Get
End Property
End Class
|
|
|
|
|
I am taking a good look at what both of you have said...
I can understand why Richard Demming thinks that this would be very bad design, but in my defense I had a specific reason for doing it.
1 - The base class provides all but a very little part of the functionality of the library.
2 - The base library only exposes 3 classes that derive from the base class, and these classes can not be inherited from any further.
3 - The base class implementations of each method very only slightly in how certain database connections are handled based upon what class has inherited the base class.
4 - The bass class implementations are not really overridden. The derived class calls the base class implementations by using MyBase.Methodname.
I considered using an interface and some helper functions here in place of inheritance, but because the implementations are so close I was seeing the possibility for a lot of duplicated code.
As for your suggestions about using Enums, I totally agree I use enums wherever I can. In fact I have been accused of their overuse if you can imagine such a thing. I figure that, besides the other benefits, enums offer a way for the user to enter in parameters in a way that removes a large likelihood of error. They can't just make up values that way, but have to pick form a list.
Paul Watson wrote:
"At the end of the day it is what you produce that counts, not how many doctorates you have on the wall."
George Carlin wrote:
"Don't sweat the petty things, and don't pet the sweaty things."
|
|
|
|
|
Hello,
I have following code
<br />
Dim i As Integer<br />
i = 3/2<br />
from my knowleadge, if you set the variable as an integer, when you divide, (from the example) suppose to be i= 1 but right now i=2 because the answer i = 1.5 and automatically set the i to 2 . why is that? I don't want the decimal numbers, I want the integer. How can I fix that problem
Thanks
|
|
|
|
|
From my knowlage of vb, when it preforms type casting for you, it will always try to round. More information on this in the MSDN under cint(). If you just want to truncate your number, in this case either fix() or int() will do the job, however there is a subtle difference (regarding negetives) between them.
Try:
i = int(3/2)
Now i = 1
|
|
|
|
|
|
its rounding up...
.5 or higher rounds it up..
i believe there is a function to format numbers...i can't remember it though..sorry
"I'm not me when I dream...anymore." -TRUSTcompany
|
|
|
|
|
hi,
i have created an ActivexDll in vb and used it in a standard Exe by using CreateObject Function instead of selecting it in the References.I am Getting the output,but after this if i try to make the dll again by making some changes,i am getting the error "Permission denied:'C:\WINNT\System32\Project2.dll".Can anyone help me how to get rid of this problem?How can i release the Object created by CreateObject?This has become a headache.I shall be very happy if anyone provides a solution for this
shankar
|
|
|
|
|
Try the following - may help
set MyObj = Nothing
Think that should help. Alternatively, do you have your control embedded on a form in the project - if you do, VB6 will have to create an instance of it to display on the form (can't remember why, but there is a reason). If it has to do this, then the file will be locked, and the permission denied message may result
|
|
|
|
|
You will have to close both dll file and Vb application which it is calling from your application.
and set createdObj = nothing.
I hope this will solve your problem.
Thanks!
Manoj Madhavan
|
|
|
|
|
whilst you are debugging, you could install the component in COM+ with the Interactive User as the identity.
Then when you need to recompile the componet, just choose ShutDown on the COM+ package.
Also you could add reference to the COM+ typelibraries etc, and then search for the application and unload/shutdown it in code. THis has worked very well for me whilst making a Checkout system for an ecomm site.
|
|
|
|
|
having performed an update in a datagrid, i get this message box: " insufficient key column information for updating or refreshing" (even though the table in the database updates successfully), why is this? Thanking you!
|
|
|
|
|
mcm wrote:
having performed an update in a datagrid, i get this message box: " insufficient key column information for updating or refreshing" (even though the table in the database updates successfully)
There could be a number of reasons for your problem. One of the most common reasons is that your data was retrieved from multiple tables. The other tables would like to try updating, but they can't because the primary key is not available in the retrieved data.
If you could provide more specifics, you might get a more useful response. For example, what kind of data are you retrieving (Access, SQL, Oracle)? Are you using ADO, ODBC, or something else to get the data? We need enough information to "debug" the problem.
|
|
|
|
|
im so sorry for my lack of information - the following is code relating to populating the datagrid:
Dim strType As String
strType = DataComboType.Text
Dim strDesc As String
strDesc = DataComboDesc.Text
'selecting the appropriate values
Dim findSQL As String
findSQL = "SELECT Price.ProductCode, Product.Description, Price.Price " & _
" FROM ProductType INNER JOIN (Product INNER JOIN (PriceDescription INNER JOIN Price ON PriceDescription.PriceCode = Price.PriceCode) ON Product.Code = Price.ProductCode) ON ProductType.TypeCode = Product.TypeCode " & _
" WHERE (((PriceDescription.PriceDesc) = '" & strDesc & "') AND ((ProductType.Description)='" & strType & "'))"
Set RS = Conn.Execute(findSQL)
'refreshing the grid
Adodc3.RecordSource = findSQL
DataGrid1.Visible = True
Set DataGrid1.DataSource = Adodc3
Adodc3.Refresh
'DataGrid1.Refresh
cmdSave.Enabled = True
i wish to edit details in the grid once populated but it returns that error when i make any changes in the grid - its access im using in the backend. if you require anymore information, let me know - thank you so much for your time!
|
|
|
|
|
Anonymous wrote:
findSQL = "SELECT Price.ProductCode, Product.Description, Price.Price " & _
" FROM ProductType INNER JOIN (Product INNER JOIN (PriceDescription INNER JOIN Price ON PriceDescription.PriceCode = Price.PriceCode) ON Product.Code = Price.ProductCode) ON ProductType.TypeCode = Product.TypeCode " & _
" WHERE (((PriceDescription.PriceDesc) = '" & strDesc & "') AND ((ProductType.Description)='" & strType & "'))"
You are selecting data from the Price and Product tables. Which colunns are being edited? To update the Description, you need the primary key of the Product table to be included in the data. To update the ProductCode or Price columns, you need the primary key of the Price table in the data.
Without the primary key columns in the data, the proper row can't be located for updating.
|
|
|
|
|
Hello, I have the following problem: I created an inherited class that inherits DataGrid and I added a property called MyProperty as integer. Then I created another class called CustomDesigner that inherits from System.Windows.Forms.Design.ControlDesigner and I setup the Design Attribute for my grid class to use this custom designer.
All works ok (I can see some messages I inserted in the Initialize() function in the designer)... but... I fail to understand how to make the actual "connection" between the changes in the property and the code behind the form. For example, if I change the property "AllowDrop" from the default value of false to True, if I look in the code, right away the line: Me.TestGrid1.AllowDrop = True appears in the InitializeComponent() routine....
But, when I change the additional property (MyProperty) nothing changes in the code behind the form, therefore rendering my custom designer to a useless item...
So, my question is: how can I "catch" the changes in the properties that extend a base class and reflect them in the InitializeComponent() function from the code behind the form?
Any help is appreciated,
Thank you!
Iulian
PS: If you know any books that talk about custom designers...
Best Regards,
Iulian
|
|
|
|
|
Does any one have a activation key for "Planet Source Code Visual Basic 2002 CD".
this cd can be downloaded as a trial version which runs only 15 searches.
http://www.exhedra.com/Exhedra/ProductCatalog/Descriptions/PSCCD_2002VB.aspx
thanx
|
|
|
|
|
on my form i have textboxes and a datagrid, each column in the datagrid relating to each of the texboxes on the form. When i click the "new" command button, i am blanking out the text in the textboxes to allow for new entry. I also want the cursor in the datagrid to point to a new row (record) (i have set the property of the datagrid to AllowAddNew), how do i do this?
Thanks in advance!
|
|
|
|
|
how can i declare structure in VB
I know that in C++
struct egStruct
{
int a;
int b;
};
void main()
{
egStruct egS;
egS.a = 2;
egS.b = 6;
}
is it
Private Type egStruct
Dim a As Integer,b As Integer
End Type
thanks
|
|
|
|
|
In Visual Basic 6.0...
Public Type egStruct
a As Integer
b As Integer
End Type In Visual Basic .NET...
Structure egStruct
Public a As Integer
Public b As Integer
End Structure
Jeremy Falcon
Imputek
|
|
|
|
|
Hi,
As follow:
Type egStruct
A As Integer
B As Integer
End Type
A. Riazi
|
|
|
|
|
|
Is it possable in VB.NET to execute an application on a remote machine over the internet so that the application opens (executes) on that specific web server. For examle: "c:\windows\system32\notepad.exe c:\file.txt" this should then open file.txt in notepad on the remote machine. I suppose this should be a SOAP, XML function.
|
|
|
|
|
not sure about vb.net, but this should still work.
Search the WMI stuff relating to remote launching, you basically connect to the server(remote machine), then tell it to create a process.
I've written a component to do this in C++, but the reason for that is I'm using a Dialup connection to connect to 380 machines, and I need other operations to continue whilst the WMI connection starts(in a thread).
If you don't have these issues, there are lots of WMI examples in MSDN for doing this.
This is a function I've used previously.
<br />
Function LaunchRemoteProgram(program As String, Optional user As String = "", Optional pass As String = "", Optional servername As String = ".") As Integer<br />
Dim objLocator As WbemScripting.SWbemLocator<br />
Dim objService As WbemScripting.SWbemServices<br />
Dim objInstance As WbemScripting.SWbemObject<br />
<br />
Set objLocator = New WbemScripting.SWbemLocator<br />
On Error Resume Next<br />
If servername = "." Then<br />
Set objService = objLocator.ConnectServer(".", "root\cimv2")<br />
Else<br />
Set objService = objLocator.ConnectServer(servername, "root\cimv2", user, pass)<br />
End If<br />
<br />
If Err.Number Then<br />
'<br />
LaunchRemoteProgram = Err.Number<br />
Else<br />
Set objInstance = objService.Get("Win32_Process")<br />
objInstance.Security_.AuthenticationLevel = wbemAuthenticationLevelConnect<br />
objInstance.Security_.ImpersonationLevel = wbemImpersonationLevelImpersonate<br />
objInstance.Create program, Null, Null, LaunchRemoteProgram<br />
End If<br />
End Function<br />
Hi this is of use to you.
|
|
|
|
|
hi,
i want to zip a file in vb or in asp,can any one help me in code/syntax or atleast tell me good sites so that i can refer that,i am new to this concept.I require any of ur guidance.Thanks in advance
|
|
|
|
|
if you have winzip 8.0, that's easy.. just use winzip command lines by calling system(). the command line is only avilable on winzip version 8.0 and above.
for example
CString str = "wzzip -d c:\temp c:\temp.zip";
system(str)
hope this will help you...
|
|
|
|