I receive excel files in a specified folder for inventory upload. When these upload my system is throwing an error of invalid InventoryId. The last row of data comes with an arrow character that when copied and pasted shows a blank space.
Does anyone know what this right arrow character is?
It is not HTML, ASCII, or Unicode.
I need to create a validation on that character not to bring the row if this is present.
You could do something like the following to remove the Unicode characters.
Dim Str As String = "My Stȟring of ChaǕracters"
Str = System.Text.RegularExpressions.Regex.Replace(Str, "[^\u0000-\u007F]", "")
or if you wanted to identify Strings then do something
Dim Str As String = "My String of Characters"
Dim UniCodeCollection As System.Text.RegularExpressions.MatchCollection = System.Text.RegularExpressions.Regex.Matches(Str, "[^\u0000-\u007F]")
If UniCodeCollection.Count > 0 Then
'Add code to do somthing here
End If
As the right-arrow character has been passed via a string, it must be a Unicode character.
If the program into which you paste the suspect character is not capable of displaying it, e.g. it is using a font without a visible representation of it, then it may well appear as a blank.
You need to track down what the code is for the character.
The character will probably be able to be shown in Visual Studio, so copy-and-paste the offending string in place of "Crème brûlée →" in the following code and examine the output for anything which stands out:
Module Module1
Sub Main()
Dim s = "Crème brûlée →"
For i = 0 To s.Length - 1
Console.WriteLine(AscW(s(i)))
Next
Console.ReadLine()
End Sub
End Module
Outputs:
67
114
232
109
101
32
98
114
251
108
233
101
32
8594
In the above, 8594 (which is &H2192) stands out as being very different. You now just need to check if s.IndexOf(ChrW(8594)) >= 0, which indicates that the character is in the string.
Solved the issue!
What I did was find what the Character was using the following code:
AscW(CurrentRecord(0).ToString) = Variable
Once I found what the character was I used the same line in an if statement to solve the issue. See Below.
If Not AscW(CurrentRecord(0).ToString) = "26" Then
If Not CurrentRecord(0).ToString = "InventoryId" Then
NewRow("InventoryId") = CurrentRecord(0)
NewRow("Quantity") = CurrentRecord(1)
NewRow("CostCentre") = CurrentRecord(2)
NewRow("UsageDate") = CurrentRecord(3)
InventoryLoad.Tables(0).Rows.Add(NewRow)
NewRow = InventoryLoad.Tables("Load").NewRow
End If
ElseIf AscW(CurrentRecord(0).ToString) = "26" Then
Else
CommonFunctions.ErrorEmail("ProductId " & CurrentRecord(0).ToString & " was not recognized", "LoadInventory - ProductId")
End If
Related
Just look at this one line code
jobject.parse("{""volume"": 5074364.34541878}").item("volume").tostring
The result is 5074364,34541878
That is with . instead of comma. How can that be? This has caused lots of bugs.
The value of
Threading.Thread.CurrentThread.CurrentUICulture.NumberFormat.CurrencyDecimalSeparator
is "."
Recently I found something weird in my computer.
For some reasons many dots becomes comma. For some reasons, some program like firefox think that the decimal separator is comma instead of dot.
That is even though my international settings is set to US (I am actually in Indonesia).
Then the program I created (that should have been independent of this) start behaving erratically.
For example, look at this code
Dim valueInString = grabform.Item(frontstr).ToString
The value of grabform.toString is
{
"key": "tTRXUSD",
"bid": 0.060322,
"ask": 0.060323,
"last": 0.060289,
"volume": 5074364.34541878,
"high": 0.061143,
"low": 0.060192,
"base123": "USD",
"quote123": "TRX"
}
The type of grabform is JObject
in this function
Private Shared Function grabValueOfActualQuote(grabform As JObject, frontstr As String) As Decimal
Dim valueInString = grabform.Item(frontstr).ToString
If valueInString = "" Then
Return 0D
End If
If valueInString.Length > 15 Then
Dim b = 1
End If
Dim left1 = Strings.Left(valueInString, 20)
Dim output = Decimal.Parse(left1, System.Globalization.NumberStyles.Any)
Return output
End Function
Now the result of valueInstring is 5074364,34541878 (notice the comma)
How can that be?
The value of
It seems that somehow there is a hidden settings in my computer that makes my computer think that the decimal mark is comma instead of dot. Obviously my program should have used dot irrelevant of computer settings. Not to mention I know where the setting is.
Newtonsoft.Json.Linq. shouldn't change behavior no matter what international setting is.
What should I do?
Look at this piece of code:
using System.Globalization;
var xyz = 5074364.34541878;
Console.WriteLine($"Current culture: {CultureInfo.CurrentCulture.Name}");
Console.WriteLine(xyz);
// https://stackoverflow.com/a/5263650/724039
Thread.CurrentThread.CurrentUICulture = new CultureInfo("en-US");
Thread.CurrentThread.CurrentCulture = Thread.CurrentThread.CurrentUICulture;
Thread.CurrentThread.CurrentUICulture.NumberFormat.CurrencyGroupSeparator = "A";
Thread.CurrentThread.CurrentUICulture.NumberFormat.CurrencyDecimalSeparator = "B";
Thread.CurrentThread.CurrentUICulture.NumberFormat.NumberDecimalSeparator = "C";
Thread.CurrentThread.CurrentUICulture.NumberFormat.NumberGroupSeparator = "D";
Console.WriteLine(xyz.GetType().ToString());
Console.WriteLine(xyz);
Console.WriteLine("Change NumberDecimalSeparator to '.'");
Thread.CurrentThread.CurrentUICulture.NumberFormat.NumberDecimalSeparator = ".";
Console.WriteLine(xyz);
It's output is:
Current culture: nl-NL
5074364,34541878
System.Double
5074364C34541878
Change NumberDecimalSeparator to '.'
5074364.34541878
Conclusion: The value that you read from JSON is a System.Double, and C# applies the NumberDecimalSeparator when using this variable.
Trying to attempt the following in MS Access.
Convert data in one field to an 18 digit number starting with 01 in another field.
There are also some conditions that have to be met:
the first dash should become double zeros
the second dash should be removed
the third and fourth dash should be a single zero
the decimal must also be replaced with a zero
My query works fine until the decimal is the 15th character in the data.
Here is the query:
SELECT MasterVacant.ParcelIdNumber,
"01" + Mid([ParcelIdNumber],1,2) + "00" + Mid([ParcelIdNumber],4,2) + Mid([ParcelIdNumber],7,1)
+ IIf(Mid([ParcelIDNumber],11,1) = "", "0"+Mid([ParcelIDNumber],9,2), Mid([ParcelIDNumber],9,3))
+ IIf(Mid([ParcelIDNumber],14,1) = ".", "0"+Mid([ParcelIDNumber],12,2), Mid([ParcelIDNumber],12,3))
+ Mid([ParcelIDNumber],15,3) AS ParcelNumber
FROM MasterVacant;
Here is a start and finish example...
'12-06-1-00-50.000-RR' should become '011200061000050000'
'12-06-3-07-09.000-RR' should become '011200063007009000'
'13-35-1-01-129.000-RR' should become '011300035100112900'
However, instead of getting `0113000351001129000' I get '013000351001129.00'.
The issue is how do I remove the decimal when the decimal is the 15th character like in the third set of example?
I receive the data as a single column. Some of it is below....
1. 13-35-1-07-29.000-RR
2. 13-35-1-01-112.000-RR (Removing the decimal when the data is like this is the issue)
3. 13-35-4-01-01.000-RR
4. 13-35-4-02-04.000-RR
5. 13-35-1-13-17.000-RR
The output for the above data should be
1. 011300351007029000
2. 011300351001112000
3. 011300354001001000
4. 011300354002004000
5. 011300351013017000
Use a custom function:
Public Function Make18(ByVal Value As String) As String
Const Head As String = "01"
Const Tail As String = "000"
Const Lead As String = "00"
Dim Parts As Variant
Dim Part As Integer
Dim Result As String
Parts = Split(Split(Value, ".")(0), "-")
For Part = LBound(Parts) To UBound(Parts)
Select Case Part
Case 0
Parts(Part) = Head & Parts(Part)
Case 1
Parts(Part) = Lead & Parts(Part)
Case 3, 4
Parts(Part) = Right(Lead & Parts(Part), 3)
End Select
Next
Result = Join(Parts, "") & Tail
Make18 = Result
End Function
and your query becomes:
SELECT
MasterVacant.ParcelIdNumber,
Make18([ParcelIdNumber]) AS ParcelNumber
FROM
MasterVacant;
I am assuming you meant the opposite where:
12-06-1-00-50.000-RR should become 011200061000050000
12-06-3-07-09.000-RR should become 011200063007009000
13-35-1-01-129.000-RR should become 0113000351001129.00
I would recommend the REPLACE() in MSACCESS to strip the dashes out. Once you have the dashes out you can MID()
Unfortunately your attempted code does something different with the 3rd row because 3 zeros are being put in when there should be only two in my opinion.
Try in a text box:
=Replace("13-35-1-01-129.000-RR","-","")
will return 1335101129.000RR
and see if that assists you in making your code.
Maybe go one step further and put it in a function.
I am using the FreeTextBox.dll to get user input, and storing that information in HTML format in the database. A samle of the user's input is the below:
133 Peachtree St NE Atlanta, GA 30303 404-652-7777 Cindy Cooley www.somecompany.com Product Stewardship Mgr 9/9/2011Deidre's Company123 Test StAtlanta, GA 30303Test test.
I want the HTMLWorker to perserve the white spaces the users enters, but it strips it out. Is there a way to perserve the user's white space? Below is an example of how I am creating my PDF document.
Public Shared Sub CreatePreviewPDF(ByVal vsHTML As String, ByVal vsFileName As String)
Dim output As New MemoryStream()
Dim oDocument As New Document(PageSize.LETTER)
Dim writer As PdfWriter = PdfWriter.GetInstance(oDocument, output)
Dim oFont As New Font(Font.FontFamily.TIMES_ROMAN, 8, Font.NORMAL, BaseColor.BLACK)
Using output
Using writer
Using oDocument
oDocument.Open()
Using sr As New StringReader(vsHTML)
Using worker As New html.simpleparser.HTMLWorker(oDocument)
worker.StartDocument()
worker.SetInsidePRE(True)
worker.Parse(sr)
worker.EndDocument()
worker.Close()
oDocument.Close()
End Using
End Using
HttpContext.Current.Response.ContentType = "application/pdf"
HttpContext.Current.Response.AddHeader("Content-Disposition", String.Format("attachment;filename={0}.pdf", vsFileName))
HttpContext.Current.Response.BinaryWrite(output.ToArray())
HttpContext.Current.Response.End()
End Using
End Using
output.Close()
End Using
End Sub
There's a glitch in iText and iTextSharp but you can fix it pretty easily if you don't mind downloading the source and recompiling it. You need to make a change to two files. Any changes I've made are commented inline in the code. Line numbers are based on the 5.1.2.0 code rev 240
The first is in iTextSharp.text.html.HtmlUtilities.cs. Look for the function EliminateWhiteSpace at line 249 and change it to:
public static String EliminateWhiteSpace(String content) {
// multiple spaces are reduced to one,
// newlines are treated as spaces,
// tabs, carriage returns are ignored.
StringBuilder buf = new StringBuilder();
int len = content.Length;
char character;
bool newline = false;
bool space = false;//Detect whether we have written at least one space already
for (int i = 0; i < len; i++) {
switch (character = content[i]) {
case ' ':
if (!newline && !space) {//If we are not at a new line AND ALSO did not just append a space
buf.Append(character);
space = true; //flag that we just wrote a space
}
break;
case '\n':
if (i > 0) {
newline = true;
buf.Append(' ');
}
break;
case '\r':
break;
case '\t':
break;
default:
newline = false;
space = false; //reset flag
buf.Append(character);
break;
}
}
return buf.ToString();
}
The second change is in iTextSharp.text.xml.simpleparser.SimpleXMLParser.cs. In the function Go at line 185 change line 248 to:
if (html /*&& nowhite*/) {//removed the nowhite check from here because that should be handled by the HTML parser later, not the XML parser
Thanks for the help everyone. I was able to find a small work around by doing the following:
vsHTML.Replace(" ", " ").Replace(Chr(9), " ").Replace(Chr(160), " ").Replace(vbCrLf, "<br />")
The actual code does not display properly but, the first replace is replacing white spaces with , Chr(9) with 5 , and Chr(160) with .
I would recommend using wkhtmltopdf instead of iText. wkhtmltopdf will output the html exactly as rendered by webkit (Google Chrome, Safari) instead of iText's conversion. It is just a binary that you can call. That being said, I might check the html to ensure that there are paragraphs and/or line breaks in the user input. They might be stripped out before the conversion.
I have the following radio box:
<input type="radio" value="香">香</input>
As you can see, the value is unicode. It represents the following Chinese character: 香
So far so good.
I have a VBScript that reads the value of that particular radio button and saves it into a variable. When I display the content with a message box, the Chinese Character appears. Additionally I have a variable called uniVal where I assign the unicode of the Chinese character directly:
radioVal = < read value of radio button >
MsgBox radioVal ' yields chinese character
uniVal = "香"
MsgBox uniVal ' yields unicode representation
Is there a possibility to read the radio box value in such a way that the unicode string is preserved and NOT interpreted as the chinese character?
For sure, I could try to recreate the unicode of the character, but the methods I found in VBScript are not working correctly due to VBScripts implicit UTF-16 setting (instead of UTF-8). So the following method does not work correctly for all characters:
Function StringToUnicode(str)
result = ""
For x=1 To Len(str)
result = result & "&#"&ascw(Mid(str, x, 1))&";"
Next
StringToUnicode = result
End Function
Cheers
Chris
I got a solution:
JavaScript is in possession of a function that actually works:
function convert(value) {
var tstr = value;
var bstr = '';
for(i=0; i<tstr.length; i++) {
if(tstr.charCodeAt(i)>127)
{
bstr += '&#' + tstr.charCodeAt(i) + ';';
}
else
{
bstr += tstr.charAt(i);
}
}
return bstr;
}
I call this function from my VBScript... :)
Here is a VBScript function that will always return a positive value for the Unicode code point of a given character:-
Function PositiveUnicode(s)
Dim val : val = AscW(s)
If (val And &h8000) <> 0 Then
PositiveUnicode = (val And &h7FFF) + &h8000&
Else
PositiveUnicode = CLng(val)
End If
End Function
This will save you loading two script engines to acheive a simple operation.
"not working correctly due to VBScripts implicit UTF-16 setting (instead of UTF-8)."
This issue has nothing to do with UTF-8. It is purely the result of AscW use of the signed integer type.
As to why you have to recreate the &#xxxxx; encodings that you sent this is result of how HTML (and XML) work. The use of this character encoding entity is a convnience that the specification does not require to remain intact. Since the character encoding of the document is quite capable or representing that character the DOM is at liberty to convert it.
I've got an old, legacy VB6 application that uses the DHTML editing control as an HTML editor. The Microsoft DHTML editing control, a.k.a. DHTMLEd, is probably nothing more than an IE control using IE's own native editing capability internally.
I'd like to modify the app to implement smart quotes like Word. Specifically, " is replaced with “ or ” and ' is replaced with ‘ or ’ as appropriate as it is typed; and if the user presses Ctrl+Z immediately after the replacement, it goes back to being a straight quote.
Does anyone have code that does that?
If you don't have code for DHTML/VB6, but do have JavaScript code that works in a browser with contentEditable regions, I could use that, too
Here's the VB6 version:
Private Sub DHTMLEdit1_onkeypress()
Dim e As Object
Set e = DHTMLEdit1.DOM.parentWindow.event
'Perform smart-quote replacement'
Select Case e.keyCode
Case 34: 'Double-Quote'
e.keyCode = 0
If IsAtWordEnd Then
InsertDoubleUndo ChrW$(8221), ChrW$(34)
Else
InsertDoubleUndo ChrW$(8220), ChrW$(34)
End If
Case 39: 'Single-Quote'
e.keyCode = 0
If IsAtWordEnd Then
InsertDoubleUndo ChrW$(8217), ChrW$(39)
Else
InsertDoubleUndo ChrW$(8216), ChrW$(39)
End If
End Select
End Sub
Private Function IsLetter(ByVal character As String) As Boolean
IsLetter = UCase$(character) <> LCase$(character)
End Function
Private Sub InsertDoubleUndo(VisibleText As String, HiddenText As String)
Dim selection As Object
Set selection = DHTMLEdit1.DOM.selection.createRange()
selection.Text = HiddenText
selection.moveStart "character", -Len(HiddenText)
selection.Text = VisibleText
End Sub
Private Function IsAtWordEnd() As Boolean
Dim ch As String
ch = PreviousChar
IsAtWordEnd = (ch <> " ") And (ch <> "")
End Function
Private Function PreviousChar() As String
Dim selection As Object
Set selection = m_dom.selection.createRange()
selection.moveStart "character", -1
PreviousChar = selection.Text
End Function
Note: this solution inserts an additional level in the undo chain. For example, typing "This is a test" gives a chain of “This is a test” -> “This is a test" -> “This is a test -> “ -> " (extra level in bold). To remove this extra level you'd have to implement some sort of PostMessage+subclassing solution that doesn't involve cancelling the native keypress
edit: Don't forget to include the DHTML Editing Control redistributable if you are targeting Windows Vista.