|
Ok this is my code
Dim sqlstr as String
sqlstr = "SELECT * FROM Products WHERE PrdName Like 'MS'"
Data1.RecordSource = (sqlstr)
Data1.Refresh
the string "MS" exists in so many records but the result is not what it should be ???
It returns 0 records found.
any ideas ???
Thanx
|
|
|
|
|
Try this...
sqlStr = "SELECT * FROM Products WHERE PrdName LIKE 'MS%'"
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."
|
|
|
|
|
For the sake of this question I will use the old animal example that gets used in all the basic inheritance books..
Lets say that I have a base class called CAnimal and I inherit it to another class called CDog
Form within CAnimal, is there a way that I can get the type that is the parent (CDog in this case)? I would like to perform some processing differently in the base class depending on what subclass has called it.
If there some way I can do something like Me.Parrent.GetType("Cdog") ?
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."
|
|
|
|
|
You can use TypeOf(Me) :
Public Class Animal
Public Sub Bark()
If TypeOf(Me) Is Dog Then
Console.WriteLine("Bark!")
Else
Console.WriteLine("I can't bark!")
End If
End Sub
End Class
Public Class Dog : Inherits Animal
End Class However, this is very bad design. You should provide generic functionality in the base class, and then override or extend that functionality in the derived class:
Public Class Animal
Public Overridable Sub Bark()
Console.WriteLine("I can't bark!")
End Sub
End Class
Public Class Dog : Inherits Animal
Public Overrides Sub Bark()
Console.WriteLine("Bark!")
End Sub
End Class If you can't provide generic functionality in the base class, you can make the method abstract (MustOverride):
Public MustInherit Class Animal
Public MustOverride Sub Bark()
End Class
Public Class Dog : Animal
Public Overrides Sub Bark()
Console.WriteLine("Bark!")
End Sub
End Class If the functionality is not applicable to all classes derived from the base class, consider removing it from the base class. For example, you wouldn't want your Cat class to have a Bark method!
"These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer
|
|
|
|
|
I want to thank both of you for your comments on this… After taking a long hard look at the architecture I had originally selected I finally decided to refactor things a bit and moved away from the inheritance aspect since there were some apparent, albeit subtle, differences in the implementation between what each child class needed. I ended up using an interface style and backed it up by using come common helper functions behind the scenes. I even ended up lowering my LOC count by about 30% and dropping the complexity of the design a significant amount because of it.
I also noticed that the problem with my chosen implementation seemed to become apparent when I started the steps of documenting the class with XML docs. There were things showing up in the docs (I am using Ndoc) and things exposed to the outside world that I did not want exposed. The process of building the documentation for the library pointed that out very quickly.
Thanks again…
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."
|
|
|
|
|
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
|
|
|
|