|
Sorry,
I just tried that, so the code is
names = New System.Collections.Generic.List(Of String)
but it comes up with an error as well as a blue squigly underneath saying it cannot be converted to '1 dimensional array of string??
I thank you for your patience
Dan
|
|
|
|
|
No worries.
Sounds like you have left the declaration of your variable as Dim names as string() . You need to change that to a List(Of as well. E.g.
Dim names = System.Collections.Generic.List(Of String)
names = New System.Collections.Generic.List(Of String)()
Or
If you have knowledge, let others light their candles at it.
Margaret Fuller (1810 - 1850)
<a href="http://www.codeproject.com/script/Articles/MemberArticles.aspx?amid=926797" target="_Blank">[My Articles]</a> <a href="http://JacksonSoft.co.uk" target="_Blank">[My Website]</a>
|
|
|
|
|
Thanks a lot
I have decided to show the code that i am using from start to fininsh.
I am using 1 button called comtest
2 list boxes called listBox1 and ListBox2
2 textboxes called text1 and text2
Imports System.IO
Public Class Form1
Dim scores = New System.Collections.Generic.List(Of String)
Dim names = New System.Collections.Generic.List(Of String)
Dim test1(0 To 10) As String
Dim test2(0 To 10) As Integer
Dim userscore As Integer
Dim username As String
Dim a As Integer
Dim b As Integer
Dim i As Integer
Dim strFilename As String = ("High Scores.txt")
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Call highscore()
names = New System.Collections.Generic.List(Of String)
scores = New System.Collections.Generic.List(Of Integer)
Dim srScores As New IO.StreamReader(strFilename)
While Not srScores.EndOfStream
Dim strRead As String = srScores.ReadLine
ListBox1.Items.Add(strRead)
Dim strSplit() As String = Split(strRead, ",")
names.Add(strSplit(0))
scores.Add(strSplit(1))
End While
srScores.Close()
End Sub
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)
test2(b) = scores(b - 1)
Next
Call newscore()
Exit Sub
End If
test1(i) = names(i)
test2(i) = scores(i)
Next
End Sub
Private Sub highscore()
For i = 1 To 10
ListBox1.Items.Add(names(i))
List2.Items.Add(scores(i))
Next
End Sub
Private Sub newscore() ' write
ListBox1.ClearSelected()
List2.ClearSelected()
For i = 1 To 10
ListBox1.Items.Add(test1(i))
List2.Items.Add(test2(i))
names(i) = test1(i)
scores(i) = test2(i)
Next
Dim objWriter As New System.IO.StreamWriter(highScoresFile)
For i = 1 To 10
objWriter.Write(names(i) & "," & scores(i))
Next
objWriter.Close()
End Sub
This is the VB6 version with the same properties
Dim scores(1 To 10) As Integer
Dim names(1 To 10) As String
Dim test1(1 To 10) As String
Dim test2(1 To 10) As Integer
Dim userscore As Integer
Dim username As String
Dim a As Integer
Dim b As Integer
Private Sub 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)
test2(b) = scores(b - 1)
Next
Call newscore
Exit Sub
End If
test1(i) = names(i)
test2(i) = scores(i)
Next
End Sub
Private Sub Form_Load()
Open App.Path & "\files\high scores.txt" For Input As #1
a = 1
While Not EOF(1)
Input #1, names(a), scores(a)
a = a + 1
Wend
Close #1
Call highscore
End Sub
Private Sub highscore()
For i = 1 To 10
List1.AddItem names(i)
List2.AddItem scores(i)
Next
End Sub
Private Sub newscore()
List1.Clear
List2.Clear
For i = 1 To 10
List1.AddItem test1(i)
List2.AddItem test2(i)
names(i) = test1(i)
scores(i) = test2(i)
Next
Open App.Path & "\files\high scores.txt" For Output As #1
For i = 1 To 10
Print #1, names(i) & "," & scores(i)
Next
Close #1
End Sub
I thought i had done coded the vb correctly with the help of zimvbcoder and the man from U.N.C.L.E howver have made a mistake somewhere. If someone can help me that would be very very very very helpful
Again thanks a million
Dan
|
|
|
|
|
I assumed that the list of names and the list of scores would be previously declared. To be honest with you I would create a class Player in my app, and in that class you could have a function GetAllPlayers which would look like this :
Imports System.IO
Public Class Player
Implements IComparable
Private strName As String
Private intHighScore As Integer
Public Property Name() As String
Get
Return strName
End Get
Set(ByVal value As String)
strName = value
End Set
End Property
Public Property HighScore() As Integer
Get
Return intHighScore
End Get
Set(ByVal value As Integer)
intHighScore = value
End Set
End Property
Public Function CompareTo(ByVal obj As Object) As Integer Implements System.IComparable.CompareTo
Dim OtherPlayer As Player = CType(obj, Player)
Return Me.HighScore - OtherPlayer.HighScore
End Function
Shared Function GetAllPlayers(ByVal FileName As String) As List(Of Player)
Dim lstPlayers As New List(Of Player)
Dim strFilename As String = FileName
Using srScores As New StreamReader(strFilename)
While Not srScores.EndOfStream
Dim newPlayer As New Player
Dim strRead As String = srScores.ReadLine
Dim strPlayerProperties() As String = Split(strRead, ",")
newPlayer.Name = strPlayerProperties(0)
newPlayer.HighScore = strPlayerProperties(1)
lstPlayers.Add(newPlayer)
End While
End Using
Return lstPlayers
End Function
End Class
Then you can declare a list(Of Player) in your main form and populate it like this :
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Try
lstPlayers = Player.GetAllPlayers(My.Settings.HighScoresFile)
lstPlayers.Sort()
For i As Integer = 0 To lstPlayers.Count - 1
ListBox1.Items.Add(lstPlayers(i).Name & ", " & lstPlayers(i).HighScore)
Next
Catch ex As System.IO.IOException
MsgBox("There was an error retrieving High Scores.")
End Try
End Sub
This is very simple but a good way to start thinking in a more structured way.
|
|
|
|
|
This LOOKS pretty awsome
I have one error and i don't actually know why.
lstPlayers = Player.GetAllPlayers(My.Settings.HighScoresFile)
VB doesn't like .High Scores File.
This is probably something stupid whch i've done but i can't work out why that doesn't like it?
Thanks again
Dan
|
|
|
|
|
Hi there. Sorry it is my fault, I forgot to mention that where ever possible it is not a good idea to hardcode things like Filenames, Connectionstrings, etc into your app. The best way to do this is to use your Application.Settings file which is automatically generated for you by VS. To access the settings file, right click on your project in Solution Explorer, select properties and a form should open up with various tabs to set up options for your app. Select Settings tab and there you can store application specific settings such as file names and connection strings. To set up HighScoresFile, type the name HighScoresFile under name, under type select string, under scope select application, and under value put the full address of the file. To access any of your settings then from your app you call My.Settings.'insert setting name here' . When considering where to put the file, you need to take into account where you will deploy the application and where the High Scores file will actually be kept when the app has been deployed on other machines. Hope this helps.
|
|
|
|
|
when running application when program hits this code I get this error.
<code> For y As Integer = 0 To frmtodayscafe.count
For x As Integer = 2 To 12
writeline1(x) = filename(y) + vbTab + frmtodayscafe.totalitemquantity(y) + vbTab + FormatCurrency(filename1(y)) + vbTab + vbTab + FormatCurrency(frmtodayscafe.cost(y))
Next
Next</code>
cheeseburger is assign to filename(y) which is declared as a string array
filename1(y) is a numeric value cost of the cheeseburger. writeline1(x) is also a string array.
by changing the code to the following:
writeline(x) = filename(y) + vbTab + format(frmtodayscafe.totalitemquantity(y)) + vbTab + FormatCurrency(filename1(y)) + vbTab + vbTab + FormatCurrency(frmtodayscafe.cost(y))
modified on Monday, March 8, 2010 12:30 PM
|
|
|
|
|
Where come from the value "cheeseburger"? Which variable hold that value? Are you trying to do a "FormatCurrency" on that value?
|
|
|
|
|
cheeseburger is a string loaded from a file .... I am trying to write the string to a concatenated string to include qty, pricing, and total pricing.
it should say on the string
cheeseburger 1 $3.00 $3.00
|
|
|
|
|
What is the type of writeline1(x)? Is it a string or double?
|
|
|
|
|
wireline1 is a string array
|
|
|
|
|
You are doing a FormatCurrency on a string value of "Cheeseburger".
I know of few countries where cheeseburgers are legal tender.
You may want to try the amount (double) rather than the file name (string).
|
|
|
|
|
filename(0) = cheeseburger
filename1(0) = 5.00
filename1(0) is being formatted to currency by not filename(0)
cheeseburger is not being formatted as double.
|
|
|
|
|
by changing the code to the following has resolved issues. there are no more errors at runtime.
writeline(x) = filename(y) + vbTab + format(frmtodayscafe.totalitemquantity(y)) + vbTab + FormatCurrency(filename1(y)) + vbTab + vbTab + FormatCurrency(frmtodayscafe.cost(y))
|
|
|
|
|
|
Check your Configuration manager. If you can think then I Can.
|
|
|
|
|
|
|
rather than removing the question (which results in a crippled thread) you should:
- append "SOLVED" to the original subject line
- and publish the solution to the benefit of the community.
|
|
|
|
|
how do you published when issues are resolved.
|
|
|
|
|
just add a reply to one of the messages in the thread (the one that helped you most, the last one, or the question itself).
|
|
|
|
|
Thanks in Advance
Is it Possible to get the File/Folder Copying History , like who copied a folder at what time etc Best Regards,
SOFTDEV
If you have knowledge, let others light their candles at it
|
|
|
|
|
I would have thought by now, with the other questions you have asked relating to this subject area, that you would know this is not easy to do.
You would have to hook into the system, and watch for all the file io operations.
|
|
|
|
|
I don't beieve that this information is logged anywhere. It would probably add quite an overhead to any OS. txtspeak is the realm of 9 year old children, not developers. Christian Graus
|
|
|
|
|
Windows and NTFS do not track such information. There is no way to get it.
Even writing an NTFS extension wouldn't do anynthing for you since a copy operation is nothing more than "open a file and read it". There's no way to tell the difference between a file being copied and one being read by its application.
|
|
|
|