|
WOOOOOO it actually seems to work.
Quick question though I tried to trick the code to see if the sort is actually working and it doesn't appear to sort the highscores into numerical order.
All i actually done was just move the highest score to the bottom of the text file, so only one of them was out of sync.
There also seems to be an error on button click, which i think is part of the sorting.
Private Sub comtest_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles comtest.Click
username = Text1.Text
userscore = Val(Text2.Text)
For i = 1 To 10
a = scores(i)
If userscore >= a Then
test1(i) = username
test2(i) = userscore
For b = i + 1 To 10
test1(b) = names(b - 1) ' comes up with an error saying ArgumentOutOfRage index was out of range, must be non-negative
test2(b) = scores(b - 1)
Next
Call newscore()
Exit Sub
End If
test1(i) = names(i)
test2(i) = scores(i)
Next
End Sub
Any ideas
Many thanks for all the help
Cheers
Dan
modified on Wednesday, April 14, 2010 10:46 AM
|
|
|
|
|
Sorting in the listbox won't work because it sorts the entries as strings and not in numerical order. So it sorts like 10,100,11 and so on.
This is a bit tricky to solve. You could padd left the scores with 0. The scores would then be 010,100,011 which would sort correctly. Try to google for a solution to this. There are a number of options you have.
Same problem in your code with the amount of entries in names list? Try ...To names/scores.count-1 instead of ..To 10
Tosch
|
|
|
|
|
1) Gotta get used to zero-indexed arrays/lists... In programming, everything starts at zero (Once you get beyond VB6)...
An array or list with 10 elements actually goes from 0 to 9. There's no element #10 (That would be the 11th element). If you count from 1 to 10, you skip the first element (0) and go past the last element (9).
2) When you're using the .NET framework, try not to reinvent the wheel. You shouldn't have to write your own sorting routine in most cases, because the framework already has those kinds of things built-in.
3) Try to think in terms of objects, not simple arrays. You're working with these things as arrays of strings and integers, when you're really dealing with high scores, each of which has a name and a value. You need to put them together so you can work with them more easily... That requires a class or structure...
Public Class HighScore
Dim Name As String
Dim Score As Integer
End Class
4) Once you put them together like this, it's a lot easier to shuffle them around as needed. If you have a List(Of HighScore) , you can even automate the sorting by just calling the Sort() function. The only trick there is that you have to tell it how a HighScore should be sorted:
Public Class HighScore
Implements System.IComparable(Of HighScore)
Dim Name As String
Dim Score As Integer
Public Function CompareTo(ByVal other As HighScore) As Integer
CompareTo = -Score.CompareTo(other.Score)
End Function
End Class
Now a HighScore object knows that it should be sorted by score. Since we negate the result in the CompareTo function, it puts it in descending order instead of ascending order. When you tell the list to Sort(), it'll know what to do.
5) But then, you want to ALWAYS have it sorted, right? Well, the framework can do that too... Instead of a List(Of HighScore) , try using a SortedList(Of HighScore) . Then you don't have to do any work at all... When you add the new score in, it'll automatically jump to the right spot.
6) As for displaying them... Well, ListBoxes are pretty smart too... Now it's been a while since I've worked with WinForms (WPF is the new way to do things), but if I remember right, ListBoxes have a "DisplayMember" property. In this case, you can just set the DisplayMember of the two lists to "Name" and "Score" respectively, and then just add the HighScore objects to them. If the DisplayMember is "Name", the control will look for a "Name" property on the object you add, and display just that property.
Anyway, that should get you pointed in the right direction.
|
|
|
|
|
WOW thanks,
However i am having a few probelms, the
Ian Shlasko wrote: SortedList(Of HighScore)
doesn't seem to work,
I have put this code under a button click and it comes up with an error saying
"no accessible 'sorted list' accepts this number of type arguments"?
I am really grateful of the time you put in explaining in depth what is needed, it was just strange that it ain't working.
I am using vb.net 2005, in normal design mode (not in console) if thats any help
|
|
|
|
|
Oh right, I always forget that... The SortedList takes two arguments, so it would be SortedList(Of Integer, HighScore) (Can't remember if that's the exact syntax, as I usually code in C#). When you add something to it, you'd do .Add(item.Score, item) , so it knows to sort it by the score.
|
|
|
|
|
hmmmm there seems to be something not right with the code.
I dont have to define SortedList of anything like that, as it still doesn't like
Ian Shlasko wrote: SortedList(Of Integer, HighScore)
I really am grateful for all the help
Dan
|
|
|
|
|
Make sure you're working with the one in System.Collections.Generics. There's a generic and regular version.
|
|
|
|
|
Hi!
i want to show the errorprovider icon within a column of a datatable. and this datatable is bound to datagrid.
is there any solution for this?
|
|
|
|
|
Are you to do anything to this column?
click it?
show under certain conditions?
otherwise have a look at this should show you what sort of columns you can have in a grid
Datagridview Column Types.
Bit more info on what you are trying to do will allow a better solution to be given
|
|
|
|
|
Hi!
thanks for ur reply!
yes i have some business logic on this column. this column can accept only three values.
1 - store
2 - development agent
3 - previous owner
anything else user trying to do system shud show errorprovider on this column with some altert message as well.
|
|
|
|
|
If user enters these values then you will need to use the DataGridView1_CellValueChanged event and then evaulate what the user has entered.
<br />
Private Sub DataGridView1_CellContentClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellContentClick<br />
If e.ColumnIndex = 2 Then <br />
'assuming this is your column number for store, development agent, previous owner<br />
'then show your error message if not enter what is required<br />
End If<br />
<br />
End Sub<br />
if the values are coming from the database only then you need to re-look at your database query.
Simon
|
|
|
|
|
Hi appreciate if someone can help me in this or who already passthrogh this situation
We have bunch of c++ and vb,asp classic and cobol application.
They all need to consume WCF service .
I have read related links as well as MSDN sample but not much strongly helpful.Can someone help me out ?
app.config and proxyclient.cs is ready. But don't know excatly how to communicate ?
Thanks!!
|
|
|
|
|
If you can use dotnet, make a com-wrapped dotnet dll that handles the wcf. Then use createobject from the vb6 application to the com-wrapped dll and your off and running.
'Never argue with an idiot; they'll drag you down to their level and beat you with experience.' ~ anonymous
'Life's real failure is when you do not realize how close you were to success when you gave up.' ~ anonymous
|
|
|
|
|
Can you elborate the answer ?
|
|
|
|
|
|
Correct.
'Never argue with an idiot; they'll drag you down to their level and beat you with experience.' ~ anonymous
'Life's real failure is when you do not realize how close you were to success when you gave up.' ~ anonymous
|
|
|
|
|
Really not helpful
Everytime I got message "entry point cound not found" when adding reference in my VB application
and I didnt get any com class.
|
|
|
|
|
I have 4 com-wrapped dlls in my production environment so it works quite well. Let's see your class and makes sure it looks correct. There is also a setting in the project that you have set for com-interoptability.
'Never argue with an idiot; they'll drag you down to their level and beat you with experience.' ~ anonymous
'Life's real failure is when you do not realize how close you were to success when you gave up.' ~ anonymous
|
|
|
|
|
actually I don't have idea about how can we add the .cs/.vb(which is created file by svcutil) and app.config file in COMClass ?
|
|
|
|
|
The article that you pointed out in an earlier answer shows you what you need to do to expose the dotnet class to com. This whole thing started because I thought you were familar with dotnet since you are going to have to write your own wcf code to talk to your services(svc files on the web server) anyway. If this is not true, your going to have to do some research on how to either bypass the need for dotnet on the UI side or research how to use dotnet and find a wcf example and adopt it to what you want to do.
'Never argue with an idiot; they'll drag you down to their level and beat you with experience.' ~ anonymous
'Life's real failure is when you do not realize how close you were to success when you gave up.' ~ anonymous
|
|
|
|
|
Hi, the COM wrapper has the clientproxy.cs, app.config (These 2 are from add service reference in vs 2008), COMClass.vb
When I built, its create the tlb file in vs. 2008.but when I added this type library (.tlb) in visual basic 6.0 and ran it I got the Error
<b>"Could not find the default endpoint element that references contract ' ‘in the ServiceModel client configuration section. This might be because no configuration file was found for your application, or because no endpoint element matching this contract could be found in the client element."</b>
Here is the application I have created one COM wrapper in VS2008 and added wcf (Add service reference) service ,Did some necessary code to instantiate the object and call methods of WCF service And run it so I got one tlb file in my bin folder which I used in my VISUAL BASIC 6.0 application.
I tried lots for dyanamic proxy and configuration with creating channel factory but not helpful .I will appreciate if someone can help me in....
Thanks
|
|
|
|
|
Hi,
One of my user is having A4 Printer only. But my program required A3 paper size.So how to allow the user to access that report?
Is it possible? Im using VB.Net 2008
Thanks
|
|
|
|
|
Rework your report so it'll fit an A4 size?? Seems kind of obvious to me...
|
|
|
|
|
I don't think it is possible to resize the page of a Crystal Report automatically: that would require repositioning every element on the page, and the resulting layout probably would not look pretty.
A report formatted to a smaller page will print just fine on a larger page. Resize your report to use A4 (which is a much more common size paper anyway) and it will still be useable on an A3 printer.
|
|
|
|
|
As a quick work-around you could print the a PDF Virtual printer, then use Adobe Acrobat Reader to print, as it has options to scale down your PDF to fit available paper sizes.
Steve Jowett
-------------------------
Real programmers don't comment their code. If it was hard to write, it should be hard to read.
|
|
|
|