Posts Tagged ‘VB express 2005’
How to scroll a textbox programatically as data is added
This should be easy, but after some experimentation it appears at least this sequence is required:
textbox1.Text = textbox1.Text & sLine & Environment.NewLine ‘ Add the data
textbox1.Focus() ‘ claim the focus
textbox1.SelectionStart = Len(textbox1.Text) – 1 ‘ set the Caret
textbox1.ScrollToCaret() ‘ move the view of the text box
textbox1.Refresh() ‘ display the view of the textbox.
This works while the application itself has focus.
Function optional variable as integer = nothing defaults to zero
The following code does not work because the value of ‘places’ is zero not nothing
Sub Main()
Dim a As Double = 1.034567
Dim b As Double = 1.434588
If DeciUnEq(a, b) Then
Console.WriteLine(“a:” & a.ToString & ” NOT EQUALS b:” & b.ToString & ” to five decimal places”)
Else
Console.WriteLine(“a:” & a.ToString & ” IS EQUAL b:” & b.ToString & ” to five decimal places”)
End If
a = b
Console.WriteLine(“Complete, press return to exit”)
Console.ReadLine()
End Sub
Public Function DeciUnEq(ByVal Vala As Double, ByVal Valb As Double, Optional ByVal places As Integer = Nothing) As Boolean
‘ Check numbers for inEquality at the specified precision level
‘ This is either passed to the routine or taken from a public variable Precision, or defaulted to 5.
If IsNothing(places) Then
places = 5
End If
If Math.Round(Vala, places) Math.Round(Valb, places) Then Return True
Return False ‘ They are equal!
End Function
My.User.Name returns an empty string
I’m not sure when or why this happened. It MAY be related to this application being a console application.
The alternative is:
Console.WriteLine(“Windows ID:” & System.Security.Principal.WindowsIdentity.GetCurrent.Name)
from a post here:
http://bytes.com/topic/visual-basic-net/answers/585547-my-user-name-returning-empty-xp-pro-sp2
‘Public Property Left() or Right() As Integer’ has no parameters and its return type cannot be indexed
The message appears against x = Left(a,2) – all of them.
The problem goes away if I comment out the line:
Imports System.Collections.ObjectModel
but I need that in order to define a variable as
ReadOnlyCollection(Of String)
There are some sites that suggest the Left is deprecated as a function, but this does not appear to be the case. (http://msdn.microsoft.com/en-us/library/y050k1wb(VS.80).aspx)
Resolution
This appears to be a poor piece of decision making by the compiler. Left can be qualified as strings.left, in which case the interpretation is explicit and correct.
e.g.
x = Strings.Left(a,2)