Turkish Characters in the VBA editor - vba

I have a problem with Turkish characters in my simple VBA code. Whenever I write some text in my module in Turkish characters (e.g. 'ş, ə, ç, ğ, ö, ü, ı"), they change to unknown letters.
I want to change "Eight" to "Səkkiz","Five", "Beş","Three" "Üç" etc.

May be you should change Font in the text editor
Try: Tools > Options at the 2nd tab choose Font Courier New (Turkish)

The VB editor doesn't support Unicode. Assuming that wherever you're displaying these characters does, you can do something like this:
Const UpsideDownE As Long = &H1DD
Sub Example()
' This would set the currently selected text in PowerPoint to ə
ActiveWindow.Selection.ShapeRange.TextFrame.TextRange = ChrW(UpsideDownE)
End Sub
Of course, choose names for the constants that make sense to you ... whatever you'd normally call the ə character.

Related

How to insert Greek characters in MS-Access

Is there any way to insert greek letters into my database or reports in ms-access?
I don't want to change whole database font and I can't find "insert symbols" like excel and word for this purpose.
As this is a programming forum, I assume you are using vba, so...
When I create a new form in Access, the default font is Calibri.
That unicode capbable font supports Greek characters.
To get a capital Greek letter Delta, in your code, put
txtControl = ChrW(916)
The ChrW() function inserts unicode characters into your text.
Change the number to get different letters.
Lower case letters start at 945.
I suspect that if you set your keyboard to Greek, it will allow you to just type in there...

How can I change the font size of non-English words?

In a Word 2007 document, I manually select a sentence containing both English and Bengali words of multiple font sizes. When I enter some numeric value in the Font size list-box in the panel and press Enter, the whole sentence font size is changed (including Bengali words).
When I select the same sentence in a Word-VBA macro and in final line try
Selection.font.Size = 8
only English words' font size gets changed.
I tried to loop through each character, but I got the same result.
I need to stick to Word-VBA as it is part of a web scraping program using Chrome web-driver Selenium.
I tried a simple macro in a manually-created Word document with manually typed mixed English and Bengali words with the Vrinda (Body CS) font and the result was the same. The whole sentence is selected, but only English words' fonts get changed.
Sample Text "I am Ok You are Ok আমিও ঠিক তুমিও ঠিক Is it ok"
Word differentiates between text formatted as left-to-right (LTR) and text formatted as right-to-left (RTL). I'm not familiar with written (or spoken) Bengali, but Word apparently considers it to be RTL. In the object model (VBA) there's a separate set of Font properties for RTL - the suffix Bi is added to the property name. So
Selection.Font.Size = 8
Selection.Font.SizeBi = 8
Should take care of both languages.

Dsplaying unicode in a Form

After much trial and error ,and with assistance from the community, the ability to use Unicode in a form has not been very successful. So the question is. Is there a method to have the ability to use Unicode within a form ? primarily in textbox control were a currency symbol like the Peso symbol(₱) will appear in a textbox. there are various ways to have it on a worksheet but in a form is an allusive task.
After much trial and error ,and with assistance from the community, the ability to use Unicode in a form has not been very successful.
Says who? :)
Private Sub UserForm_Initialize()
TextBox1.Text = ChrW(8369)
End Sub
And welcome to stackoverflow :)
Among other methods, you could:
copy & paste Unicode into a textbox, or,
or use ChrW to use a specific character like this:
UserForm1.TextBox1 = ChrW(8369) 'puts a ₱ in the text box.
Note that in most cases the VBA Editor (VBE) won't display Unicode (so copy/pasting the above code into your VBE will replace the ₱ with a ?).
By the way CodePoints is a handy site for finding/identifying unicode symbols. Type whatever you're looking for in the search bar, or copy & paste from a website to find out more.
Also, note that all symbols that appear on your system may or or may not render properly on others.

how to retrieve word by word from richtextbox in vb.net

