Classic ASP language (monthname for chinese) - vbscript

Have been struggling to find a solution for this.
I am looking for monthname to return the chinese version of January (or spanish etc.). At the moment it is returning english.
The site is installed on an english windows machine.
I have tried adding session.lcid as well as: <%#LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>
but I keep getting the english version of the month name (and to change each occurrence is a major code change). Also I need to try and keep the date format as per what I have as changing that might be an issue as well.
Can anyone recommend an answer? Much appreciated.

You need the SetLocale function and the locale identifier of the language.
Sample test vbs script
Option Explicit
Dim language, outputString
For Each language In Array( "es-es", "en-us", "zh" )
SetLocale language
outputString = outputString & MonthName( 2 ) & vbCrLf
Next
WScript.Echo outputString
Output

Related

CStr() vs Str()

I have to modify some old VB6 code, but I've been using VB.Net for so long I have forgotten some of the subtleties, and documentation is getting harder to find.
In Vb.Net CStr() takes into account international settings and uses commas instead of dots for people with foreign language settings whereas Str() always uses English conventions. I can't remember though if this was the same in VB6.
OK, tested it by changing my locale settings, and the following code..
Yes it seems that CSTR() is locale aware, and STR() isnt..
Private Sub Form_Load()
Dim X As String
Dim Z As Currency
Z = 456789.12
X = CStr(Z) 'with locale settings of sep='.' and dec=',' prints 456789,12
'X = Str(Z) 'with locale settings of sep='.' and dec=',' prints 456789.12
Me.Caption = X
End Sub

Export validation rules from Microsoft Access mdb file

