How to play audio via a specific sound card? - audio

I need to play a sound (.WAV file) from a Visual Basic 6 application. However, the PC is equipped with multiple sound cards and the user should be able to use it.
Up till now a default sound card was supported and I would play a sound like this:
CommandString = "Open " & Chr$(34) & mstrFilename & Chr$(34) & " type waveaudio alias MediaFile"
mciSendString CommandString, vbNullString, 0, 0&
If PlayFromPercent <= 0 Then
CommandString = "play MediaFile"
lngRetcode = mciSendString(CommandString, vbNullString, 0, 0&)
Else
CommandString = "play MediaFile from " & CLng(lngLength * (PlayFromPercent / 100))
lngRetcode = mciSendString(CommandString, vbNullString, 0, 0&)
End If
Is there a way to adapt this code for a specific sound card or is there a different approach I could take (e.g. DirectX or a commercial 3rd Party Library)?
Bonus, if the approach supports playing the file from a specific position (as you can see, the code above supports it)

This may work; call mciSendCommand() with MCI_SET & MCI_WAVE_SET_PARMS setting wOutput to the desired playback device's ID.
You can get IDDevice for mciSendCommand() via mciGetDeviceID("waveaudio")
Its not 100% clear what wOutput wants, its probably the same ID as returned by waveOutGetDevCaps()

Related

Converting bullets Text to HTML using VBA function Excel

I have lots of products which have description including bullets, which I want to convert it to html form excel file.
Description of product be like in one cell :
• Our aim is to be devoted to building a sustainable future.
• We are keen to preserve the human being and its environment.
• It is best for all skin types
some macro code I have tried is like:
Sub aTest()
Dim rCell As Range, spl As Variant, i As Long
For Each rCell In Selection
spl = Split(rCell, Chr(10))
For i = LBound(spl) To UBound(spl)
spl(i) = Chr(60) & "li" & Chr(62) & spl(i) & Chr(60) & "/li" & Chr(62)
Next i
rCell = Join(spl, Chr(10))
Next rCell
Selection.ColumnWidth = 200
Selection.EntireRow.AutoFit
Selection.EntireColumn.AutoFit
End Sub
this code gives me output including bullets within it:
Expected:
<li> Our aim is to be devoted to building a sustainable future. </li>
<li> We are keen to preserve the human being and its environment.</li>
<li> It is best for all skin types</li>
Could anyone please help me get this correct, as I do not have any idea of VB.
Moreover, it would be great to have Function rather than macro.
Thanks
Update: I have this whole content within one cell and want it to convert to html together. Is that possible?
BIODERMA is a brand of NAOS, the world’s number 1 cosmetic company. BIODERMA has been dedicated to skin health for 40 years and has pioneered many breakthroughs in dermatological care. We are a company that provides high-quality skin care products developed by medical professionals with the absolute highest safety standards.
Key Features:
• Our aim is to be devoted to building a sustainable future.
• We are keen to preserve the human being and its environment.
• It is best for all skin types
Private Function ConvertBulletToHTML(argInput As String) As String
Dim cleanArr() As String
cleanArr = Split(argInput, vbLf)
Dim i As Long
For i = 0 To UBound(cleanArr)
If Instr(cleanArr(i), Chr(149)) <> 0 Then
cleanArr(i) = Replace(cleanArr(i), Chr(149), vbNullString)
cleanArr(i) = "<li>" & Trim(cleanArr(i)) & "</li>"
End If
Next i
ConvertBulletToHTML = "<div>" & Join(cleanArr, vbLf) & "</div>"
End Function
This is the output:
<div><li>Our aim is to be devoted to building a sustainable future.</li>
<li>We are keen to preserve the human being and its environment.</li>
<li>It is best for all skin types</li></div>
And output for the updated question:
<div>BIODERMA is a brand of NAOS, the world’s number 1 cosmetic company. BIODERMA has been dedicated to skin health for 40 years and has pioneered many breakthroughs in dermatological care. We are a company that provides high-quality skin care products developed by medical professionals with the absolute highest safety standards.
Key Features:
<li>Our aim is to be devoted to building a sustainable future.</li>
<li>We are keen to preserve the human being and its environment.</li>
<li>It is best for all skin types</li></div>
Remove the Trim in the for loop if you do not want it trimmed.
Note: vbLf is the same as Chr(10) so you can just use the built-in constant.
Try:
spli(i) = Replace(spli(i), Chr(149), "")
You must check if it is actually Chr(149) and change it to something else if it is not.
Other way - assuming it is the first character in your spli(i)
spli(i) = Right(spli(i), Len(spli(i)) - 1)
This must be applied before adding html tags.

