VBA Run two Commands at once together Beep Command - vba

I have made a program that generates frequencies using the Beep statement.
For example: Beep(Val(FreqTestTxt.Text), Val(DurLbl.Text) * 1000)
What I need to do though is to Generate 2 frequencies at once. How can it be done?

Related

Access 2007 - Programmatically Run Report Multiple Times

I am using Access 2007. I want to use VBA code that will programmatically
run an Access Report a series of times. Something like this:
Dim eid$(5)
eid$(1)="001":eid$(2)="021":eid$(3)="043":eid$(4)="052":eid$(5)="067"
for i=1 to 5
Forms![frmWork]!txtEid=eid$(i)
DoCmd.OpenReport "rptEmployees", acViewPreview
next i
The report uses a query that contains:
WHERE (employee.eid)=Forms![frmWork]!txtEid
After the report appears on the screen I want it to immediately close - without the user
clicking Close Print Preview - and return to the VBA loop so another report can be generated.
You may wonder why I'm doing this? Let's just say I'm experimenting.
My question is...how can I get the report to close? Is there an event that occurs
when a report has finished printing?
If I knew how many records (n) were output by the query I could put a counter
in the report's Detail_Print() code. When the counter reached n I could have the report close.
Can I determine how many records are in the query results when the report opens?
Thanks very much.

Use autosave with numeric condition

I am looking for a way to use autosave in VBA if an evolving numeric condition is met. Basically, I am looping through a variable called 'input_row' and I would like to use a condition that tests whether that variable is a multiple of 25 for instance:
If input_row = (random integer) * 25 Then
ActiveWorkbook.AutoSave
End If
Given that my code is constantly crashing due to issues with IE8, as discussed here, here making sure to autosave now and then seems pretty important. At the moment I am saving after every iteration in my loop which works fine but slows down the entire process quite a bit.
Any simple 'if' statement suggestion?
Use the Mod function to test if your number is a multiple of 25:
If input_row Mod 25 = 0 Then
'input_row is a multiple of 25
End If

How to prompt messagebox once inside a for loop in vb.net?

Is it possible to display a single messagebox inside a for loop codes?
I am trying to but cannot successfully make it.
Please help.
Thanks in advance.
Code inside a loop, by definition, is meant to execute multiple times, for each iteration of it, so if you don't want to have multiple messages, move that call outside of the loop so it executes only once. This would be the main way of doing so, because it makes it clear that there will be ever only one of them.
Otherwise, you can condition its display, by some particular condition that's warranted to happen only once, possibly caching the result from the user. The second snippet from phadaphunk does something like that.
From you question, I get that you don't understand how it works below.
The loop is a set of instructions that must be executed "x" number of time. So everything that is in the body of that loop will be executed that number of time. Which means that if there are 5 iterations to the loop, you will get 5 messagebox.
This is how you do it if you want a different box for each iterations :
For Each x As Integer In someList
MessageBox.Show(x.ToString());
Otherwise you can't do it unless there is a certain condition that explains to the compiler at which iteration you want the message box to appear. Something like
For Each x As Integer In someList
If (x == 5)
MessageBox.Show(x.ToString());

Script to modify outlook (2003) contacts

I'm trying to clean up my outlook 2003 contacts, which has become a rather ugly mess of various formatting, etc.
Basically, I have a bunch of contacts, in the form of either:
0xxxxxxxxx [ten digits, starting with 0] 0xxxxxxxx [nine digits, starting with 0] 0xxxxxxxx (xxxxx) [the same nine digits above with the last five repeated in parentheses] +xxxxxxx [some random "complete" number with an international dialing code, etc]
I want all of the numbers to match the last format. The algorithm is simple enough: for the first two types, drop the 0 and add +YYY where YYY is my country code. Ditto for the third, but drop everything in parentheses.
My problem is that I don't know how to go about doing this. I've written a million scripts in my life in Perl, but I'd rather not export everything to text, process it, and re-import; I'd like to have a one-click solution that can easily be re-run (such as when I import a new contact from my companies' directory which comes in one of the forms above). I suspect that VBScript is the way to go; I've seen a few references online to accessing contacts as objects, but I'm not really sure what the best way to get started is.
Any recommended resources?
This is a duplicate of https://superuser.com/questions/15913/script-to-modify-outlook-2003-contacts ; I'm not sure which site is a better location
I would say VBA, rather than VBScript.
Sub GetContactsTel()
Set oFolder = GetNamespace("MAPI").GetDefaultFolder(olFolderContacts)
' Loop through all of the items in the folder.
For i = 1 To oFolder.Items.Count
Debug.Print oFolder.Items(i).BusinessTelephoneNumber
Next
End Sub

vba more realistic random number generator

I know I can use a quasi-random number generation function/variable called Rnd. However, I've noticed that whenever I used Rnd in my userform, this sequence of numbers always show up:
first iteration: 0.705547511577606
second iteration: 0.533424019813538
...
As a result, b/c the sequence of numbers showing up are the same every time when I relaunch the userform, it doesn't feel random. Are there other functions in the VBA function set that would make it feel more random? Thanks in advance.
Try adding a single call to Randomize Timer before you do any calls to Rnd. This will seed the random number generator using the time of day.
I don't know a lot about VB but I think you need to seed your number generator. I think Randomize does it for VB.
You could manually set the seed based on the time of day... insert something like this at the top of your vba code:
For i = 0 To (CInt(Format(Time, "ms"))) 'minutes and seconds turned to integer
test_random = Rnd()
Next