I am trying to create a programming editor using a rich text box in vb.net. It should change
the color of text according to that text. For example, the keywords should be displayed in red, and numbers in blue. I can't find how to retrieve word by word from a rich text box .
You can use regular expressions to find the words, and another one for numbers.
Try this website that well help you create your desired regular expressions http://regexpal.com/
I would just take the rich textbox text field and do a string split by space.
If you don't have to roll-your-own, the editors from SharpDevelop are easily extendable.
SharpDevelop3 uses SharpTextEditor(WinForms).
SharpDevelop4 uses AvalonEdit (WPF)
I would do the following:
Dim txt as String = RichTextBox1.Text
Dim arr as String() = txt.Split(" "c) REM split along the whitespace character
For Each i In arr
If IsNumeric(i) Then
REM change the color of the number to blue
Next i

How to represent Unicode character in VB.Net String literal?

I know you can put Unicode character codes in a VB.Net string like this:
str = Chr(&H0030) & "More text"
I would like to know how I can put the char code right into the string literal so I can use Unicode symbols from the designer view.
Is this even possible?
Use the ChrW() function to return Unicode characters.
Dim strW As String
strW = ChrW(&H25B2) & "More text"
The C# language supports this with escapes:
var str = "\u0030More text";
But that isn't available in VB.NET. Beware that you almost certainly don't want to use Chr(), that is meant for legacy code that works with the default code page. You'll want ChrW() and pass the Unicode codepoint.
Your specific example is not a problem, &H0030 is the code for "0" so you can simply put it directly in the string literal.
Dim str As String = "0MoreText"
You can use the Charmap.exe utility to copy and paste glyphs that don't have an easy ASCII code.
Replace Chr with Convert.ToChar:
str = Convert.ToChar(&H0030) & "More text"
To display an Unicode character, you can use following statement
ChrW(n) where n is the number representing de Unicode character.
Convert.ToChar(n)
type directly character in editor using Alt + N key combination
paste/copy Unicode character directly in editor
Char.ConvertFromUtf32(n)
XML String using &#x....; syntax
Example to assign ♥ character :
s = ChrW(&H2665)
s = Convert.ToChar(&H2665)
s = "♥" 'in typing Alt+2665
s = "♥" 'using paste/copy of ♥ from another location
s = Char.ConvertFromUtf32(&H2665)
s = <text>I ♥ you</text>
BUT when Unicode Character is greater than 0xFFFF (C syntax is more readable 😉), only method 4, 5 and 6 are working !
ChrW() function indicates an error at build
Convert.ToChar() function crashes at runtime
Alt+N is refused because it accepts only 4 digits
Example
lblCharacter.Text = "This solution works 😉"
Debug.Print (Char.ConvertFromUtf32(&H1F600))
s = <text>diable: 😈</text>
PS: smiley pasted (0x1F600) directly in Visual Studio code editor or Notepad++ have lost background color ! Explanation: the smiley pasted in this answer is filled by orange color but in Visual Studio editor or Notepad++, this color has disappeared !
To use String literals in Visual Studio Editor, you must use method 3 or 4 !
In Form (Design mode)
In Properties (see Text property)
I was hoping you could use XML literals and XML escapes but it doesn't work. I don't think XML literals allow you to use &#NN;. Although it is a way of including quotes " inside strings.
'Does not compile :('
Dim myString = _
<q>This string would contain an escaped character  if it actually compiled.</q>.Value
I use the Character Map utility (charmap.exe). Run and select the characters you want in the control's font, such as ©Missico™, copy then paste into the Text property in the property grid. You will have to change the font because the default font for a form is "Microsoft Sans Serif" which is not a Unicode font. I do not think you can use this method for non-printable characters.
Depending on your needs, you can also use Localization, which creates resource files for each language. Again, you would use charmap.exe to select and copy the characters needed and paste them into the resource file. You probably can use non-printable characters, such as tabs, newline, and so on, since this is just a text file (Unicode).
No, it's not possible since VB strings don't support escape sequences. Simply use ChrW, which is a few characters more to type, but also a bit cleaner.