I've looked at other posts about this, but I must be missing something. The time remaining isn't right and I'm a bit stuck on this. TIA
mTimeSpan = Now - mStartTime
If (mThisRec > 10) Then
txt_StatusBox.Text = txt_StatusBox.Text & "Time remaining about "
Dim mRate As Double = (CDec(mThisRec) / CDec(mTimeSpan.TotalSeconds)) * (CDec(mMaxRecs) - CDec(mThisRec)) / 1000
mTimeSpan = Now.AddSeconds(mRate) - Now
If mTimeSpan.Hours > 0 Then
If mTimeSpan.Hours > 0 Then
txt_StatusBox.Text = txt_StatusBox.Text & mTimeSpan.Hours.ToString & " hours, "
End If
If mTimeSpan.Minutes > 0 Then
txt_StatusBox.Text = txt_StatusBox.Text & mTimeSpan.Minutes.ToString & " minutes."
Else
txt_StatusBox.Text = txt_StatusBox.Text & mTimeSpan.Seconds.ToString & " seconds."
End If
End If
Related
I am trying to break up the full name of two Recipients to get the first names.
Here is the code:
For r = 1 To .recipients.Count
Debug.Print .recipients(r)
strgreetname = Left(.recipients(r), InStr(1, .recipients(r), " ") - 1)
strTo = Left(strGreetNameAll, InStr(1, .recipients(r), " ") - 2)
strGreetNameAll = strGreetNameAll & strgreetname & ", "
strgreetnameall1 = strgreetname
Next r
For i = 1 To .recipients.Count
Debug.Print .recipients(i)
strgreetname = Left(.recipients(i), InStr(1, .recipients(i), " ") - 1)
strTo1 = Right(strTo, InStr(1, .recipients(i), " ") - 2)
strGreetNameAll = strGreetNameAll & strgreetname & ", "
strgreetnameall1 = strgreetname
Next i
I cannot get strTo and strTo1 to work separately based on the recipients count. It seems to only change if I change the first defined item, in this case r. Changing the i value does nothing. It seems that the first defined variable controls everything below it, even though I have it set separately. How do I break these up so that r controls one section, while i controls another, so they work autonomously?
Update--I got it to separate but the first alias (strTO) is cutting off in strange ways. I want to cut off at the first space in the alias, which I thought I did with the "left" piece. However, it is not consistent, cutting off long names, or pulling in parts of the next name if the first alias was a short name (like Tom).
For R = 1 To .recipients.Count
Debug.Print .recipients(R)
strgreetname = Left(.recipients(R), InStr(1, .recipients(R), " "))
strgreetname2 = Left(.recipients(2), InStr(1, .recipients(R), " "))
strGreetNameAll = strGreetNameAll & strgreetname
strGreetNameAll1 = strgreetname
strTo = Left(strGreetNameAll, InStr(1, .recipients(R), " "))
strTo1 = Left(strgreetname2, InStr(1, .recipients(R), " "))
Next R
StrTO and strTO1 are the first and second aliases in the To field, respectively.
For example:
Given .Recipients "William Hartnell", "Carole Ann Ford", "Patrick Troughton", "Anneke Wills", "Jon Pertwee", and "Tom Baker".
I want strTO to be William. I want strTO1 to be Carole. So it could be Dear William and Carole.
Based on your comment that you want strTO to be all characters up to the first space in .Recipients(1), and you want strTO1 to be all characters up to the first space in .Recipients(2), then you can use the following code:
strTO = Left(.Recipients(1), InStr(.Recipients(1) & " ", " ") - 1)
If .Recipients.Count > 1 Then
strTO1 = Left(.Recipients(2), InStr(.Recipients(2) & " ", " ") - 1)
Else
strTO1 = ""
End If
And, if you were using this to create a "greeting", you could just use something like:
strGreetName = Left(.Recipients(1), InStr(.Recipients(1) & " ", " ") - 1)
If .Recipients.Count > 1 Then
strGreetName = strGreetName & " and " & Left(.Recipients(2), InStr(.Recipients(2) & " ", " ") - 1)
End If
and not worry about having strTO and strTO1.
Or, if you wanted to include all the names, you could use something like
strGreetName = ""
For i = 1 to .Recipients.Count
If i > 1 Then
If i = .Recipients.Count Then
strGreetName = strGreetName & " and "
Else
strGreetName = strGreetName & ", "
End If
End If
strGreetName = strGreetName & Left(.Recipients(i), InStr(.Recipients(i) & " ", " ") - 1)
Next
you are doing this
for r = 1 to 10
a = r + 4
next r
for i = 1 to 10
b = a + 2
next r
when you want
for r = 1 to 10
a = r + 4
b = a + 2
next r
I have used this loop to display Data that graph using the Google Chart
The problem is that the graph contains a lot of data and it takes a long time to be made loaning
The question is whether there is a faster way to pass the data base?
dRow As Data.DataRow In xdata.Rows
If j = 0 Then
TempDate = Format(CDate(dRow.Item(0)), "dd/MM/yyyy")
MyXML += "[new Date(" & TempDate.Year & "," & TempDate.Month - 1 & ")"
j += 1
Else
TempDate = Format(CDate(dRow.Item(0)), "dd/MM/yyyy")
MyXML += ",[new Date(" & TempDate.Year & "," & TempDate.Month - 1 & ")"
j += 1
End If
For colIdx As Byte = 1 To xdata.Columns.Count - 1
If colIdx > 0 Then
If (dRow.Item(colIdx)).ToString <> Nothing Then
MyXML += "," & (dRow.Item(colIdx)).ToString
Else
MyXML += "," & "0"
End If
End If
`
You should be using a StringBuilder if you are going to be concatenating hundreds of strings. .NET strings are immutable which means each time they change, a new object has to be created.
Dim sb As New StringBuilder
For dRow As Data.DataRow In xdata.Rows
If j = 0 Then
TempDate = Format(CDate(dRow.Item(0)), "dd/MM/yyyy")
sb.Append("[new Date(" & TempDate.Year & "," & TempDate.Month - 1 & ")")
j += 1
Else
TempDate = Format(CDate(dRow.Item(0)), "dd/MM/yyyy")
sb.Append(",[new Date(" & TempDate.Year & "," & TempDate.Month - 1 & ")")
j += 1
End If
For colIdx As Byte = 1 To xdata.Columns.Count - 1
If colIdx > 0 Then
If (dRow.Item(colIdx)).ToString <> Nothing Then
sb.Append("," & (dRow.Item(colIdx)).ToString)
Else
sb.Append("," & "0")
End If
End If
Next
Next
And when you're done parsing the data:
Return sb.ToString
I am using the code below to find a value in 8 [qty] fields which is closest in value to the value in [make quantity] field.
The code works as I want provided the value in the [qty] fields are ascending values. eg. 10,20,30,40,50,60,70,80
The code fails if the values are descending, or mixed eg. 80,70,60,50,40,30,20,10 or 10,30,50,40,70,20,80 etc
can anyone suggest how to handle this in a better way
If Me![Make Quantity] <= Me![qty1] Then
materialprice = Me![raw1]
ElseIf Me![Make Quantity] <= Me![qty2] And Me![Make Quantity] > Me![qty1] Then
materialprice = Me![raw1]
ElseIf Me![Make Quantity] <= Me![qty3] And Me![Make Quantity] > Me![qty2] Then
materialprice = Me![raw2]
ElseIf Me![Make Quantity] <= Me![qty4] And Me![Make Quantity] > Me![qty3] Then
materialprice = Me![raw3]
ElseIf Me![Make Quantity] <= Me![qty5] And Me![Make Quantity] > Me![qty4] Then
materialprice = Me![raw4]
ElseIf Me![Make Quantity] <= Me![qty6] And Me![Make Quantity] > Me![qty5] Then
materialprice = Me![raw5]
ElseIf Me![Make Quantity] <= Me![qty7] And Me![Make Quantity] > Me![qty6] Then
materialprice = Me![raw6]
ElseIf Me![Make Quantity] <= Me![qty8] And Me![Make Quantity] > Me![qty7] Then
materialprice = Me![raw7]
Else
materialprice = Me![raw8]
End If
UPDATED!! Changed code so that if QTY < lowest, default to lowest; if > highest, use highest.
Here's some code I threw together... since I don't have your data, i loaded test data into 8 pairs of textboxes (using your field names). Note that I used the 'CHANGE' event for the 'Make Quantity' textbox to invoke the code. You can force execution however you like...
Once satisfied, comment out the Debug statements and the MsgBox.
Option Compare Database
Option Explicit
Private Sub Form_Load()
Dim i As Integer
Dim MakeQuantity As Integer
Dim materialprice As Double
Me.qty1 = 30: Me.qty2 = 20: Me.qty3 = 70: Me.qty4 = 50: Me.qty5 = 10: Me.qty6 = 60: Me.qty7 = 80: Me.qty8 = 70
Me.raw1 = 3.3: Me.raw2 = 2.2: Me.raw3 = 7.7: Me.raw4 = 5.5: Me.raw5 = 1.1: Me.raw6 = 6.6: Me.raw7 = 8.8: Me.raw8 = 7.7
End Sub
Private Sub Make_Quantity_AfterUpdate()
Dim i As Integer
Dim iDiff As Integer
Dim iLow As Integer
Dim iMatch As Integer
Dim iHigh As Integer
Dim dPriceL As Double
Dim dPriceH As Double
Dim dPriceM As Double
Dim iQtyL As Integer
Dim iQtyH As Integer
iLow = 30000
iHigh = 0
iMatch = 10
Debug.Print "Find Qty of: " & Me.[Make Quantity]
For i = 1 To 8
If Int(Me("qty" & i)) <= iLow Then
iLow = Int(Me("qty" & i))
dPriceL = Me("raw" & i)
iQtyL = Int(Me("qty" & i))
End If
If Int(Me("qty" & i)) >= iHigh Then
iHigh = Int(Me("qty" & i))
dPriceH = Me("raw" & i)
iQtyH = Int(Me("qty" & i))
End If
iDiff = Abs(Me.[Make Quantity] - Me("qty" & i))
If Int(Me("qty" & i)) <= Int(Me.[Make Quantity]) Then
If iDiff <= iMatch Then
iMatch = iDiff
dPriceM = Me("raw" & i)
End If
End If
Debug.Print "i: " & i & vbTab & "Qty: " & Me("qty" & i) & vbTab & "Diff: " & iDiff & vbTab & "Raw: " & Me("raw" & i)
Next i
If dPriceM <> 0 Then ' Did we find a suitable match?
MsgBox "Make Quantity: " & Me.[Make Quantity] & vbCrLf & "Price: " & dPriceM
Else ' Didn't find a good match; must be < lowest or > highest
If iQtyL > Int(Me.[Make Quantity]) Then ' Greater than lowest QTY, use Lowest QTY price...
MsgBox "Make Quantity: " & Me.[Make Quantity] & vbCrLf & "Price: " & dPriceL
ElseIf iQtyH < Int(Me.[Make Quantity]) Then ' Greater than highest QTY, use highest QTY price...
MsgBox "Make Quantity: " & Me.[Make Quantity] & vbCrLf & "Price: " & dPriceH
Else
MsgBox "Impossible? Asked for Qty of: " & Me.[Make Quantity] & vbCrLf & _
"Lowest Qty: " & iQtyL & vbTab & _
"Highest Qty: " & iQtyH
End If
End If
End Sub
I want to manipulate following condition to check if value is either 41 or 42 then ii want to exit the condition , any value other than 41 or 42 i want to execute SendEmailCPK(Msg).
Following is the code i have , but it's not working
If (rs.Fields("machine").Value <> "42" OrElse rs.Fields("machine").Value <> "41") Then
SendEmailCPK(Msg)
EventLog1.WriteEntry(EventLog1.Source, "Coil " & rs.Fields("Lot").Value & " " & rs.Fields("Coil").Value & " Cpk is Out of Spec " & rs.Fields("cpk").Value)
End If
You mean if value is different from 42 and from 41 ?
If (rs.Fields("machine").Value <> "42" AndAlso rs.Fields("machine").Value <> "41") Then
SendEmailCPK(Msg)
EventLog1.WriteEntry(EventLog1.Source, "Coil " & rs.Fields("Lot").Value & " " & rs.Fields("Coil").Value & " Cpk is Out of Spec " & rs.Fields("cpk").Value)
End If
If values of rs.Fields("machine") are always numbers you could do
Dim machine as Int = CInt(rs.Fields("machine").Value)
If Not (machine >= 41 AndAlso machine <= 42) Then
SendEmailCPK(Msg)
EventLog1.WriteEntry(EventLog1.Source, "Coil " & rs.Fields("Lot").Value & " " & rs.Fields("Coil").Value & " Cpk is Out of Spec " & rs.Fields("cpk").Value)
End If
As mentioned by Matt below a neater solution which makes the code easier to understand is...
If (machine < 41 AndAlso machine > 42) Then....
I run this little piece of code to do a kind of activity log window.
Sub writetolog(i As String)
Try
'outfile.Write(DateTime.Now.ToString("mm/dd/yyyy - H:mm:ss:fffffff") & "--->" & i & vbCrLf)
Console.WriteLine(DateTime.Now.ToString("HH:mm:ss:ff") & " - " & i)
If String.IsNullOrWhiteSpace(i) = False Then LogLB.Items.Add(DateTime.Now.ToString("[" & "MM/dd/yy - HH:mm:ss:ff") & "] -- " & i) 'Else MsgBox(i & " is nothing!")
If LogLB.Items.Count >= 100 Then LogLB.Items.RemoveAt(0)
If LogLB.Items.Count > 0 Then LogLB.SelectedIndex = LogLB.Items.Count - 1
Catch ex As Exception
Console.Write(ex)
End Try
End Sub
So it works most of the time, but for some reason at seemingly random times I get a Null Exception and it points to the end of the line at
LogLB.Items.Count - 1
Why?