|
Have your method accept an IProgress<T> Interface (System) | Microsoft Docs[^] implementation, and call it to report the progress.
The caller will need to pass in an appropriate implementation - eg: Progress<T> Class (System) | Microsoft Docs[^].
But as already mentioned, you will need to know how much work your method needs to do if you want to report how far through the work it has got.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
How about this approach ...
1) Run the process as a test, collecting the total time it takes. Call it "T"
2) Store that run time somewhere
3) Next time you run the process you can now use "T" as the denominator to calculate the percent complete. p = duration_now/T
4) If the percentage calculation goes over 100, then set it 100.
5) Capture the new total time, "T", store it for the next iteration.
Rinse, repeat.
Not perfect, but it might work for you.
|
|
|
|
|
Hi
I've wrote this code
With NewHS
.Lines = nLijnen
.PlayDate = Now
Console.SetCursorPosition(10, 21)
Console.Write("New highscore. " & nLijnen & " Your name please? ")
.Name = Console.ReadLine
.Name = .Name.Trim
If .Name = "" Then .Name = "[No Name]"
End With
When running the line console.readline It asks for two enters to accept. I see the cursor movingto the begin of the next line by the first enter.
The second time the program runs those lines of code it working well with one enter.
I'm clearing the keyboardbuffer before starting writing to the console with
Sub ClearKBBuffer()
While Console.KeyAvailable
Console.ReadKey(True)
Console.ReadKey()
End While
End Sub
Any Idea why or how to solve this.
Jan
|
|
|
|
|
I just tried your initial code (with various responses) and it works with only one press of the Enter key.
|
|
|
|
|
The whole code where start is the real game
<TargetFramework>net6.0</TargetFramework>
Sub ClearKBBuffer()
While Console.KeyAvailable
Console.ReadKey(True)
End While
End Sub
Sub Main()
Dim k As ConsoleKey
Console.TreatControlCAsInput = True
Randomize()
Do
Console.CursorVisible = False
Dim nLijnen = Start()
ClearKBBuffer
Console.CursorVisible = True
Dim hs As HighScores = HighScores.Load()
Console.BackgroundColor = ConsoleColor.Red
Console.ForegroundColor = ConsoleColor.Black
Dim NewPLace As Integer = -1
For i As Integer = 0 To 9
If nLijnen > hs.Scores(i).Lines And NewPLace < 0 Then
NewPLace = i
End If
Console.SetCursorPosition(10, 10 + i)
Console.Write(hs.Scores(i).Name.PadRight(30) & hs.Scores(i).Lines.ToString.PadLeft(10) & " " & hs.Scores(i).PlayDate.ToString("dd/MM/yyyy HH:mm:ss"))
Next
Console.Beep()
If NewPLace >= 0 Then
Dim NewHS As New Score
With NewHS
.Lines = nLijnen
.PlayDate = Now
Console.SetCursorPosition(10, 21)
Console.Write("New highscore. " & nLijnen & " Your name please? ")
.Name = Console.ReadLine
.Name = .Name.Trim
If .Name = "" Then .Name = "[No Name]"
End With
For i = 8 To NewPLace Step -1
hs.Scores(i + 1) = hs.Scores(i)
Next
hs.Scores(NewPLace) = NewHS
hs.Save()
End If
Console.SetCursorPosition(0, Console.WindowHeight - 2)
Console.WriteLine("New game? (Y/N) ")
Do
k = Console.ReadKey.Key
Loop While k <> ConsoleKey.Y And k <> ConsoleKey.N
Loop While k = ConsoleKey.Y
End Sub
|
|
|
|
|
Sub ClearKBBuffer()
While Console.KeyAvailable
Console.ReadKey(True)
Console.ReadKey()
End While
End Sub
Surely that will block when there are an odd numbers of keys in the input queue.
Did you mean this
Sub ClearKBBuffer()
While Console.KeyAvailable
Console.ReadKey(True)
End While
End Sub
Alan.
|
|
|
|
|
That was stupit wasn't it
|
|
|
|
|
I need to build a database using vb6 and ms access for various groups or organisation which have various members, can someone suggest how to build this kind of database using ms-access, one table will have the organisation information such as its name, establishment date etc, and another database which store members for each organisation, these organization can have members of 5 nos. to 20 or more numbers, can anyone suggest how to build this kind of database, would be more grateful if someone can give a free code for this type of database.
Thanks in advanvce
Zela
|
|
|
|
|
|
Thanks for the response and suggestion, I'm not into programming deeply, just need to create a simple database which keep record for some 50/100 nos of organisation which have its name and address along with the organisation members using vb and ms-access since i have a little knowledge on this. I can manage building for the organisation but keeping record for each of the organisation members becomes a little difficult.
|
|
|
|
|
Hello
I have Seen this Article:
DataGridView – Stacked Header; talk about how to make Multi Layer head for DatagridView
it was on C# , I have translated to VB.net but there was some errors,
have made it before in VB.net ?
I try to attach Source code of VB.net but I have'nt seen attachment option
many thanks
|
|
|
|
|
You can add the relevant code, and full details of the errors into your question. Please ensure you add the correct <pre lang="VB"></pre> tags around the code.
|
|
|
|
|
thanks
what about if want to attached file?
|
|
|
|
|
There is no attach feature. You need to copy the code that has the problem and paste it into your question as I suggested above.
|
|
|
|
|
|
hello everyone I have the following format of a configuration file so I want to edit these values, the file has the following extension data.config
format
Image — Postimages[^]
Form
Image — Postimages[^]
|
|
|
|
|
And? You never asked a question or detailed a problem you're having.
That kind of file is just your normal, everyday .INI file, completely outdated nowadays.
|
|
|
|
|
Hi sir,
i'm already try to pool data into listview and it worked. But i need to pool the data using timer can anyone guide me ?
<pre> Try
Dim cmd As New FbCommand("SELECT A.EVENTDATE AS EVENTDATE ,A.PRIORITY AS PRIORITY ,B.CARDHOLDERID AS CARDHOLDERID," & _
"B.EMAIL AS EMAIL,B.NAME AS NAME,C.WINSOCKIPADDRESS AS WINSOCKIPADDRESS,A.DEVICEID AS DEVICEID, " & _
"D.DESCRIPTION AS DESCRIPTION " & _
" FROM EVENT A , CARDHOLDER B , COMMCHANNEL C, DEVICE D " & _
"WHERE (A.CARDHOLDERID = B.CARDHOLDERID)" & _
" AND (A.COMMCHANNELID = C.COMMCHANNELID) " & _
" AND (A.DEVICEID = D.DEVICEID) " & _
"AND A.CARDHOLDERID IS NOT NULL " & _
"AND B.USERDEFINED9 = 'STAFF' AND B.STATUS='Normal'" & _
" AND A.PRIORITY IS NULL " & _
"AND A.EVENTDATE >= CAST('TODAY' AS DATE) AND A.EVENTMSG = 'Access Granted' " & _
"ORDER BY A.EVENTDATE ASC", IBSSCN)
IBSSDR = cmd.ExecuteReader()
ListView1.Items.Clear()
Dim bFlag As Boolean = True
Do Until Not bFlag
While IBSSDR.Read
Dim touch As DateTime = Convert.ToDateTime(IBSSDR.Item("EVENTDATE"))
Dim date1 As String = touch.Date.ToString("dd/MM/yyyy")
Dim time1 As String = Format(touch, ("hh:mm:ss tt"))
Dim str(5) As String
Dim itm As ListViewItem
str(0) = IBSSDR.Item("CARDHOLDERID")
str(1) = IBSSDR.Item("NAME")
str(2) = date1
str(3) = time1
If IBSSDR.Item("EMAIL") Is DBNull.Value Then
str(4) = ""
Else
str(4) = IBSSDR.Item("EMAIL")
End If
itm = New ListViewItem(str)
ListView1.Items.Add(itm)
End While
bFlag = IBSSDR.NextResult
Loop
IBSSCN.ClearAllPools()
Catch ex As Exception
MsgBox(ex.Message)
End Try
I already add the timer :
<pre lang="VB">
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
Timer1.Enabled = True
Timer1.Interval = 6000
ListView1.Update()
ListView1.Refresh()
end sub
Can anybody help me, plz , tq
|
|
|
|
|
You have to call your code that retrieves the data from the database from your timer Tick handler.
Separate your code so you're putting the database retrieval code into it's own function that returns the data set. DO NOT put the code that handles putting that data into the ListView in that same code! Break that out into its own method. Methods should only do one thing, like retrieving a specific dataset from the database, or updating the data in a control. They should NOT do multiple things.
|
|
|
|
|
Ok thanks you for support and guide, i will try to separate task by method,
One more thing sir, how to make last item in listview always highligthed or fullselectedrow?...Hope can guide me, thank a lots.
|
|
|
|
|
|
|
Since some weeks i'm working on a german cards game "Schafkopf" [private] demo.
The demo is not bad but somehow my coding drifted away and appears like "Spaghetti code".
The game has 32 cards and 4 players.
For a "SOLO" or "WENZ" the declarer plays against the 3 other players.
A standard game is that the declarer plays with one "Ace" (owned by another player) => 2 play against the other 2.
The computer controls 3 players, one player is the user who can click on one of his cards (which are presented on a dgv).
The problem is that there are many, many loops when checking a players cards and endless "rules" which now are done with
"If, Then, ElseIf ..." statements.
So one of the related functions is > 500 code lines ...
I think I need a better concept, because the existing one is hard to handle, problems are not easy to fix.
Any ideas?
Example for those loops:
Try
If MyForm.GameOver = True Then Exit Function
If GameStatus.ToString = "SpielAus" Then MyForm.GameOver = True
If GameStatus.ToString = "SpielAus" Then Exit Function
If sHandCards Is Nothing Then
' => LeadSuit n.a.
Debug.Print("ACP 516 sHandCards: Is Nothing")
Debug.Print("ACP 517 LeadSuitID: '" & LeadSuitID & "'; TrumpCardID: '" & TrumpCardID & "'")
sHandCards = sTrumpList
Else
'sHandCards <> Nothing
'MessageBox.Show("ACP 525 sHandCards: " & sHandCards.ToString)
If ContainsHandCardsStandardTrumps(sHandCards) = False Then
'MessageBox.Show("ACP 528 sHandCards: " & sHandCards.ToString)
If TrumpCardID <> 4 Then sHandCards = sTrumpList
If TrumpCardID = 4 Then
If sHandCards.ToString.Contains("O") Then
Else
sHandCards = sTrumpList
End If
End If
End If
If dgv.CurrentCell.Value.ToString.Contains("♠") Or dgv.CurrentCell.Value.ToString.Contains("♥") Or
dgv.CurrentCell.Value.ToString.Contains("Ⴖ") Or dgv.CurrentCell.Value.ToString.Contains("Ꚛ") Or
dgv.CurrentCell.Value.ToString = "" Or dgv.CurrentCell.Value Is Nothing Or
dgv.CurrentCell.Value.ToString = String.Empty Then
For Each row As DataGridViewRow In dgv.Rows
For n As Integer = 1 To dgv.Columns.Count - 1
If row.Cells(n).Value.ToString.Contains(GetLowOfHandCards(row.Cells(n), PlayerID,
DeclarerID, GameStatus, sHandCards, TrumpCardID, dgv, MyForm, LeadSuitID)) Then
If dgv.CurrentCell.Value.ToString.Contains("♠") Or
dgv.CurrentCell.Value.ToString.Contains("♥") Or
dgv.CurrentCell.Value.ToString.Contains("Ⴖ") Or
dgv.CurrentCell.Value.ToString.Contains("Ꚛ") Or
dgv.CurrentCell.Value.ToString = "" Or
dgv.CurrentCell.Value Is Nothing Or
dgv.CurrentCell.Value.ToString = String.Empty Then
If row.Cells(n).RowIndex = LeadSuitID AndAlso row.Cells(n).RowIndex <>
MyForm.RufAs.CardColor Then
If row.Cells(n).Value.ToString.Contains("O") = False AndAlso
row.Cells(n).Value.ToString.Contains("U") = False Then
SetCurrentCell(dgvCell, dgv, row.Cells(n), row.Cells(0), " ~ " &
(String.Format("Line # {0}", (New StackTrace(New
StackFrame(True))).GetFrame(0).GetFileLineNumber())) & " ~ ")
End If
End If
End If
End If
Next
Next
End If
|
|
|
|
|
Simple thing like:
string s = dgv.CurrentCell.Value.ToString
then
If s.Conttains("x") or s.Contains...etc
makes the thing more palatable.
Then you look at it again; repeat.
"Before entering on an understanding, I have meditated for a long time, and have foreseen what might happen. It is not genius which reveals to me suddenly, secretly, what I have to say or to do in a circumstance unexpected by other people; it is reflection, it is meditation." - Napoleon I
|
|
|
|
|
Thank you.
Will use string s = dgv.CurrentCell.Value.ToString
and remove redundant code lines.
But the main question is if it makes sense using If - Then statements for game rules or if there is a better way to do this.
modified 19-May-22 3:45am.
|
|
|
|