How to get a specific statement from a PDF using selenium with VBA

This is a continuity question of the below link. https://stackoverflow.com/a/56649098?noredirect=1
I need to do two things
1. Copy all text from PDF and paste it to the excel
2. Copy multiple lines and run a loop to find the text I need
The background of my project - I am opening a webpage with user credentials, after couples of clicks a PDF is opened in the browser. So now I need to get a particular statement from it. The problem is that the PDF is dynamic and the statement I require keeps changing (the line sometimes it is in 6th and sometimes in 9th or 10th and 11th) so the 2 things which I mentioned above will help me I am aware both sounds the same but it is different. Below is the code I used to get a particular statement, but how do I create a loop through all the statement or get multiple statements.
Const statext As String = _
"addEventListener('message',function(e){" & _
" if(e.data.type=='getSelectedTextReply'){" & _
" var txt=e.data.selectedText;" & _
" callback(txt && txt.match(/[^\r\n]+/g)[7]);" & _
" }" & _
"});" & _
"plugin.postMessage({type:'initialize'},'*');" & _
"plugin.postMessage({type:'selectAll'},'*');" & _
"plugin.postMessage({type:'getSelectedText'},'*');"
Casestatus = bot.ExecuteAsyncScript(statext)
I am very new to programming and automation so I may be missing a basic thing. Kindly pardon me.

Lotus Notes: Add clickable telephone number to mail

In lotus notes i have a script agent that auto generate mails and send it.
In the body of these mails i put lots of data among which some telephone numbers that i want they will be clickable from devices. How can i do this ?
Here the code that i use:
notebody="People:" & doc.people(0) & chr(10) & Cstr(doc.date(0)) & "Phone Number:"& doc.phone(0)
Set rtItem = New NotesRichTextItem(Maildoc , "Body" )
Call rtItem.AppendText(notebody)
The field that i want will be clickable is doc.phone(0). How can i do ? thank's
'First, see here: Answer to 'Is there a way to make a phone number clickable...'
In order to adapt that answer to a Notes agent that is using the rich text classes to generate a message, you would need to use pass-thru HTML. You can do this simply by surrounding the HTML fragment with '[' and ']' characters.
I.e., something like this:
notebody="People:" & doc.people(0) & chr(10) & Cstr(doc.date(0)) & |Phone Number: [| & doc.phone(0) & "]"
Note: not tested! I used the | char as the alternate for quotation marks in order to avoid escaping, and I checked carefully for typos, but...

Play sound file from within VBScript when msgbox appears

I am trying to play a sound file from within a VBScript when a certain msgbox appears. The only problem is that I will be sending this elsewhere and the person who receives it won't have the same pathname as the audio file that I want to play. I was thinking about putting all of the sound files that I want to use in the same folder as the script and then sending that folder, but I don't know how to make sure the sound file will play.
So I guess the biggest question is how to generalize the pathname so that anyone can hear the file from within the script from any machine.
Here is my code so far:
if intAnswer3 = vbyes then
strSoundFile = "C:\pathname"
Set objShell = CreateObject("Wscript.Shell")
strCommand = "sndrec32 /play /close " & chr(34) & strSoundFile & chr(34)
objShell.Run strCommand, 0, True
Assume that you have a folder named Music with your script, so you can use a relative path like this ./Music/Matrix.mp3
So you can give a try like this :
Option Explicit
Dim Msg,Question,PathSound
Msg = "Did you want to hear some music ?"
PathSound = "./Music/Matrix.mp3" 'Relative Path
Question = MsgBox(Msg,VbQuestion+VbYesNo,Msg)
If Question = VbYes Then
Call Play(PathSound)
Else
Wscript.Quit()
End If
'**********************************************************
Sub Play(SoundFile)
Dim Sound
Set Sound = CreateObject("WMPlayer.OCX")
Sound.URL = SoundFile
Sound.settings.volume = 100
Sound.Controls.play
do while Sound.currentmedia.duration = 0
wscript.sleep 100
loop
wscript.sleep(int(Sound.currentmedia.duration)+1)*1000
End Sub
'**********************************************************
And if you like to play the music online, so you can do it like this :
Option Explicit
Dim Msg,Question,PathSound
Msg = "Did you want to hear some music ?"
PathSound = "http://hackoo.alwaysdata.net/Matrix.mp3"
Question = MsgBox(Msg,VbQuestion+VbYesNo,Msg)
If Question = VbYes Then
Call Play(PathSound)
Else
Wscript.Quit()
End If
'**********************************************************
Sub Play(SoundFile)
Dim Sound
Set Sound = CreateObject("WMPlayer.OCX")
Sound.URL = SoundFile
Sound.settings.volume = 100
Sound.Controls.play
do while Sound.currentmedia.duration = 0
wscript.sleep 100
loop
wscript.sleep(int(Sound.currentmedia.duration)+1)*1000
End Sub
'**********************************************************
I hope that this answer can help you to complete your main script ;)
Did you mean something like that :
Description :
This Vbscript "PlayListSongs.vbs" scan into a folder and its subfolders for songs and create a playlist in a text file in order to play it in background.
Update : I add another vbscript to stop and kill the "wscript.exe" process in order to stop music playing in background.
I add another vbscript to play the playlist with Windows Media Player in foreground.
in sum you can found into zip 3 vbscript
1- To play the playlist in the background.
2- To Stop the music.
3- To Play the music with Windows Media Player in foreground.
So you can download it from here and test it

