How to iterate over a mailbox in SystemVerilog without removing its elements? - iteration

I have a mailbox of type ethernet packet. I have randomly put data into the mailbox. Now I want to print each element of mailbox without removing the element.
I tried doing try_peek but it always points to the first element, so it always prints the first element. the get() method removes the element, so at the end of for loop the mailbox is empty.
Is there a way that I can iterate over a mailbox in SystemVerilog without removing its elements?
for (int i=0; i<=9; i++)
begin
mbox_pkt.try_peek(pkt1);
$display("mbox_pkt=%p", pkt1);
end
mbox_pkt is a mailbox of type ethernet packet.

There is no way to access elements of a mailbox without removing the next element with a get or try_get.

Related

Access address of Textbox within Multipage

I have a userform with a runtime-defined multipage. On launch, the multipage populates a number of pages, each with their own textbox.
Example of the multipage defined during runtime.
The challenge comes that during runtime, the user can reorder, delete, add and rename these pages. At the end, I need to call all data from each page of the multipage, including the textbox. This means that within Me.Controls, the item numbers are not useful as they become jumbled.
However, within each page of the multipage is a further set of controls, which will only ever have the 1 item (the textbox). This means when I sweep the multipage in a 'for' loop, I could just always call item 1, similar to a 'me' statement.
Item1 within controls of each page of the multipage object.
However the code fails when I try to go beyond the second bunch of controls to call the value of the textbox.
For i = 0 to Last_Page-1
Example_String = Me.My_MultiPage.Pages.Item(i).Controls.Item(1).Value
Next i
Why can I not call this second tier of controls? Without this i have to write a huge amount of work-around code to manage names of each textbox as the user re-orders them.
Thanks in advance!
Collections use a 0 based index.
For i = 0 to Last_Page-1
Example_String = Me.My_MultiPage.Pages.Item(i).Controls.Item(0).Value
Next i
.Item is not needed because a Collection's default value is its Items.
For i = 0 to Last_Page-1
Example_String = Me.My_MultiPage.Pages(i).Controls(0).Value
Next i

Target all selected Illustrator objects, or target all objects if none are selected

How can I target an Adobe Illustrator script to limit itself to the user's selection if anything is selected, or to run on all objects if nothing is selected?
app.activeDocument.selection is often used to target the current selection but is empty if there's no selection.
app.activeDocument.pageItems is where to access all items as if everything was selected. So, this one liner:
var scope = app.activeDocument.selection.length ? app.activeDocument.selection : app.activeDocument.pageItems;
...sets the variable scope to be the selection if there is one, or everything if there is none. Its contents can then be cycled through the normal way, for example:
for(var i=0;i<scope.length;i++){
// do things with scope[i]
}

outlook vba code to display pictures in email

By default, my MS Outlook 2013 is set NOT to download images in received HTML e-mail messages. I would like to keep this setting.
There are some senders whose emails are handled by my Outlook VBA code...and filed into specific folders (rather than the INBOX). I do not use the in-built RULES.
These are known senders...and I would like to have the pictures in the emails from these SELECT KNOWN senders downloaded and displayed. I could do this manually for each email... by right clicking etc... but that is a pain... when there are many such emails.
I am unable to figure out the few lines of code (one line ?) required to download / enable display of images / pictures in the email. Something like... MailItem.Display (which does not work... it only displays the mail in an independent window)... or MailItem.DisplayImages (that is not a known method!).
I would include this one line (or lines) in the routine which handles emails from some known senders....so that their emails always have images / pictures downloaded and displayed.
Thanks.
You would need to set the PidTagBlockStatus property - see http://msdn.microsoft.com/en-us/library/ee219242(v=exchg.80).aspx.
Note that while you can read/write that property using MailItem.PropertyAccessor.SetProperty, you will not be able to calculate its value correctly - Outlook Object Model rounds off the value of the message delivery time, and you would need the raw Extended MAPI value (accessible in C++ or Delphi only) as the FileTime structure.
If using Redemption (I am its author) is an option, it exposes the RDOMail.DownloadPictures property. Something like the following should do the job (VB script):
set Session = CreateObject("Redemption.RDOSession")
Session.MAPIOBJECT = Application.Session.MAPIOBJECT
set Item = Session.GetRDOObjectFromOutlookObject(YourOutlookItem)
Item.DownloadPictures = true
Item.Save
The Outlook object model doesn't provide any property or method for that.