I have an MDB file which contains a number of tables and forms. Each field has a validation rule such as Is Null Or >=0 And <=255.
This access database is being converted into an online system using MySQL. Exporting all the data is easy using MDBTools (https://github.com/brianb/mdbtools).
However I can't find any way of exporting the validation rules. There are thousands of fields across over 100 tables so it's going to be important to export and import them rather than rewrite each one.
I don't really mind what format they're exported in, any sort of text format so I could do a regular expression or something will be fine.
However I haven't been able to find any information anywhere on exporting these validation rules.
Perhaps if it's not built into access by default then a VB script could be used to find the info and write it to a text file? I'm not really familiar with access or windows at all so if anyone could suggest if that was a possibility that would be great.
Using VBA allows you to retrieve field validation rules directly.
I realize it's probably too late to help you now. And, although it may not seem appropriate for someone unfamiliar with Access and VBA, this approach requires only a table, copying the code below into a standard module, and running it. So someone else may benefit.
I created my table, field_validation_rules, to store the text of the validation rule properties. The table includes 3 text fields: table_name; field_name; and validation_rule.
Public Sub GatherValidationRules()
Dim db As DAO.Database
Dim fld As DAO.Field
Dim rs As DAO.Recordset
Dim tdf As DAO.TableDef
Set db = CurrentDb
Set rs = db.OpenRecordset("field_validation_rules", dbOpenTable, dbAppendOnly)
For Each tdf In db.TableDefs
If Not (tdf.Name Like "~*" Or tdf.Name Like "MSys*") Then
For Each fld In tdf.Fields
If Len(fld.ValidationRule) > 0 Then
rs.AddNew
rs!table_name.Value = tdf.Name
rs!field_name.Value = fld.Name
rs!validation_rule.Value = fld.ValidationRule
rs.Update
End If
Next
End If
Next
rs.Close
End Sub
The ValidationRule property is a string value. If the property has not been assigned for a given field, ValidationRule is an empty string. The code skips those, storing only validation rules for fields which have them assigned.
If you want the collected validation rules in a text file, there a several options. I dumped mine to CSV like this:
DoCmd.TransferText acExportDelim, , "field_validation_rules", "C:\share\Access\field_validation_rules.txt", False
To anyone else finding this, this is how I wound up doing it. This was in Access 2003, it may be different in other versions.
First I went to Tools > Analyze > Documenter selected the table I wanted and used these settings:
I was then presented with what looked like a pdf or word doc (I don't think it is, but it doesn't really matter).
I then did File > Export and selected "Text Files .txt" and saved it to a location on my computer.
I then opened the .txt file in PHP (anywhere you can do regular expressions should be fine).
In my instance not every single field had validation rules and the validation rules did not appear if they were not set, which meant a regular expression to fetch the fieldID had more results than to fetch the validation rules.
So I used two regular expressions.
/SourceField:\s+(\S+).*?AllowZeroLength/msi
This gets everything betwenen SourceField and AllowZeroLength. AllowZeroLength is the first bit of repeating text after the validation rules.
I then used this regular expression to get the validation rules from within that string.
/ValidationRule:\s+(.*)\\r/
I had to use \r instead of new line, probably something to do with moving it from Windows to Ubuntu.
In PHP it looked like this:
<?php
$file_contents = file_get_contents('validations.txt');
$response = [];
preg_match_all('/SourceField:\s+(\S+).*?AllowZeroLength/msi', $file_contents, $matches);
for($i = 0; $i < count($matches[0]); $i++) {
$id = $matches[1][$i];
preg_match('/ValidationRule:\s+(.*)\\r/', $matches[0][$i], $validation_match);
$response[$id] = $validation_match[1] ?? null;
}
There is almost certainly a cleaner regular expression than this, but this was incredibly quick and I got exactly what I wanted.

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.

VBS objFile.DateLastModified and Date Format Settings

I'm trying to do some date modify check for a file in my VBS script. But it looks like comparison operation depend on date format which set on machine where script is runnnig. I have diverse machines where Regioanal & date settings could be Russian, English US, English UK and I need to run my VBS against all machines and being able to compare date correctly.
When I'm trying to use
If objFile.DateLastModified = cdate("19.10.2012 11:34:06") then
do something
Else do something else
End IF
It seemingly works and doing correct comparison on machine with Russian formats setting, but fails on machine with English UK formats setting with following error
Type mismatch: 'cdate'
800A000D
If I use following DateSerial(2012,10,19) it doesn't throw an error but fail to compare dates correctly.
What is the best and easiest way to compare file modify date against predifined value with VBS irrespectively of machine date format setting?
Long story short: Don't use localized date formats when parsing dates.
ISO 8601 format works just fine:
If objFile.DateLastModified = CDate("2012-10-19 11:34:06") Then
' do something
Else
' do something else
End If
If you must, you can use the SetLocale() function explicitly to make your script run under different environments:
SetLocale 1049 ' LCID "Russian"
MsgBox CDate("5.4.2013 15:00:00") ' April 5, shown as 05.04.2013 15:00:00
SetLocale 1033 ' LCID "English - United States"
MsgBox CDate("5.4.2013 15:00:00") ' Type mismatch error
Refer to the list of assigned LCIDs on the MSDN.
Use
objFile.DateLastModified = DateSerial(2012,10,19) + TimeSerial(11,34,06)
Use a Date literal (format #mm/dd/yyyy h:mm:ss AM/PM#, locale-independent):
objFile.DateLastModified = #10/19/2012 11:34:06 AM#
Use what xkcd tells you.
objFile.DateLastModified = CDate("2012-10-19 11:34:06")

how to get email address from messages in outlook 2003

Sub GetALLEmailAddresses()
Dim objFolder As Folders
Set objFolder = Application.ActiveExplorer.Selection
Dim dic As New Dictionary
Dim strEmail As String
Dim strEmails As String
Dim objItem As MailItem
For Each objItem In objFolder.Items
strEmail = objItem.SenderEmailAddress
If Not dic.Exists(strEmail) Then
strEmails = strEmails + strEmail + ";"
dic.Add strEmail, ""
End If
Next
Debug.Print strEmails
End Sub
I use this code to get email address from message body. I'm not prefect in vb. is there any to help how to get email address from messages in outlook 2003?
In that case, I don't think there's anything built in, so I'd suggest that you don't bother with the SenderEmailAddress but instead just get out the Body and then search the text for email addresses. This will get somewhat complicated though since it might be difficult to be able to tell what's part of an email address and what isn't.
The easiest place to start with is to just look for any # in the text, and then search for the next whitespace on either side of the # and get everything between those whitespaces. But there are a lot of issues to think about. What if the user typed # for some other reason, or if the email contains something like The first email is xxx#test.com.The second email is xxx2#test.com (note the missing space between the . and the The), where your app might think that the email should be xxx#test.com.The.
Edited since my answer was based on a complete misunderstanding of the question.

Resources