WIA, Vista, and VB6. Does this code work? - vb6

Basically the constraints here are that i must use WIA because i am trying to get my scanner software to work in Windows 7 and Vista. It would be preferable (like really preferable) if i could do this in VB6.
Now this code i have compiles and everything, however when i run it i get the error "No WIA device of the selected type is available." I'm beginning to suspect that my scanner is not WIA compatible.
Could anyone confirm that this code should work? (needs to work with any WIA device not just scanners)
Dim WIADia As WIA.CommonDialog
Dim Scan As WIA.DeviceManager
Set WIADia = New WIA.CommonDialog
Set Scan = WIADia.ShowSelectDevice(WIA.WiaDeviceType.UnspecifiedDeviceType, True, False)
WIADia.ShowAcquisitionWizard (Scan)
Thanks!

WIA.CommonDialog WIADia;
Device Scan;
WIADia = new WIA.CommonDialog();
Scan = WIADia.ShowSelectDevice(WiaDeviceType.UnspecifiedDeviceType, true, false);
WIADia.ShowAcquisitionWizard(Scan);

Related

Remove incompatible spaces from propertybag to solve error when saving form with ActiveX control

I am looking for a way to have VB6 edit a controls' propertybag right before or while the Form is being saved..
We're using an activeX control (AxisMediaControl) that seemingly uses Spaces in it's propertybag names which throws an error when trying to save the form the control is on.
System Error &H80070057 (-2147024809)
The same problem is described here:
Source of a similar problem, but i don't have *.h files ()
but since we use the compiled ActiveX i can't edit the way it handles writing properties, and we don't have access to the source of the ActiveX..
I've managed to create a workaround loading the control at runtime,as an Array of objects, but this way i wont have them indexed to capture events by index.
Dim Axis(1) As AxisMediaControl
For i% = 0 To 1
Set Axis(i%) = Controls.Add("AxisMediaControl.AxisMediaControl.1", "AMC" & i%)
Axis(i%).Tag = "CAM" + Format$(i%)
Next i%
' Play Video
With Axis(0)
.Top = 600
.Left = 240
.Width = 9135
.Height = 5535
.Visible = True
.StretchToFit = True
.MaintainAspectRatio = True
.EnableContextMenu = True
.MediaFile = VideoFile$
.play
End With
' Play Stream
With Axis(1)
.Top = 6840
.Left = 240
.Width = 9135
.Height = 5535
.Visible = True
.StretchToFit = True
.MaintainAspectRatio = True
.EnableContextMenu = True
.MediaFile = VideoStream$
.play
End With
The ActiveX is working fine with younger versions of Visual Basic like express 2005 or vb.net and only occurs under vb6.
Are there ways to 'edit' the way the properties are saved to the propertybag?
Can i edit the dll or ocx to behave differently and have a working up-to-date version of an ActiveX that was previously incompatible? I've tried using Resource Hacker on the dll files but to no avail since my knowledge there is limited..
Since you mentioned the control works in dotnet versions of VB, a workaround could be to write a wrapper in VB.NET, and then use that wrapper from VB6. This wrapper would provide a standard "ActiveX" (COM) interface and internally just call the original control. You would only need to expose the bare minimum of functionality in the wrapper, just to minimize the effort involved.
(Note - while this might work technically it may not be the best overall solution. For instance, if upgrading to a more modern control is possible that might be a better investment of time.)
Edit 1: A wrapper would impose some additional overhead, that is certain. But this overhead might not be important at all. If you only have to make a few calls for instance the runtime effect is probably irrelevant. OTOH if you have to call this thing within the innermost loop of some algorithm (doubtful for a UI control but...) that could be more of a problem.
Edit 2: If you don't already have any dotnet components in your app it might not be worth adding that dependency just for this issue. Or maybe it would be, if this truly is a showstopper; but that could be an additional consideration to think through carefully.

VBScript not working on IE11 which has frames

I have a code which is working perfectly fine in Excel VBA but when I am trying the same in VBscript, it is erroring out while looking for Frames on IE 11.
Name Value
Microsoft VBScript runtime error: Object doesn't support this property or method: 'ieobjbtn.GetElementsByTagName'
Dim objLink, ieobjbtn1, ieobjbtn
Set objCollection = objIE.Document.frames
Set ieobjbtn = objCollection("toolbar").Document.GetElementsByTagName("a")
'Script is giving mentioned error here
For Each objLink In ieobjbtn
If InStr(objLink.innerHTML, "xxxxx.gif") > 0 Then
objLink.Click
Wait_Webpage
Exit For
End If
Next
In the standard DOM the function is called getElementsByTagName - note the lowercase g at the start.
It wouldn't surprise me if older versions of IE supported case-insensitivity because that is normal in VBScript, but newer ones have withdrawn that feature. VBScript is rarely used in IE these days and is being dropped entirely in the Windows 10 version of IE.
''Update:''
The corrected version is:
Set objCollection = objIE.Document.frames
Set ieobjbtn = objCollection("toolbar").document.getElementsByTagName("a")

AVSpeechUtterance Not Working

In IOS 8 AVSpeechUtterance is Not Working. Every time I use AVSpeechSynthesizer along with AVSpeechUtterance, I get "Speech initialization error: 2147483665". The same code works fine for IOS 7.1 I have a very large text to convert to speech, and using Google TTS won't allow me to use more than 100 characters at a time. How can I implement text-to-speech in IOS 8? Any help will be appreciated.
See this topic, and linked question also: AVSpeechSynthesizer iOS 8 Issues
For me, TTS on iOS work only on real device, not simulator. But iOS8 still have some problems with voices, some workaround mentioned in questions above.
Also, please mention this (user should set some settings): Using AVSpeechSynthesizer/AVSpeechUtterance for Text-To-Speech will not work if SpeakSelection is not enabled in device's Accessiblity settings
First import Speech
import Speech
Secondly define global variable for AVSpeechSynthesizer
let speakTalk = AVSpeechSynthesizer()
Create function Audio to take input as string
func Audio(Input : String)
{
let speakText = AVSpeechUtterance(string: "\(Input)")
speakText.rate = 0.5
speakText.pitchMultiplier = 1.7
speakTalk.speak(speakText)
}
call func Audio()
Audio(Input : "Hello")

