I'm trying to create a Backgammon game board using Unicode graphics with an array back-end. For example; White Draughts Man: U+26C0 to represent checkers on a slot. What do I need to do to make this work ?
I've tried using ChrW() with the Unicode that is given from a Unicode table elsewhere
PS: This code is from a test application before adding to my actual assignment.
I just receive an error.
Sub Main()
Console.OutputEncoding = System.Text.Encoding.Unicode
Console.WriteLine(ChrW(&H26C0))
Console.ReadKey()
End Sub
I have reduced my problem to the following code example. I am using a German Excel version in which separators in normal Excel formulas are semicolons ";" instead of "," (e.g. =SUMME(A1;A3) instead of =SUM(A1,A3)).
Now the code which works different from time to time:
Sub CommasDoNotWorkAnymore()
Dim a()
Dim i%
a = Array("A1,A3,A5", "B1", "B2")
i = 0
Debug.Print Sheets(1).Range(a(i)).Address
End Sub
Normally, when starting Excel, this code works. But sometimes Excel seem to switch the accepted separators used in the Range() to semicolons untill I restart Excel. This occurs most times when rerunning the code after a runtime error.
Is this a general Excel bug? Does anybody know what is behind this behaviour? Is there some Excel-wide "local option" for the Range class?
EDIT: I just tried to convert the a(i) with CStr(a(i) but this does also not work. So no ByRef kind of problem...
If you want to control it, check first what separator is currently in use. What I guess is that you want to know the list separator:
Application.International(xlListSeparator)
Check other separators here:
https://msdn.microsoft.com/en-us/vba/excel-vba/articles/application-international-property-excel
The other time I had a problem with identifying decimal separator in VBA. Finnally I was able to get it in this way:
Function GetVBAdecimalSep()
Dim a(0) As Variant
a(0) = 1 / 2
GetVBAdecimalSep = Mid(a(0), 2, 1)
End Function
Changing separator not always works. Please see this: Changing decimal separator in VBA (not only in Excel)
The best solution is to check/change locale, even temporary.
Application.LanguageSettings.LanguageID(msoLanguageIDUI)
gives the LCID which would be 1033 for English (US)
Today I opened a visual basic project which has several lines that declare some strings, which contain comma separated data. I amended one of the strings, rebuilt and closed the project. When I came to test it, there was an error. When I looked at the code, I discovered that the strings on lines after the one I had amended had also changed - they had spaces inserted after the commas.
Has anyone seen normal strings incorrectly having formatting applied by the IDE in visual studio 2015?
It seems like the string is being formatted as if it were code. I would suspect this has something to do with String Interpolation, though these are legacy projects that do not use it.
Edit, FWIW the code is similar to this, I've renamed the fields and headings to try keep it short.
fullColumnMappingsBuilder.Append(",field1,field2,field3,field4,field5,field6,field7,field8,field9,field10")
fullColumnHeadingsBuilder.Append(",heading1,heading2,heading3,heading4,heading5,heading6,heading7,heading8,heading9,heading10")
If clientCode = "ML" Then
fullColumnMappingsBuilder.Append(",mlField")
fullColumnHeadingsBuilder.Append(",mlHeading")
End If
defaultColumnMappingsBuilder.Append(",morefields1,morefields2,morefields3,morefields4")
defaultColumnHeadingsBuilder.Append(",moreHeadings1,moreHeadings2,moreHeadings3,moreHeadings4")
My edit was to simply add in field11 and heading11, and save. But the code ended up looking like this:
fullColumnMappingsBuilder.Append(",field1,field2,field3,field4,field5,field6,field7,field8,field9,field10,field11")
fullColumnHeadingsBuilder.Append(",heading1,heading2,heading3,heading4,heading5,heading6,heading7,heading8,heading9,heading10,heading11")
If clientCode = "ML" Then
fullColumnMappingsBuilder.Append(", mlField")
fullColumnHeadingsBuilder.Append(", mlHeading")
End If
defaultColumnMappingsBuilder.Append(", morefields1, morefields2, morefields3, morefields4")
defaultColumnHeadingsBuilder.Append(", moreHeadings1, moreHeadings2, moreHeadings3, moreHeadings4")
The problem is that the IDE has inserted spaces after the commas on lines that I did not edit.
Well, I think I know how I did it. If you start with something like this:
Public Class Class1
Sub New()
Dim string1 As String = "Hello there world asdfj asldfkja sad "
Dim string2 As String = "some code like words dim private as object sub"
End Sub
End Class
I think I must have taken the first double quotes character off the declaration of string1, and then moved the position of the text cursor to a different line. In previous versions of visual studio, the IDE would have marked the first line as being in error.
Now we have multi-line strings, it thinks you have a multi-line string running from the quotes at the end of the first line up to string2 As String", and that the following text is code, and so it gets changed (in this case the keywords are capitalized).
Dim string2 As String = "some code Like words Dim Private As Object Sub"
I'll just have to be more careful when editing strings.
Might not have been your fault.
I've seen VS 2015 automatically make changes very similar to the above example:
Dim string2 As String = "some code like words dim private as object sub"
... changing to:
Dim string2 As String = "some code Like words Dim Private As Object Sub"
This was on both multi-line and single-line strings, in procedures I had not touched at all, in a .vb file where I was changing strings in other procedures. Only reason I caught VS doing this was because I did a Compare before check-in.
In Visual Studio formatting Strings as VB.NET code it suggests un-checking Tools > Options > Text Editor > Basic > Advanced > Pretty listing (reformatting) of code, but am reluctant to turn off all the good things that does.
Feels like a bug in VS 2015 to me. Have never seen this in 16 years of using prior versions of VS, before 2015.
I have a VB method
Public Sub append_text(ByVal s As String)
f1.TextBox1.AppendText(s)
End Sub
which is called over COM from C++
_bstr_t b(L"test\nnew\nlines\n");
ATLENSURE_SUCCEEDED(t->append_text(b));
But the text box ends up saying
testnewlines
Without the aforementioned new lines.
Why is that then?
For the sake of completeness, posting my comment as an answer (now that I know it's correct...):
Different operating systems consider different character combinations as new lines. The *nixes, for instance, use a single \n, as in your code. Windows, on the other hand, uses the \r\n combination. Therefore, the single \n in your string just isn't enough to be considered a new line marker. Using \r\n will do the trick.
Eran is right.
To fix it on the VB side, try this
Dim s2 As String = s.Replace(vbLf, vbCrLf)
f1.TextBox1.AppendText(s2)
EDIT Sideshow Bob has compiled and tested this.
Is there any way to align text into the center in msgbox in VB or VBA? Does VB have any functionality to do the same?
No. The MsgBox() function is simply a wrapper for the Windows MessageBox() function and as such has no stylistic control over the dialog beyond the icon.
If you want to change it any further than this, you will need to create your own window and show that instead.
On Windows Vista+ you can use TaskDialogs that allow a lot more control.
no, but you can cheat by using spaces.
msgbox(" your message")
VBA
Some notes: http://access.mvps.org/access/bugs/bugs0035.htm AND http://www.tek-tips.com/viewthread.cfm?qid=435428 However, it is not so difficult to build your own message box, which solves all your problems.
When you are building your strings you could pad them at the beginning and end with spaces to achieve a target length. If you're using excel the worksheet function rept is handy for this.
function pad_n_center(byval mystring as string, lenmax as integer) as string
dim pad_by as integer
dim pad as string
pad_by = (lenmax - len(mystring))/2
'some more code to finesse that?
pad = worksheetfunction.rept(" ",pad_by)
pad_n_center = pad & mystring & pad
end function
As mentioned before if the msgbox still doesn't look good you can use textbox shape object (or other objects) to get the desired effect.