I download an exchange rate through an XmlHttp request that gets inside the code as a string (being the .innerText of a <div> element) and represents a double type number: 1.525.
When building this script, I've done it on my OS which has the English culture model (i.e. 1.525 means 1 unit and 0.525 decimals).
However, this script will now run on a French OS which uses the comma , instead of the . to separate decimals.
Which means, the operation Application.Evaluate(10000/myRate) will fail if the . is instead of the ,.
Easy solution would be to replace the "." with a "," via Application.Evaluate(10000/Replace(myRate,".",","). However, this is clearly not nice because now the script would fail on an English system.
With VB.NET I would be able to make it culture-independent by converting it like:
myRate.ToDouble(System.Globalization.CultureInfo.InvariantCulture)
I've tried Googling the VBA alternative for a while without success; does anyone know if there's a more elegant way of internationalize my script than just replacing the "." with a ","?
Here's my current solution (that I don't really like):
On Error Resume Next
test = CDbl(myRate)/2
If Err.Number <> 0 Then
myRate = Replace(myRate,".",",")
On Error GoTo 0
End If
use the Application.DecimalSeparator property?
Application.Evaluate(10000/CDbl(Replace(myRate,".", Application.DecimalSeparator))
You can temporary change decimal and thousands separator, by using Application object.
To read several current OS (International) settings: Application.International(index) property
To change:
Application.ThousandsSeparator = "."
In MS Access, we do not have Application.DecimalSeparator nor Application.ThousandsSeparator nor Application.International. The only thing we have is Val(vString) and Str(vNumber). They both convert the argument using the English (invariant) culture.
So, in MS Access the OP's question could be solved like this:
vResult = 10000/Val(myRate)
Related
My question relates to coding selenium specifically in VBA.
I have a function that finds webelements based on text passed to it (in string variable 'toFind'). The relevent Xpath identification method I use is (where driver. is the selenium chromedriver):
mySearch = "//*[contains(text(),'" & toFind & "')]"
Set ret = driver.FindElementsByXPath(mySearch)
This works unless the toFind variable contains an apostrophe. For example if "Consultant's Forename" is passed then my expression evaluates to:
Set ret = driver.FindElementsByXPath("//*[contains(text(),'Consultant's Forename')]"), which causes an invalid selector run-time error.
I have researched elsewhere on the site and see a number of answers describing escaping from the single quotes using the backslash character. Based on this I have tried to use Set ret = driver.FindElementsByXPath("//*[contains(text(),\"Consultant's Forename\")]") instead. However, this will not compile in microsoft visual basic for applications as it reports a syntax error (code line is red). I have not tried using the driver.findElements(By.xpath method as opposed to driver.FindElementsByXPath as I assumed this would not make a difference to the handling of the XPath expression. I have tried the other suggestions of using the 'concat' function but this also seems not to be valid in VBA selenium.
I don't know if these methods are specficaly for platforms other than VBA or I am just getting my syntax wrong?
The only way I can work it at present is to ignore the existence of the apostrophe:
Set ret = driver.FindElementsByXPath("//*[contains(text(),'Consultant') and contains(text(),'s Forename')]")
Whilst this works it is an incomplete solution and any help on the correct syntax to deal with the xpath location in VBA for text containing an apostrophe would be much appreciated.
I have a calculation which will remove a blank space and replace with a full stop. This is correct for 90% of my cases. However, sometimes two blanks will appear in my value. For the second space I want to delete it. Is this possible?
I think it may be possible using a code stage, but I am not sure what the code would be.
My current calculation is Replace([Item Data.Name], " ", ".")
Example data John B Smith I want the result to be John.BSmith
For anything that'd like to do with the strings, there is a really powerful tool called Regular Expressions (regex). I encourage you to play with it, because it's a really powerful tool in the hands of RPA developer.
To replace the second space in any string with a "." you can use the following action.
Object: Utility - Strings
Action: Regex - Find and Replace
Input:
Regex Pattern: "(?<= .*) "
Text: "John B Smith"
Replacement: "."
The above action is not a standard Blueprism one, so it has to be added to your VBO. The action looks as follows:
The VB.net code for that action is as follows:
Dim R as New Regex(Regex_Pattern, RegexOptions.SingleLine)
Dim M as Match = R.Match(Text)
replacement_result = R.Replace(Text,Regex_Pattern,replacement_string)
There might be a need for some additional assemblies, so please see below a printscreen of references and namespaces used in my object:
I resolved this issue by using the Utility - Strings object and the split text action. I split my name by space. This outputted a collection which I was then able to loop through and add a full stop after the fist instance but then trim the other instances.
Please see screenshot
I think the simplest solution would be
Replace(Replace(Text," "," ")" ","."))
if you know that it will give one or two spaces
First replace the two white spaces to single and then again single white space to dot(.)
My delay codes are always 3 digits. Two letters a dash (-) and a number. I am trying to use a single line of code to detect either MT or DA, the actual classification number is irrelevant, so I want the message box to fire on the two letters only.
The code looks right, but it doesn't fire as it should. If I take out the wild card it works. I think I have a problem with the concatenation, but I'm not sure. I tried putting () brackets around it but that was not help.
Additionally I tried using an or statement to capture the MT code on the other side but got nothing but an error code for type mismatch. Any ideas?
If Range("L24").Value = "DA" & "*" Then
MsgBox "The flight had a Maintenance delay"
Else
End If
A simple solution to this kind of problem would be to ignore the wildcard altogether and check the first two digits:
If Left(Range("L24").Value, 2) = "DA" Then
Running Coldfusion 8, I am trying to clean text input before saving to a database that will take things like the MS equivalent of ' " - and accented letters, and converting them.
I have tried replace, REReplace, and various UDFs found on the internet. None seem to work. In fact, I tried this:
<cfscript>
function cleanString(string) {
var newString = string;
newString = replace("'", "'", ALL);
return newString;
}
</cfscript>
The single quote to be replaced above is a MS Word style single quote. Coldfusion threw an error, the error scope said invalid syntax and the single quote in the error scope was a square. If I change it to the chr() form, and replace with ', I get a blank. If I do chr() to the entity, I get a blank.
I am more than certain I have jumped this hurdle before, and not sure why nothing is working now. Is there a new setting in CF8 vs CF7 regarding character encoding that I am missing?
There is a great script for demoronizing (yes, that's a technical term) text copied from MS word and the like. It can be found at CFLib:
http://cflib.org/index.cfm?event=page.udfbyid&udfid=725
I've used it several times, and been happy with it out-of-the-box (though I have added some additions for specific applications).
What, if anything, is the benefit of using
If StrComp(strVal1, strVal2, vbTextCompare) = 0 Then
as opposed to using
If strVal1 = strVal2 Then
If Option Compare Text is set at the module level, is there any difference?
I know StrComp handles null scenarios and <> scenarios, I am only interested in the situation where strVal1 and strVal2 have non-null valid strings assigned.
If Option Compare Text is set at the module level, is there any difference?
No. It simply offers a finer grained control (no module-level strategy commitments). However, if you can make such a commitment, go for the x = y option: less code is always better code.
Since StrComp is comparing string (with cultural info), UpperCase and LowerCase are not taking care ... (so Hello is the same as hello). In the case of =, there will be different (Like using a Binary compare).
If option compare text is at module level, there will be no difference (but you should use StrComp in case another guy delete it)...