Applescript for turning desktop Gmail link into iOS Gmail app link

I'm looking to build an Applescript that will take a desktop Gmail message link as input, and output a URL that will work on iOS to open the same message in the iOS Gmail app.
Here's a typical Gmail URL:
https://mail.google.com/mail/u/1/?zx=tso6hataagpp#inbox/143c5ddc34313e1f
And here's what that same URL would need to look like to work on iOS:
googlegmail:///cv=143c5ddc34313e1f/accountId=2
A couple notes:
The important part (the thread identifier) is the last part of the string in the original desktop URL. That's what needs to go after cv= in the mobile URL. However because Gmail allows multiple account log-in, we also need to note the account ID number after the /u/, which on the desktop is 1, but for mobile is 2. It looks like the desktop URLs are numbered starting at 0, while the mobile URLs are numbered starting at 1, based on which account you logged into first. So we need to increment the account ID number by 1 for the iOS URL.
Also, I'm not sure what the "?zx=tso6hataagpp" is before #inbox; I find that sometimes my desktop Gmail URLs include that part, other times they don't (but still include #inbox). I don't think it matters though, since the important parts we want are at the end of the string, and the number after the always-consistent "mail.google.com/mail/u/".
Ideally the Applescript would look at the clipboard for a desktop Gmail URL, and if it found one, it would output that same URL, then a line break, then the iOS URL immediately following it, like so:
https://mail.google.com/mail/u/1/?zx=tso6hataagpp#inbox/143c5ddc34313e1f
googlegmail:///cv=143c5ddc34313e1f/accountId=2
Any Applescript gurus out there that can show me how to hack this together?
The simplest way I can think of is:
This gets fixed path components. i.e component 5 and the last item
--https://mail.google.com/mail/u/1/?zx=tso6hataagpp#inbox/143c5ddc34313e1f
set pathUrl to (the clipboard)
set pathComponents to words of pathUrl
if item 1 of pathComponents is "https" and item 2 of pathComponents is "mail.google.com" then
set composed to pathUrl & return & "googlegmail:///cv=" & last item of pathComponents & "/accountId=" & (((item 5 of pathComponents) as number) + 1)
end if
This makes sure it always get the component ( account) after the "u" regardless of where it is.
You could do the same for the message id. by using "inbox"
set composed to ""
--set pathUrl to "https://mail.google.com/mail/u/1/?zx=tso6hataagpp#inbox/143c5ddc34313e1f"
set pathUrl to (the clipboard)
set pathComponents to words of pathUrl
if item 1 of pathComponents is "https" and item 2 of pathComponents is "mail.google.com" then
repeat with i from 1 to number of items in pathComponents
set this_item to item i of pathComponents
if this_item is "u" then
set this_item to item (i + 1) of pathComponents
set composed to pathUrl & return & "googlegmail:///cv=" & last item of pathComponents & "/accountId=" & ((this_item as number) + 1)
exit repeat
end if
end repeat
end if
composed
Try the following - delegates the parsing to bash via do shell script.
# Get text from clipboard.
# Test with: "https://mail.google.com/mail/u/1/?zx=tso6hataagpp#inbox/143c5ddc34313e1f"
set hLink to (the clipboard as text)
# Parse the link to extract the information of interest.
set parseResult to do shell script ¬
"[[ " & quoted form of hLink & " =~ /u/([0-9]+)/.+#inbox/(.+)$ ]] &&
printf '%s\\n' \"${BASH_REMATCH[1]}\" \"${BASH_REMATCH[2]}\""
# Synthesize the Gmail for iOS link.
set gmLink to "googlemail:///cv=" & ¬
(paragraph 2 of parseResult) & "/accountId=" & (1 + (paragraph 1 of parseResult))
# Synthesize the result
set res to hLink & linefeed & gmLink
# Put the result back on the clipboard.
set the clipboard to res

Resources