Can someone help with vba to have beep sounds a few times at the end of multiple macros running.
You can obtain a nice effect using the next class code. Firstly, insert a class module, name it clsMusic and paste the next code in it:
Option Explicit
#If Win64 Then
Private Declare PtrSafe Function Beep Lib "kernel32" _
(ByVal dwFreq As Long, ByVal dwDuration As Long) As Long
#Else
Private Declare Function Beep Lib "kernel32" _
(ByVal dwFreq As Long, ByVal dwDuration As Long) As Long
#End If
Enum Note
Ab7 = 3322.44
G7 = 3135.96
Gb7 = 2959.96
F7 = 2793.83
E7 = 2637.02
Eb7 = 2489.02
D7 = 2349.32
Db7 = 2217.46
c7 = 2093
B7 = 1975.53
Bb7 = 1864.66
A7 = 1760
Ab6 = 1661.22
G6 = 1567.98
Gb6 = 1479.98
F6 = 1396.91
E6 = 1318.51
Eb6 = 1244.51
D6 = 1174.66
Db6 = 1108.73
c6 = 1046.5
B6 = 987.767
Bb6 = 932.328
A6 = 880
Ab5 = 830.609
G5 = 783.991
Gb5 = 739.989
F5 = 698.456
E5 = 659.255
Eb5 = 622.254
D5 = 587.33
Db5 = 554.365
c5 = 523.251
B5 = 493.883
Bb5 = 466.164
A5 = 440
Ab4 = 415.305
G4 = 391.995
Gb4 = 369.994
F4 = 349.228
E4 = 329.628
Eb4 = 311.127
D4 = 293.665
Db4 = 277.183
c4 = 261.626
B4 = 246.942
Bb4 = 233.082
A4 = 220
Ab3 = 207.652
G3 = 195.998
Gb3 = 184.997
F3 = 174.614
E3 = 164.814
Eb3 = 155.563
D3 = 146.832
Db3 = 138.591
c3 = 130.813
B3 = 123.471
Bb3 = 116.541
A3 = 110
Ab2 = 103.826
G2 = 97.9989
Gb2 = 92.4986
F2 = 87.3071
E2 = 82.4069
Eb2 = 77.7817
d2 = 73.4162
Db2 = 69.2957
c2 = 65.4064
B2 = 61.7354
Bb2 = 58.2705
A2 = 55
Ab1 = 51.9131
G1 = 48.9994
Gb1 = 46.2493
f1 = 43.6535
E1 = 41.2034
Eb1 = 38.8909
d1 = 36.7081
Db1 = 34.6478
c1 = 32.7032
B1 = 30.8677
Bb1 = 29.1352
A1 = 27.5
End Enum
Public Sub Play(myNote As Note, mySeconds As Long, Optional times As Integer = 1)
Dim i As Integer
If times >= 1 Then
For i = 1 To times
Beep myNote, (mySeconds * 300)
Next
End If
End Sub
It creates musical notes...
Then, at the end of your code use something like this:
Sub MusicTest()
Dim Muz As New clsMusic
Muz.Play c4, 1
Muz.Play E4, 1
Muz.Play G4, 1
Muz.Play c5, 3
End Sub
I must mention that I am not the father of the code. I have it in my collection of nice codes. I took it from internet some years before and I do not know who posted it to send the credit in that direction...
Related
I am using rbx.lua. Everything works except for the color changing at the bottom.
Please note that the script is not finished, I just stopped at p1.
--Variables--
local r1 = math.random(100)
local r2 = math.random(100)
local r3 = math.random(100)
local p1 = workspace.Part1
local p2 = workspace.Part2
local p3 = workspace.Part3
local c1 = game.ServerStorage.green
local c2 = game.ServerStorage.yellow
local c3 = game.ServerStorage.red
local grn = NumberRange.new(0, 45)
local ylw = NumberRange.new(46, 75)
local red = NumberRange.new(76, 100)
--Randomizing Y Vector Between 0 and 100--
p1.Size = Vector3.new(4, r1, 4)
p2.Size = Vector3.new(4, r2, 4)
p3.Size = Vector3.new(4, r3, 4)
--Setting up colors--
if p1.Size.Y == grn then
p1.BrickColor = c1
end
if p1.Size.Y == ylw then
p1.BrickColor = c2
end
if p1.Size.Y == red then
p1.BrickColor = c3
end
Try this instead:
Remove the NumberRange variables, and replace the if blocks with this:
if p1.Size.Y <= 45 then
p1.BrickColor = c1
elseif p1.Size.Y <=75 then
p1.BrickColor = c2
else
p1.BrickColor = c3
end
The elseif block won’t be checked unless the p1.Size.Y value is above 45. Same for the else block: it won’t be entered unless the value is above 75.
Hope that helps! You were checking to see if a specific value was equal to (==) a range...not if the value was in the range.
With the below code I am trying to format cells when certain names appear in a drop down list(cell C4) and format these specific cells in Range G9:N9. But when I run the code it converts all numbers into percents appose to differentiating between the two formatting styles (Percent and General). Can anyone help?
Sub LetsMakeThisWork()
With Worksheets("Geo")
If C4 = V2 Or C4 = x2 Or C4 = AB2 Or C4 = AD2 Or C4 = AG2 Or C4 = AM2 Or C4 = AO2 Or C4 = AQ2 Or C4 = AU2 Or C4 = AW2 Then
ActiveCell.Range("G9:N9").NumberFormat = "0.0%"
Else
ActiveCell.Range("G9:N9").NumberFormat = "General"
End If
End With
End Sub
In context, you intend C4, V2 etc. to be a cell references but VBA is interpreting them as variables. The fact that your code runs at all in that case implies that you are not using Option Explicit, which you really should use in VBA. What seems to be happening is that you are implicitly creating empty variables in the process of testing them for equality. Any two empty variables are equal, hence the first clause of the If statement is always run. Corrected, but not tested, your code should (I think) look like this:
Option Explicit
Sub LetsMakeThisWork()
Dim C4 As Range
With Worksheets("Geo")
Set C4 = .Range("C4")
If C4.Value = .Range("RV2").Value Or C4.Value = .Range("X2").Value Or _
C4.Value = .Range("AB2").Value Or C4.Value = .Range("AD2").Value Or _
C4.Value = .Range("AG2").Value Or C4.Value = .Range("AM2").Value Or _
C4.Value = .Range("AO2").Value Or C4.Value = .Range("AQ2").Value Or _
C4.Value = .Range("AU2").Value Or C4.Value = .Range("AW2").Value Then
.Range("G9:N9").NumberFormat = "0.0%"
Else
.Range("G9:N9").NumberFormat = "General"
End If
End With
End Sub
I am having some trouble with my vba code. It seems to be running in F8 but not in F5. When it runs in F5, item is not recognized (shows up as item = nothing). I have pasted the code below.
Sub SlicerSelect()
'On Error Resume Next
Worksheets("Sheet3").Activate
'Dim cache As Excel.SlicerCache
Dim item As SlicerItem
Dim Eval_Cell As String
Offset_Cell = Sheets("Sheet3").Range("A18").Address
A = 1: AA = 0: AAA = 0
For A = 1 To 2
AA = AA + 1
If AA = 1 Then
Slicer_Name = "Slicer_Color"
ElseIf AA = 2 Then
Slicer_Name = "Slicer_Letter"
End If
'Set cache = ActiveWorkbook.SlicerCaches(Slicer_Name)
BB = 0
Do Until End_Switch = 1
AAA = AAA + 1: BB = BB + 1: Eval_Cell = Range(Offset_Cell).Offset(0, CStr(AAA))
If BB = 1 Then
'''
Else
For Each item In ThisWorkbook.SlicerCaches(Slicer_Name).SlicerItems
If item.Name = Eval_Cell Then
item.Selected = True
Else
item.Selected = False
End If
Next item
End If
If IsEmpty(Eval_Cell) Then End_Switch = 1
Stop
Loop
End_Switch = 0
Next A
End Sub
I'm working with parsing emails for a project i'm working on.
so far I connect to a pop3 mail server, download all of the mail thats there and loop through it getting the sender, subject and body.
I then decode the base64 body, which leaves me with a multi-part MIME message, like the following test email i sent myself...
I need to be able to split this Multipart MIME email body so that I can have one string which contains just the plain text version of the mail and another string which contains the html part.
I'm not interested in anything else the mail might have... attachments and suchlike can all get dropped.
Can anyone point me in the right direction?
If i'm going to be looking at using a 3rd party control, does anyone know of anything freeware that would be able to do this? I would never need to encode, just decode.
Assuming you have the headers in the email which you have extracted so that you can get the string used to identify the part boundaries in the email, you can get some way through the parsing with code like this:
Imports System.IO
Imports System.Text.RegularExpressions
Module Module1
Sub Main()
Dim sampleEmail = File.ReadAllText("C:\temp\SampleEmail.eml")
Dim getBoundary As New Regex("boundary=(.*?)\r\n")
Dim possibleBoundary = getBoundary.Matches(sampleEmail)
Dim boundary = ""
If possibleBoundary.Count = 0 Then
Console.WriteLine("Could not find boundary specifier.")
End
End If
' the boundary string may or may not be surrounded by double-quotes
boundary = possibleBoundary(0).Groups(1).Value.Trim(CChar(""""))
Console.WriteLine(boundary)
boundary = vbCrLf & "--" & boundary
Dim parts = Regex.Split(sampleEmail, Regex.Escape(boundary))
Console.WriteLine("Number of parts: " & parts.Count.ToString())
' save the parts to one text file for inspection
Using sw As New StreamWriter("C:\temp\EmailParts.txt")
For i = 0 To parts.Count - 1
' this is where you would find the part with "Content-Type: text/plain;" -
' you may also need to look at the charset, e.g. charset="utf-8"
sw.WriteLine("PART " & i.ToString())
sw.WriteLine(parts(i))
Next
End Using
Console.ReadLine()
End Sub
End Module
The email I used to test that did not have any base-64 encoding involved.
I would recommend using my free/open source MimeKit library to accomplish this task as opposed to using a regex solution.
I don't really know VB.NET, so the following code snippet might not be quite right (I'm a C# guy), but it should give you the general idea of how to accomplish the task you want:
Dim message = MimeMessage.Load ("C:\email.msg");
Dim html = message.HtmlBody;
Dim text = message.TextBody;
As you can see, MimeKit makes this sort of thing extremely trivial.
A = E1 = 80 =
= B8 = E1 = 80 = 80 = E1 = 80 = BC = E1 = 80-8A = E1 = 80 = BA; = 50 = 61 = 74 = 69 = 65 = 6E = 74 ;;
-PRINTABLE: = 50 = 61 = 74 = 69 = 65-6 E = 74 = 20 = E1 = 80 = 99 = E1 = 80 = 81 = E1 = 80 = 84 = E1 = 80 = BA =
E1 = 81 = 80 =
= E1 = 80 = 84 = E1 = 80 = BA = E1 = 80 = B8 = E1 = 80 = 80 = E1 = 80 = BC = E1 = 80 = 8A = E1 = 80 = BA
B = E1 = 80 = AD = E1 = 80 = AF; = 50 = 61 = 74 = 69 = 65 =
6E = 74 ;;
E1 = 80 = AF =
END: VCARD
I have textbox1 and textbox2 which will be the two inputed data, and I want to get the values between them. And the challenge is the ASCW character I and O is not included.
Im using this basis code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim tb1 As String = TextBox1.Text
Dim tb2 As String = TextBox2.Text
Dim cb As String = ""
If tb1.Substring(tb1.Length - 1) <> tb2.Substring(tb2.Length - 1) Then
While (tb1 <> tb2)
Dim temp As String = tb1.Substring(0, tb1.Length - 1)
Dim temp1 As Char = tb1(tb1.Length - 1)
If AscW(UCase(temp1)) >= 48 And AscW(UCase(temp1)) < 90 Then
temp1 = ChrW(AscW(UCase(temp1)) + 1)
ElseIf AscW(UCase(temp1)) >= 90 Then
temp1 = ChrW(AscW(UCase(temp1)) - 42)
End If
tb1 = temp & temp1
If tb1 <> tb2 Then
cb += tb1 & " "
End If
End While
MessageBox.Show(cb)
Else
'Do here
MessageBox.Show("none")
End If
End Sub
Basic arrangement: A0 A1 A2 A3 A4 A5 A6 A7 A8 A9 AA AB AC AD AE AF AG AH AJ AK AL AM AN AP AQ AR AS AT AU AV AW AX AY AZ B0 B1 B2 B3 B4 B5 B6 B7 B8 B9 BA...... ETC.
The ASCW character I and O is not included.
Example Scenario:
textbox1 = SF446DNLS
textbox2 = SF446DNNZ
Output:
SF446DNLT SF446DNLU SF446DNLV SF446DNLW SF446DNLX SF446DNLY SF446DNLZ SF446DNM0 SF446DNM1 SF446DNM2 SF446DNM3 SF446DNM4 SF446DNM5 SF446DNM6 SF446DNM7 SF446DNM8 SF446DNM9 SF446DNMA SF446DNMB SF446DNMC SF446DNMD SF446DNME SF446DNMF SF446DNMG SF446DNMH SF446DNMJ SF446DNMK SF446DNML SF446DNMM SF446DNMN SF446DNMP SF446DNMQ SF446DNMR SF446DNMS SF446DNMT SF446DNMU SF446DNMV SF446DNMW SF446DNMX SF446DNMY SF446DNMZ SF446DNN0 SF446DNN1 SF446DNN2 SF446DNN3 SF446DNN4 SF446DNN5 SF446DNN6 SF446DNN7 SF446DNN8 SF446DNN9 SF446DNNA SF446DNNB SF446DNNC SF446DNND SF446DNNE SF446DNNF SF446DNNG SF446DNNH SF446DNNJ SF446DNNK SF446DNNL SF446DNNM SF446DNNN SF446DNNP SF446DNNQ SF446DNNR SF446DNNS SF446DNNT SF446DNNU SF446DNNV SF446DNNW SF446DNNX SF446DNNY SF446DNNZ
Check my other answer on Extract data really slow with a 30MB random data file for searching between two strings using Regex:
If you need to exclude I and O, use ^ (based on code in the above answer):
Dim allData = "nonmatch2_strA_match_strB_nonmatch2"
Dim r = Regex.Match(allData, "strA([^IO]*)strB")
You can further fine tune the expression to accept only numbers + characters, but without I and O using
Character Class Subtraction # MSDN