The listbox doesn't "sort" either; that's the job of the collection. You think it's sorting because that's where the interface is. The person in the drive-thru window doesn't actually make the burger; someone else does and passes it back.
"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
For i = 0 To .DataGridView1.Rows.Count - 1
cm = New MySqlCommand("update tblproduct set qty = qty - " & CInt(.DataGridView1.Rows(i).Cells(9).Value.ToString) & " where id like '" & .DataGridView1.Rows(i).Cells(1).Value.ToString & "'", cn)
subject is declare event on Form1 , and run that event on Form2
here is the code , but event doesnt work on Form2 !! what is missing here??
Public Class Form1
Private Sub btnOpenForm2_Click(sender As Object, e As EventArgs) Handles btnOpenForm2.Click
Public Event show_My_Message()
Private Sub btnShowMessageOnForm2_Click(sender As Object, e As EventArgs) Handles btnShowMessageOnForm2.Click
Public Class Form2
Public WithEvents My_Form1 As Form1 = New Form1
Private Sub Show_My_Message_On_Form2() Handles My_Form1.show_My_Message
What you're doing seems backwards, but, hey, it's your app and I don't know anything about it.
Since Form2 doesn't (and SHOULDN'T!) know anything about Form1. By doing this, you forever tie both forms together making it impossible to use one of them without the other.
Your Form2 code is creating a NEW INSTANCE of Form1, NOT using the existing instance! That's why it doesn't work. You do not need the "WithEvents", or even that entire line, on Form2.
If Form2 needs to subscribe to events exposed by Form1, you have to pass your instance of Form1 to a constructor on Form2 so it knows which instance events to subscribe to. Then the constructor needs to "wire-up" the event handlers for whatever events it needs, manually using AddHandler.
My VB.NET is really rusty, so the following may not even compile let alone run:
PublicEvent Show_My_Message(ByVal message AsString)
PrivateSub btnOpenForm2_Click(sender AsObject, e As EventArgs) Handles btnOpenForm2.Click
Dim form2 AsNew Form2(Me) ' This passes the reference to the Form1 instance to the Form2 instance
form2.Show() ' Show an instance of Form2EndSubPrivateSub btnShowMessageOnForm2_Click(sender AsObject, e As EventArgs) Handles btnShowMessageOnForm2.Click
RaiseEvent Show_My_Message("Some message")
PublicSubNew(Form1 eventProvider) ' THIS IS BAD PRACTICE! Form1 should be replaced by an interface!AddHandler eventProvider.Show_My_Message, AddressOf ShowMyMessageHandler
EndSubPublicSub ShowMyMessageHandler(ByVal message AsString)
I've never got along with Events - they seem overly convoluted for simple tasks. My (also) rusty VB suggests that something like the following might do what you want (it is probably overkill)
Private f2 As Form2 = NothingSub F2IsActive(Enabled AsBoolean)
btnStartForm2.Enabled = Not Enabled
btnDoSomethingOnForm2.Enabled = Enabled
btnCloseForm2.Enabled = Enabled
If Enabled ThenIfNot FormIsOpen(f2) Then' Needs to be opened
f2 = New Form2()
EndIfElseIf FormIsOpen(f2) Then' Needs to be closed
f2 = NothingEndIfEndSubPrivateSub btnStartForm2_Click(sender AsObject, e As EventArgs) Handles btnStartForm2.Click
EndSubPrivateSub btnDoSomethingOnForm2_Click(sender AsObject, e As EventArgs) Handles btnDoSomethingOnForm2.Click
If f2 IsNothingThen
MsgBox("You have to open Form2 first")
ElseIf FormIsOpen(f2) Then
Else' No longer exists
MsgBox("Form2 has disappeared")
EndIfEndSubPrivateFunction FormIsOpen(formToFind As Form) AsBooleanForEach testform As Form In Application.OpenForms
If testform.Equals(formToFind) ThenReturnTrueEndIfNextReturnFalseEndFunctionPrivateSub btnCloseForm2_Click(sender AsObject, e As EventArgs) Handles btnCloseForm2.Click
IfNot FormIsOpen(f2) Then
MsgBox("Form2 has already been closed")
EndSubPrivateSub Form1_Load(sender AsObject, e As EventArgs) HandlesMyBase.Load
MsgBox("Hello from Form 1")
I hope I'm posting this in the right place. I'm using VistaDb version 6.2 I have a Main Database with several tables Like Clients, Inventory, etc. I have a Backup Database with the same table(s) and structure as the Main database. I'm trying to copy 1 or more records from the Backup Database, like the Inventory Table to the Main Database Inventory Table. The code below is inserting records from the Main database inventory table, and not from the backup database. Do I need to do this by First selecting the data and placing it in a tmp table then insert the records from the tmp table? Any help would be appreciated.
Here is the code I have:
Dim MyFile AsString = TreeListTransfer.FocusedNode(0).ToString
Dim VdbConn1 AsString = "Data Source=" & Application.StartupPath & "\Backup\" & MyFile & ".vdb6"Try'Count the files in the ListboxFor i AsInteger = 0To LstFiles.Items.Count - 1
LstFiles.SelectedIndex = i
FileId = CInt(LstFiles.Text)
'Add the Contents to the DatabaseUsing conn AsNew VistaDBConnection(VdbConn)
StrSql = "INSERT INTO Inventory(ClientId, Category, Product, PartNo, PurchaseDate, Unit, UnitPrice, InStock, OnOrder, Photo)
SELECT ClientId, Category, Product, PartNo, PurchaseDate, Unit, UnitPrice, InStock, OnOrder, Photo
WHERE (InventoryId = @InventoryId)"Using cmd AsNew VistaDBCommand(StrSql, conn)
EndWith'Execute the Statement
'Close the Connection
MessageBox.Show("Transfer successfully completed on the 'Inventory' table", "Transfer Inventory Data", MessageBoxButtons.OK, MessageBoxIcon.Information)
Catch ex As Exception
MessageBox.Show(ex.Message, "Transfer Inventory Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
That's only possible if you have some metric for how many items the process has to work on.
Such as records in a database or file.
But you could also add logging such as
Part 1 Beginning
Part 1 Success
Part 2 Beginning
Part 2 Success
Another Option here
we could use "BackgroundWorker" as following:
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
ProgressBar1.Maximum = ???? Here what should put?
BackgroundWorker1.WorkerReportsProgress = True
Private Sub BackgroundWorker1_DoWork(sender As Object, e As System.ComponentModel.DoWorkEventArgs) Handles BackgroundWorker1.DoWork
'We can measure this loop for example
For t = 0 To myMax
Label1.Text = t
'But we need to measure process percentage of (My_Process()) ,
'No have (t) digital counter to use in (BackgroundWorker1.ReportProgress(t))
'So what is the solution here???
Private Sub BackgroundWorker1_ProgressChanged(sender As Object, e As ProgressChangedEventArgs) Handles BackgroundWorker1.ProgressChanged
Label1.Text = e.ProgressPercentage.ToString() & " %"
ProgressBar1.Value = e.ProgressPercentage
Private Sub My_Process()
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.
.Lines = nLijnen
.PlayDate = Now
Console.Write("New highscore. " & nLijnen & " Your name please? ")
.Name = Console.ReadLine
.Name = .Name.Trim
If .Name = "" Then .Name = "[No Name]"
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
Any Idea why or how to solve this.
Last Visit: 31-Dec-99 18:00 Last Update: 28-Sep-22 0:47