|
You are generating new plate objects for comparison, however IndexOf does an object comparison. The newly created objects will never match anything in your list.
What Indexof is doing is iterating through the list calling Equals to compare each object in turn. The only way your comparison can work is to override the Equals method on your PlateObj . E.g.
Public Overrides Function Equals(ByVal obj As Object) As Boolean
Dim plate As Plateobj = TryCast(obj, Plateobj)
If plate Is Nothing Then Return False
If plate.Name <> Me.Name Then Return False
If plate.Order <> Me.Order Then Return False
Return True
End Function
If only the names need to match then only compare the names.
|
|
|
|
|
Mr Kuryakin
Thanks for the answer this makes sense I did try before posting a compareto function in the plateobj class, which I have successfully used for sorting.
Ok so how to use the code you posted.
1) I assume I add this to the plateobj class ?
2) I get an error that suggests instead of using Overides I should use Overloads
3) Dim plate As Plateobj = TryCast(obj, Plateobj)gives two errors
- TryCast not declared
- 'Plateobj' is a type and cannot be used as an expression.
Could I ask you to insert your code into my example and post back.
Many Thanks
Geoff
|
|
|
|
|
Hello every body
I want to know the ascii code of Backspace and Delet in vb.Net.how I can find those? please tell me the functions.
I want user writes in a textbox only numbers, this is my code
< If IsNumeric(e.KeyChar) = False Then
e.KeyChar = ""
End If >
but in this way user can not use delet and backspace. I want to active these 2 buttons by ascii codes?
please help me. thank you
|
|
|
|
|
You can use following code to check if backspace was pressed:
e.KeyChar == (char)Keys.Back
I just checked in KeyPress event of the textbox. It does not seem to handle delete button press. Hence I think it should work fine.
50-50-90 rule: Anytime I have a 50-50 chance of getting something right, there's a 90% probability I'll get it wrong...!!
|
|
|
|
|
thank you, but unfortunately following code does not work:
e.KeyChar == (char)Keys.Back
|
|
|
|
|
Well, that is not the complete code. That is merely the condition you should be having in your if statement. Moreover, that is C#, I don't know how you would check for quality in VB.
50-50-90 rule: Anytime I have a 50-50 chance of getting something right, there's a 90% probability I'll get it wrong...!!
|
|
|
|
|
Why don't you use Keys enumeration e.g. Keys.Back and Keys.Delete .
|
|
|
|
|
Hi,
some basic info for you:
1. In .NET all characters and strings are Unicode, not ASCII.
2. Hitting a key causes several events, starting with a KeyDown; have a look at KeyEventArgs
3. Keys are identified primarily by their KeyCode, not their KeyChar
4. there is a Keys enumeration to help you identify keys, including all the special keys.
5. only some keys (the ones typically generating text) also fire the KeyPress event
6. you can influence some of the key handling by using ProcessCommandKey, IsInputKey, and maybe some more; however you would seldom need these.
So start using KeyDown event and KeyCode value.
Luc Pattyn [Forum Guidelines] [My Articles]
I only read code that is properly indented, and rendered in a non-proportional font; hint: use PRE tags in forum messages
|
|
|
|
|
Hi All,
I have a SQL database column "ID", in which I added one by one entries as 2,5,6,1,8... randomely.
I want to arrange these entries in Ascending order so that in datagridview it get displayed in order 1,2,3,4... like this.
Can someone help me on this?
Thanks.
|
|
|
|
|
Use order by in the query/stored procedure you are using to retrieve the data.
50-50-90 rule: Anytime I have a 50-50 chance of getting something right, there's a 90% probability I'll get it wrong...!!
|
|
|
|
|
This is not the appropriate forum for your question. Choosing the correct forum helps you get more answers (and better answers).
|
|
|
|
|
If you have a SQL Question Post here
General Database
http://www.codeproject.com/Forums/1725/General-Database.aspx[^]
in the Query that you use to display the Grid with , add the Following line of SQl
Order by ID ASC
Vuyiswa Maseko,
Spoted in Daniweb-- Sorry to rant. I hate websites. They are just wierd. They don't behave like normal code.
C#/VB.NET/ASP.NET/SQL7/2000/2005/2008
http://www.vuyiswamaseko.com
vuyiswa@its.co.za
http://www.itsabacus.co.za/itsabacus/
|
|
|
|
|
So I have finally figured out how to dynamically add data to comboboxes created on the fly however I still cant create an on change event for the combobox.
Heres what I am looking at doing.
Set optioncombobox = Me.controls.Add("Forms.ComboBox.1", "Cheese" & comboNumber)
With optioncombobox
.Text = "Please Select an option..."
.left = 114
.width = 276
.top = 102
.Height = 18
End With
While Not (IsEmpty(Range("'Info'!a" & Counter)))
X = Range("'Info'!a" & Counter).Value
If InStr(1, X, "|") > 0 Then
Else
With controls("Cheese" & comboNumber)
.AddItem (Range("'Info'!b" & Counter).Value)
End With
End If
Counter = Counter + 1
Wend
Then I am trying to create something like this
Private Sub Controls("Cheese1")_Change()
Do Stuff
End Sub
But I am getting an error saying "Expected: Identifier"
Anyone have any thoughts on how I can resolve this??
However when I create a commandbutton click event it can do all of this with no issue.
But I want to do this in an On Change event.
Even if there is some way to run an event if any combobox on the whole form changes that would be fine.
|
|
|
|
|
In VB6, handling events for dynamically added controls in quite difficult. There is a keyword WithEvents that may help you, but I am not sure how you can use it with dynamically added controls.
Your syntax for event method declaration is totally wrong Work on the WithEvents keyword.
|
|
|
|
|
Why are you still using VB6 in 2009 ?
Vuyiswa Maseko,
Spoted in Daniweb-- Sorry to rant. I hate websites. They are just wierd. They don't behave like normal code.
C#/VB.NET/ASP.NET/SQL7/2000/2005/2008
http://www.vuyiswamaseko.com
vuyiswa@its.co.za
http://www.itsabacus.co.za/itsabacus/
|
|
|
|
|
Hi,
I am using SQL database with VB. The database "company" has 1 column "EmpID" which I filled with 0,1,2,... so on, and "EmpID" column is in string format.
Now I want to get the MAX of this "EmpID", for this I wrote a code like this in VB :
SELECT MAX(EmpID) From company.
I found that out of 0 to 150 EmpID in database, it is selecting MAX value as 9 and sometime as 99.
I think there is something wrong with this. Also, If I test it for small data, say from 1 to 15, it is selecting correct MAX value.
Can someone help me how to do this? My basic idea is to get the last "EmpID" which I will add and use it as next "EmpID".
Thanks
R.S.
|
|
|
|
|
I think that is because your EmpId id not an integer in your database. It something be varchar or something similar. You should change it to int if it can have only integer values. In order to make the query work in current condition, use following:
SELECT MAX(cast(EmpID as int)) From company
Note that this is not a good practice.
50-50-90 rule: Anytime I have a 50-50 chance of getting something right, there's a 90% probability I'll get it wrong...!!
|
|
|
|
|
It is because your EmpID is stored as text instead of number. The correct datatype to use is 'int', and your EmpID column most probably is 'varchar' datatype.
|
|
|
|
|
Select MAX(cast(EmpId as int)) from TblName
OR
Select top 1 EmpId from TblName order by EmpId desc
Niladri Biswas
|
|
|
|
|
Dear,
Could any body assist me regardig the following issues.
1. In my VB project when I am trying to upload .xls file.Error message is coming "Run Time Error '-2147319779(8002801d)' Automation Error : Library Not Registered"
Code Line where error is coming...
<br />
If (fso.FileExists(Trim(Text1.Text)) = False) Then <br />
however same code is running in other machine without any error.
Please let me know asap.
Thanks
Ashish
modified on Friday, November 27, 2009 1:09 AM
|
|
|
|
|
I believe this is VB6 code and you are using File System Objects in your code. Your target system is missing the Microsoft Scripting Runtime Library DLL (scrrun.dll).
Please note that there is a known versioning problem with this DLL. Ensure that you copy and register the correct version that you have compiled your application with.
|
|
|
|
|
Dear Shameel,
I have done what I was told by you.Still the same error is coming.Even I have given full rights for me(as a login user).
Could you/anybody suggest me for that...
Thanks
Ashish
|
|
|
|
|
Check if you have scrrun.dll in your target box (typically in %System32% folder), and if it matches the exact same version of the dll that is in your development box.
|
|
|
|
|
mates,
Is it possible to automatically open an excel print preview?
if possible, can you give me an idea how to do it..
thanks.
note: I will code this in visual basic.
thanks in advance
C# コードMicrosoft End User
2000-2008
「「「「「「「「「「「「「「「「「「「「「「「「「「「「
The best things in life are free
」」」」」」」」」」」」」」」」」」」」」」」」」」」」
|
|
|
|
|
I think you can use Microsoft.Office.Interop.Excel.Workbook.PrintPreview method for this.
50-50-90 rule: Anytime I have a 50-50 chance of getting something right, there's a 90% probability I'll get it wrong...!!
|
|
|
|