Pete's Windows, Office, VB & SQL Blog

Problems I have solved (or not) and good ideas I've found

Posts Tagged ‘VB express 2005

How to scroll a textbox programatically as data is added

with one comment

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.

Written by fisherpeter

2009 November 24 at 17:17

Posted in VB express 2005

Tagged with ,

Function optional variable as integer = nothing defaults to zero

leave a comment »

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

Written by fisherpeter

2009 September 3 at 13:03

My.User.Name returns an empty string

leave a comment »

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

Written by fisherpeter

2009 August 14 at 14:07

‘Public Property Left() or Right() As Integer’ has no parameters and its return type cannot be indexed

with one comment

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)

Written by fisherpeter

2009 August 7 at 10:47

Follow

Get every new post delivered to your Inbox.