|
My formula or code is terrible for calculating the percentage complete based on 100
There must be a better way to write this.
Just looking for suggestions, in this example, there are 330 records, and the step is .0627
So the first value is -1, and the program bombs. Now my m_progressPos is always 0.
I mostly write web apps, so I don't have much experience with this.
This is what I have.
If (itemIndex.Count > 0) Then
dialogPos = 0.0
dialogStep = 100 / itemIndex.Count - 1
dialogWait.UpdateProgress(1, "Located " & itemIndex.Count & " product items(s)")
End If
rC = 0
For Each i As itemIndex In itemIndex
dialogPos += dialogStep
Dim m_dialogPos As Integer = Convert.ToInt32(Math.Round(dialogPos))
m_dialogPos = If(m_dialogPos > -1, m_dialogPos, 0)
dialogWait.UpdateProgress(m_dialogPos, "Calculating profit for " & i.ItemNumber & " (" & rC & " of " & itemIndex.Count & ") ")
load_SR_Invoice_Profit(connection, i.ItemNumber, profits)
rC += 1
Next
<pre>
|
|
|
|
|
(100 / max number of items) * current position.
I would also recommend on updating on a specified interval, not each item. Something like below;
int startTick = Environment.TickCount;
if (Environment.TickCount - startTick > 250)
{
UpdateStatus();
startTick = Environment.TickCount;
} That way you get the optimal througput without having to synchronize to the mainthread for each item.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Possibly an easier way for you to achieve your result would be to set the Progressbar maximum property in your dialog to the itemIndex.Count value, that way you won't have to worry about the calculating your percentage - just set the progress bar value from i to itemCount
To do this you would need to create a new property for your dialogWait class to hold the progress bar maximum e.g.
Class dialogWait
Public WriteOnly Property progressmax() As Integer
Set(value As Integer)
myprogress.Maximum = value
End Set
End Property
(this is assuming you have a progress bar control called myprogress of course). Then you could change your main code section to this
If (itemIndex.Count > 0) Then
dialogWait.progressmax = itemIndex.Count
End If
rC = 0
For Each i As item In itemIndexes
rC += 1
dialogWait.UpdateProgress(rC, "Calculating profit for " & i.ItemNumber & " (" & rC & " of " & itemIndex.Count & ") ")
load_SR_Invoice_Profit(connection, i.ItemNumber, profits)
Next
|
|
|
|
|
I was pretty brain dead this day, I should of said that I wanted to keep the max value at 100%, and constantly calculate for any number of records at 100%.
So today with the progress bar breaking, I took the time to fix it, and went to a basic calculator website to figure out the formula, in which there really was no formula, just basic math that was so simple.
And yes this is the loop function that I wrote about in my post in the database form about merging SQL for FoxPro statements that I posted 5 mins ago.
In the end, I need to dump this code for something faster, but it works for now until I can figure out something better.
So thanks Eddy for the suggestion, and the other op as well.
If (invIndex.Count > 0) Then
dialogPos = 0.0
dialogWait.pb_progress.Maximum = 100
dialogWait.UpdateProgress(0, "Located " & invIndex.Count & " invoices(s)")
Dim rC As Integer = 0
For Each i As invoiceIndex In invIndex
Dim m_percentage As Decimal = ((rC / invIndex.Count()) * 100)
Dim m_dialogPos As Integer = Math.Round(m_percentage)
dialogWait.UpdateProgress(m_dialogPos, "Calculating profit for Invoice " & i.InvoiceNumber & " (" & rC & " of " & invIndex.Count & ") ")
load_SR_Invoice_Profit(connection, i.InvoiceNumber, profits)
rC += 1
Next
|
|
|
|
|
I create a class to use in List(of class)
Then I'm populating the class with item names.
I wrote this, but I'm still getting duplicate value, so I got it wrong somewhere.
Dim reader As System.Data.OleDb.OleDbDataReader = command.ExecuteReader()
While reader.Read()
Dim m_itemNumber As String = reader.GetValue(0)
If Not p.Contains(New itemIndex() With {.ItemNumber = m_itemNumber}) Then
p.Add(New itemIndex() With
{
.ItemNumber = reader.GetValue(0)
})
End If
End While
Maybe I got it wrong in the SQL
" SELECT " & _
" DISTINCT FITEMNO " & _
" FROM " & _
"( " & _
" SELECT " & _
" h.FITEMNO " & _
" FROM ARTRS01H.dbf h " & _
" WHERE h.FINVNO = @FINVNO " & _
" UNION ALL " & _
" SELECT " & _
" v.FITEMNO " & _
" FROM ARTRS01.dbf v " & _
" WHERE v.FINVNO = @FINVNO " & _
") " & _
" GROUP BY FITEMNO "
|
|
|
|
|
Sort of like SQL Linq.
Dim reader As System.Data.OleDb.OleDbDataReader = command.ExecuteReader()
While reader.Read()
Dim m_itemNumber As String = reader.GetValue(0)
Dim aFlag As Boolean = p.Exists(Function(m) m.ItemNumber = m_itemNumber)
If (False = aFlag) Then
p.Add(New itemIndex() With {
.ItemNumber = m_itemNumber
})
End If
End While
|
|
|
|
|
Hello !
Is there any library to compare 2 SQL server databases inside a vb.net program ? ( I mean to compare the structure and relationships, no data)
Thank you !
|
|
|
|
|
|
About the SMO , can you specify some more information , because on that link I can't find any way to do this.
|
|
|
|
|
It's a big library so you need to navigate through the documentation. To have something to start from , have a look at:
|
|
|
|
|
Have a look at OpenDBDiff[^]
=========================================================
I'm an optoholic - my glass is always half full of vodka.
=========================================================
|
|
|
|
|
This doesn't seems to be used from inside a vb.net application , but as a external tool.
|
|
|
|
|
You may or may not be able to integrate the supplied source code
=========================================================
I'm an optoholic - my glass is always half full of vodka.
=========================================================
|
|
|
|
|
For this I need some help
|
|
|
|
|
You know how this site works, right? You start yourself and if you run into a specific problem you can ask
If the brain were so simple we could understand it, we would be so simple we couldn't. — Lyall Watson
|
|
|
|
|
No , I don't know. Thank you for telling me.
But what if I don't know how to start ?
Can't this forum help someone how to start ?
|
|
|
|
|
I wrote this piece of code in the event of a textbox LEAVE where I enter the city automatically brought in CAP PR and the results of a query ....
Making debugging line by line VS 2010 jumps the line Dim laws as OdbcDataReader and therefore it does not perform the query and gives me error as if there were no data.
I made a few mistakes in the code?
Private Sub txtPaese_Leave_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtPaese.Leave
Try
Dim cn As New OdbcConnection("dsn=PHOENIXDB;uid=SYSDBA;pwd=masterkey;")
Dim com As String = txtPaese.Text
Dim strCn As String = "Select distinct * from TBL_COMUNI where COMUNE='" & com & "'"
Dim cmd As OdbcCommand = New OdbcCommand(strCn)
Dim leggi As OdbcDataReader
Dim daSelPaese As New OdbcDataAdapter
Dim dsSelPaese As New DataSet
cn.Open()
daSelPaese.SelectCommand = cmd
daSelPaese.SelectCommand.Connection = cn
daSelPaese.Fill(dsSelPaese, "TBL_COMUNI")
leggi = cmd.ExecuteReader
Me.txtCAP.Text = leggi.Item(11)
Me.txtPR.Text = leggi.Item(4)
leggi.Close()
cn.Close()
Catch ex As Exception
MsgBox("Error: " & ex.Source & ": " & ex.Message, MsgBoxStyle.OkOnly, "Connection Error !!")
End Try
End Sub
|
|
|
|
|
Your code is vulnerable to SQL Injection[^].
NEVER use string concatenation to build a SQL query. ALWAYS use a parameterized query.
You're executing your command twice - once to fill a DataTable , which you then throw away, and once with the ExecuteReader method.
You've then tried to access columns from the returned OdbcDataReader object without first calling its Read method. This will throw an exception.
Your query is selecting multiple rows from the table, but you're only using the first row. You should change it to only select a single row instead.
You're using SELECT * FROM ... , which returns every column in the table. You're then only using two columns. Change your query to return only the columns you need.
You should also wrap any objects that implement IDisposable in a Using block.
Private Sub txtPaese_Leave_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtPaese.Leave
Try
Using cn As New OdbcConnection("dsn=PHOENIXDB;uid=SYSDBA;pwd=masterkey;")
Dim query As String = "SELECT TOP 1 * FROM TBL_COMUNI WHERE COMUNE = ?"
Using cmd As New OdbcCommand(query, cn)
cmd.Parameters.AddWithValue("p0", txtPaese.Text)
cn.Open()
Using reader As OdbcDataReader = cmd.ExecuteReader(CommandBehiavor.CloseConnection)
If reader.Read() Then
Me.txtCAP.Text = reader.Item(11)
Me.txtPR.Text = reader.Item(4)
Else
End If
End Using
End Using
End Using
Catch ex As Exception
MsgBox("Error: " & ex.Source & ": " & ex.Message, MsgBoxStyle.OkOnly, "Connection Error !!")
End Try
End Sub
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Grazie tantissimo.... Ora funziona tutto....
Thank you so much .... Now everything works ....
|
|
|
|
|
Hello Everyone,
I am Working on SCADA project in which I am writing real time data to excel worksheet. Now I want to apply a check on data that if worksheet is updating continuously or not if not then I will restart my windows form Application. I try following code but it doesn't work.
Private EventDel_CellsChange As Excel.DocEvents_ChangeEventHandler
Public Sub UseDelegate()
xlBook = excelWB
xlSheet1 = xlBook.Worksheets(2)
CType(xlSheet1, Excel._Worksheet).Activate()
EventDel_CellsChange = New Excel.DocEvents_ChangeEventHandler( _
AddressOf CellsChange)
AddHandler xlSheet1.Change, EventDel_CellsChange
xlApp.Visible = True
xlApp.UserControl = True
End Sub
Private Sub CellsChange(ByVal Target As Excel.Range)
MsgBox("Restrating Of Application Required")
End Sub
Any Help Please ................ thanks in advance.
|
|
|
|
|
I am trying to read a CLOB value from an Oracle database query using the GetChars method. I am doing this so that I can buffer very large CLOB values and write the results out to an XML file.
However, there seems to be an issue where the GetChars method of an OracleDataReader is only buffering half the characters it should. This causes me to continue buffering in a loop until GetChars returns 0, but I think this is very inefficient and is slowing down my program.
Does anyone know why this is happening? Here is the fragment of code that I am using:
Dim reader As Data.OracleClient.OracleDataReader
Dim bufferSize As Integer = 1024 * 2000
Dim outChar(bufferSize - 1) As Char
Using connection As New Data.OracleClient.OracleConnection(connectString)
Dim command As New Data.OracleClient.OracleCommand(statement)
command.Connection = connection
connection.Open()
reader = command.ExecuteReader(System.Data.CommandBehavior.SequentialAccess)
Do While reader.Read()
startIndex = 0
Array.Clear(outChar, 0, bufferSize)
retval = reader.GetChars(0, startIndex, outChar, 0, bufferSize)
Do Until retval = 0
rawStr = New String(outChar)
rawStr = rawStr.Replace(Chr(0), "")
myxml.WriteRaw(rawStr)
myxml.Flush()
startIndex += rawStr.Length
Array.Clear(outChar, 0, bufferSize)
retval = reader.GetChars(0, startIndex, outChar, 0, bufferSize)
Loop
Loop
End Using
|
|
|
|
|
Aaron Rosenthal wrote: This causes me to continue buffering in a loop until GetChars returns 0 You are reading it in blocks of 1024 * 2000 chars. If you know the size of the blob, then you could see if you can fetch it completely.
Aaron Rosenthal wrote: I think this is very inefficient and is slowing down my program Why do you think that?
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
I can't assume to know the size of the CLOB in my program because it may vary. Also, if I simply buffered the entire CLOB, what would be the point of buffering? I'm trying to avoid doing that so I don't run into memory issues for very large CLOBs.
What I don't get is why doesn't GetChars fill the entire outChar array? I know that it can fill more than it does. For example, on a further iteration of my loop GetChars only fetches FOUR characters, and there are still 3 more to fetch, so I have to continue iterating. Why does it do that?
|
|
|
|
|
Aaron Rosenthal wrote: Why does it do that? I don't know the exact implementation details of the method, despite having it open in ILSpy.
The buffer will be filled to its maximum with the available data. Did you set the commandbehaviour to sequential on the reader?
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
What type is the myxml variable? If it's an System.Xml.XmlWriter , you should probably be using the WriteRaw overload[^] that takes a char[] , rather than creating two new strings every time:
retval = reader.GetChars(0, startIndex, outChar, 0, bufferSize)
Do Until retval = 0
myxml.WriteRaw(outChar, 0, retval)
myxml.Flush()
startIndex += retval
Array.Clear(outChar, 0, retval)
retval = reader.GetChars(0, startIndex, outChar, 0, bufferSize)
Loop
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|