Just a small question. When applying Ardens lemma(X=RX+S=R*S) on the following..
E3 = 01* + 2E3 I understood it as either one of these but im quite unsure...
E3 = 01*2* or is it E3 = 01* + 2*
Related
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...
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'm trying to create a solution where I push a button and two random numbers appear, that are divisible and leave no remainder. Below is the following code;
Dim E1 As Integer = CInt(Int((11 * Rnd()) + 1)) 'Random number between 1 and 10
Dim E2 As Integer = CInt(Int((11 * Rnd()) + 1)) 'Random number between 1 and 10
Do While E1 Mod 2 <> 0
E1 = CInt(Int((11 * Rnd()) + 1))
Loop
Do While E1 Mod E2 <> 0 And _
E2 <> 1 And _
E2 <> 0 And _
E1 <> E2
E2 = CInt(Int((11 * Rnd()) + 1))
Loop
lstDivVar1.Items.Add(E1)
lstDivVar2.Items.Add(E2)
The plan is to make a question that a student can answer - by being asked to divide E1 by E2. However, I don't want E2 to have (in chronological order to the Do While statement for E2);
(1) To be a number that causes a remainder
(2) To be 1
(3) To be 0
(4) To be the same number as E1
These are for obvious mathematical reasons to provide questions that challenge the students more.
Unfortunately, only the first logic in my Do While for E2 is being applied (E1 Mod E2 <> 0)
Any suggestions how to apply multiple conditions to a loop - it's a mickey mouse mistake I'm sure but I can't find the answer online - so please answer kindly :)
Hugh
You just had your logic wrong. This should work for you.
Do While E1 < 4 OrElse E1 Mod 2 <> 0
E1 = CInt(Int((11 * Rnd()) + 1))
Loop
Do While E1 Mod E2 <> 0 OrElse _
E2 = 1 OrElse _
E2 = 0 OrElse _
E1 = E2
E2 = CInt(Int((11 * Rnd()) + 1))
Loop
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