Use of SAPI Speech Recognition in a VBS Script?

I found this one-line example that allows to use the Windows SAPI Text-to-Speech feature in VBScript:
CreateObject("SAPI.SpVoice").Speak("This is a test")
I wonder if the SAPI Speech Recognition could be used in a VBScript program in the same easy way. When I seek for such information the tons of SAPI information that appear are related to C++, like the Microsoft SAPI site, or to Text-to-Speech in VBS. I tried to find documentation about the SAPI COM object Speech Recognition part that could be used in a VBScript, but found none.
Do you know if such a documentation exists? TIA
EDIT: Additional request added after the first answer was recevied
Although the first answer below provide a link to the SAPI COM object documentation, I want to attract your attention to a point in my question: "I wonder if the SAPI Speech Recognition could be used in a VBScript program IN THE SAME EASY WAY". The SAPI documentation is huge! I read several pages of it and I am completely lost... My goal is to recognize just a few single words, say 8 or 10, and show a different message in the screen each time that one of they was recognized; that is it! (The program should be a console application started via cscript). Is there a simple example of VBS code that achieve such thing? If the required code to program this solution needs to have several pages, then it is not the answer I am looking for...
Here is a working example of vbscript listening a wav file:
scriptRunning = true
Sub rc_Recognition(StreamNumber, StreamPosition, RecognitionType, Result)
Wscript.Echo "Reco: ", Result.PhraseInfo.GetText, ".", RecognitionType
End Sub
Sub rc_StartStream(StreamNumber, StreamPosition)
Wscript.Echo "Start: ", StreamNumber, StreamPosition
End Sub
Sub rc_EndStream(StreamNumber, StreamPosition, StreamReleased)
Wscript.Echo "End: ", StreamNumber, StreamPosition, StreamReleased
scriptRunning = false
End Sub
outwav = "C:\SOFT\projects\af2t\t.wav"
Const SAFT22kHz16BitMono = 22
Const SSFMOpenForRead = 0
set sapiFStream = CreateObject("SAPI.SpFileStream")
sapiFStream.Format.Type = SAFT16kHz16BitMono
sapiFStream.Open outwav, SSFMOpenForRead
MsgBox "A SpeechLib::ISpRecoContext object will be created"
Const SGDSActive = 1
Set rct = WScript.CreateObject("SAPI.SpInProcRecoContext", "rc_")
Set rgnz = rct.Recognizer
Set rgnz.AudioInputStream = sapiFStream
Set rcGrammar = rct.CreateGrammar
'rcGrammar.DictationLoad
rcGrammar.DictationSetState SGDSActive
i = 0
while scriptRunning and i < 100
WScript.Sleep(50)
i = i + 1
wend
MsgBox "A SpeechLib::ISpRecoContext object has been created"
The magical part of the code is this line (the "rc_" prefix param allows events to be caught by the subs):
Set rct = WScript.CreateObject("SAPI.SpInProcRecoContext", "rc_")
The recorded text in the t.wav file I used for testing has been generated with SAPI.SpVoice::Speak and MS-David voice ;-)
I spent 10 days figuring out how to write this script. Microsoft is removing documentation about automation, COM, old style scripts, etc. A shame.
So, this works in dictation mode reading a wav file. But I couldn't correct it to make it work in live dictation mode (i.e. using the microphone as direct input). Any help appreciated for this. Thanks.
EDIT: direct/live dictation mode solved. If interested I share the vbscript code.
EDIT2: text sample spoken in the wav: Hello world. This is a talk about gear tooth profile using a circle involute.
Console output from the vbscript
C:\SOFT\projects\af2t>cscript r.vbs
Microsoft (R) Windows Script Host Version 5.812
Copyright (C) Microsoft Corporation. Tous droits réservés.
Start: 1 0
Reco: Hello world . 0
Reco: this is a talk about gear to the profile using a circle invalid . 0
End: 1 195040 -1
C:\SOFT\projects\af2t>
Yes. Look at the SAPI Automation Overview; it will tell you all about the late-bound COM interfaces and objects available to VBScript.

I can't get instance of pos printer

I'm working on EPOS pos printer (EPOS TM-T88III). İ stalled it's driver, EPOS ADK and POS for .NET I can get print from my pos printer with PrintDocument function but i want to use EPOS ADK. I try its "Hello OPOS for .NET" sample but it's not work.
Because,
deviceInfo = posExplorer.GetDevice(DeviceType.PosPrinter, strLogicalName)
m_Printer = posExplorer.CreateInstance(deviceInfo)
i can get deviceInfo but, posExplorer.CreateInstance(deviceInfo) returns nothing. Icant solve this problem.
How can i solve this problem to succeed returns something from posExplorer.CreateInstance(deviceInfo) or is there anyway or sample code to use EPOS ADK to print something.
you have to tpyecast it to PosPrinter. that is the correct method.
m_Printer = (PosPrinter)posExplorer.CreateInstance(deviceInfo)
For samples: You will get many sample applications when you install the OPOS for .net ADK for EPSON. You can find those in your installation directory.
Also check your OS version and IDE used, the object initialization for PosPrinter wont happen for some OS and IDEs.

Resources