|
Thank you. Your wisdom is appreciated.
|
|
|
|
|
For i = 0 To .DataGridView1.Rows.Count - 1
cn.Open()
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)
cm.ExecuteNonQuery()
cn.Close()
|
|
|
|
|
... abd does it work?
|
|
|
|
|
Victor Nijegorodov wrote: ... abd does it work?
Not as written. Even if the logic is correct (and we have no way of ascertaining what is in cols 1 and 9) OP needs a Next statement.
Also, why is the value to be subtracted converted to a String and then parsed to CInt only for it to be boxed (a Javaism) / wrappered (JSism) back to a String?
And, can the OP confirm that the ID is a string (hence the quotes)? It is common for it to be a sequential number.
|
|
|
|
|
jsc42 wrote: why is the value to be subtracted converted to a String and then parsed to CInt only for it to be boxed (a Javaism) / wrappered (JSism) back to a String? That sequence is more and more common these days. I can only assume they are learning it from YouTube.
|
|
|
|
|
|
Hello everyone
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??
many thanks
Public Class Form1
Private Sub btnOpenForm2_Click(sender As Object, e As EventArgs) Handles btnOpenForm2.Click
Form2.Show()
End Sub
Public Event show_My_Message()
Private Sub btnShowMessageOnForm2_Click(sender As Object, e As EventArgs) Handles btnShowMessageOnForm2.Click
RaiseEvent show_My_Message()
End Sub
End Class
Public Class Form2
Public WithEvents My_Form1 As Form1 = New Form1
Private Sub Show_My_Message_On_Form2() Handles My_Form1.show_My_Message
MsgBox("Hello")
End Sub
End Class
|
|
|
|
|
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:
Public Class Form1
Public Event Show_My_Message(ByVal message As String)
Private Sub btnOpenForm2_Click(sender As Object, e As EventArgs) Handles btnOpenForm2.Click
Dim form2 As New Form2(Me)
form2.Show()
End Sub
Private Sub btnShowMessageOnForm2_Click(sender As Object, e As EventArgs) Handles btnShowMessageOnForm2.Click
RaiseEvent Show_My_Message("Some message")
End Sub
End Class
Public Class Form2
Public Sub New(Form1 eventProvider)
AddHandler eventProvider.Show_My_Message, AddressOf ShowMyMessageHandler
End Sub
Public Sub ShowMyMessageHandler(ByVal message As String)
MsgBox(message)
End Sub
End Class
|
|
|
|
|
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)
Public Class Form1
Private f2 As Form2 = Nothing
Sub F2IsActive(Enabled As Boolean)
btnStartForm2.Enabled = Not Enabled
btnDoSomethingOnForm2.Enabled = Enabled
btnCloseForm2.Enabled = Enabled
If Enabled Then
If Not FormIsOpen(f2) Then
f2 = New Form2()
f2.Show()
End If
ElseIf FormIsOpen(f2) Then
f2.Close()
f2 = Nothing
End If
End Sub
Private Sub btnStartForm2_Click(sender As Object, e As EventArgs) Handles btnStartForm2.Click
F2IsActive(True)
End Sub
Private Sub btnDoSomethingOnForm2_Click(sender As Object, e As EventArgs) Handles btnDoSomethingOnForm2.Click
If f2 Is Nothing Then
MsgBox("You have to open Form2 first")
ElseIf FormIsOpen(f2) Then
f2.DoSomethingOnForm2()
Else
MsgBox("Form2 has disappeared")
F2IsActive(False)
End If
End Sub
Private Function FormIsOpen(formToFind As Form) As Boolean
For Each testform As Form In Application.OpenForms
If testform.Equals(formToFind) Then
Return True
End If
Next
Return False
End Function
Private Sub btnCloseForm2_Click(sender As Object, e As EventArgs) Handles btnCloseForm2.Click
If Not FormIsOpen(f2) Then
MsgBox("Form2 has already been closed")
End If
F2IsActive(False)
End Sub
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
F2IsActive(False)
End Sub
End Class
Public Class Form2
Public Sub DoSomethingOnForm2()
MsgBox("Hello from Form 1")
End Sub
End Class
modified 6-Jul-22 12:42pm.
|
|
|
|
|
Hi Everyone,
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:
Private Sub TransferInventory()
Dim MyFile As String = TreeListTransfer.FocusedNode(0).ToString
Dim VdbConn1 As String = "Data Source=" & Application.StartupPath & "\Backup\" & MyFile & ".vdb6"
Try
For i As Integer = 0 To LstFiles.Items.Count - 1
LstFiles.SelectedIndex = i
FileId = CInt(LstFiles.Text)
Using conn As New VistaDBConnection(VdbConn)
conn.Open()
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
FROM dbo.Inventory
WHERE (InventoryId = @InventoryId)"
Using cmd As New VistaDBCommand(StrSql, conn)
With cmd.Parameters
.AddWithValue("@InventoryId", FileId)
End With
cmd.ExecuteNonQuery()
conn.Close()
End Using
End Using
Next
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)
Return
Finally
End Try
End Sub
Thanks in Advance.
|
|
|
|
|
|
Hello
How we can get the Percentage of any Process?
for example we have the the following:
Private Sub My_Process()
----Code
----Code
End Sub
this My_Process will have a lot of codes and process and may will take a time to finish
Is there a way to measure the achievement percent of M_Process while process?
thanks regards
|
|
|
|
|
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
...
|
|
|
|
|
Thanks sir for reply
other option
could we do the following:
Private Sub My_Process()
Timer1.Start
----Code
----Code
Timer1.Stop
End Sub
Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
'What we should do here to link progress bar to timer in Parallel ???
End Sub
mean we shall measure the time for whole process
then we need to link that time to ProgressBar to show where we are in process
but here also must link the ProgressBar to timer in Parallel
May be we can use threading start ProgressBar and TimerTick??
Does that Possible?
If so, can show main function or code to achieve that?
modified 19-Jun-22 6:32am.
|
|
|
|
|
Are you saying that you're trying to estimate the amount of time the entire process will take?? That also requires that you know how many items you're going to be processing.
|
|
|
|
|
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
BackgroundWorker1.RunWorkerAsync()
End Sub
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
BackgroundWorker1.ReportProgress(t)
Threading.Thread.Sleep(100)
Next
'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???
End Sub
Private Sub BackgroundWorker1_ProgressChanged(sender As Object, e As ProgressChangedEventArgs) Handles BackgroundWorker1.ProgressChanged
Label1.Text = e.ProgressPercentage.ToString() & " %"
ProgressBar1.Value = e.ProgressPercentage
ProgressBar1.Refresh()
End Sub
Private Sub My_Process()
---- Code
End Sub
modified 19-Jun-22 10:31am.
|
|
|
|
|
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
|
|
|
|
|