While loop to find a running total

I am trying to run a simple while loop to demonstrate to some pupils. The exercise is to be able to put numbers into a text box, press a button and the running total is shown in a label. The loop would be broken if the user put in the number 999. Below is my current attempt. The program will load but when the button is pressed nothing happens. Sigh!
Below is my current attempt.
- (IBAction)btnCalculate:(id)sender
{
int Total, Number;
Total = 0;
Number= 0;
while (Number!=999)
{
Number = [self.txtNumber.text integerValue];
Total = Total + Number;
self.lblTotal.text= [NSString stringWithFormat:#"%d",Total];
}
}
What do you expect to happen?
I think the loop is blocking your main thread, so you don't see everything happen and cannot change the labels text.
I think for your purpose it would be better to read the number from the label and increase total until it has the value of number.
NSInteger number = [self.txtNumber.text integerValue];
while(total <= number) {
NSLog("%d", total++);
}
If you want to put it in lblTotal you should run the loop on a background thread, but make sure to update your lbltotal.test on the main thread.
looks like an infinite loop to me. The method is likely called when you click the button, and the integer value you get doesn't change in subsequent loop iterations (because you don't allow the UI thread to continue to do its thing). You'll need to move the state out into properties on the object. This is not like reading input from stdin. The execution flow should go through the entire OS event loop, and your while loop is not at all part of that. So if the first value you enter is not 999, you get stuck in the while loop and the value you get after subsequent iterations in the while loop does not change (because your while loop is the only thing running on the UI thread and it's blocking further interactivity).
Really, you need to think about the flow of control. it's not at all like a standard terminal input / output model.

Removing items from listbox using backgroundworker

I want to delete all the items of a listbox that does NOT contain "mysite" and here's my code that works fine without backgroundworker.
Do Work Event:
Dim relevantSite As Integer = 0
Do Until relevantSite = lstLinks.Items.Count
If lstLinks.Items.Item(relevantSite).ToString.Contains("mysite") Then
relevantSite += 1
Else
bgWorker.ReportProgress(relevantSite)
End If
Loop
ProgressChanged Event:
lstLinks.Items.RemoveAt(CInt(e.ProgressPercentage))
What it does is, it removes alot of items, sometimes all items. I know I'm making some terrible mistake with e and reportProgress thing.
Please explain them to me, I searched various sites but could not understand it...
Rather than directly changing the items in the list you should create a new list in your background worker. This way you can add remove items from the list and return it to the UI once all the processing is completed and rebind the drop down.
I want to delete all the items of a listbox that does NOT contain
"mysite"
Walk the ListBox backwards and delete the offending items as you go. Wrap the process in BeginUpdate() and EndUpdate() so the ListBox only refreshes once when you're all done:
lstLinks.BeginUpdate()
Dim NumItems As Integer = lstLinks.Items.Count - 1
For i As Integer = NumItems To 0 Step -1
If Not lstLinks.Items(i).ToString.Contains("mysite") Then
lstLinks.Items.RemoveAt(i)
End If
Next
lstLinks.EndUpdate()
lstLinks.Refresh()
You are expecting the code to act as if it is synchronized. But multi-threading does not work that way.
Your code in do work will be processing the next record before report progress has completed. In other words the loop will not pause and wait for report progress to complete. This is a problem because when you call out to remove a item from the list, you reuse the index assuming the item is gone. After a few removals, the index passed in will not indicate the correct item. If you were to use an identifier rather than an index it would work. But the whole thing seems wrong to me since you are not doing any heavy lifting in the do work method.