Valhalla Legends Forums Archive | .NET Platform | VB8 - Weird problem using constant color value?

AuthorMessageTime
JoeTheOdd
I've started writing a bot in VB8, so naturally, I had to write an addChat-type function.

[code]Module modUserInterface

    Public Sub addChat(ByVal Color As System.Drawing.Color, ByVal Text As String)
        With frmMain.rtbOutput
            .SelectionStart = Len(.Text)
            .SelectionColor = Color.White
            .SelectedText = "[" & Microsoft.VisualBasic.TimeString & "] "
            .SelectionColor = Color
            .SelectedText = Text & Microsoft.VisualBasic.Chr(13)
            .SelectionStart = Len(.Text)
        End With
    End Sub

End Module
[/code]

On the line, [tt].SelectionColor = Color.White[/tt], I get the warning [tt]Access of shared member, constant member, enum member or nested type through an instance; qualifying expression will not be evaluated.[/tt]

Obviously it's not a fatal error or anything, but I'm trying to follow good coding style and proper language usage all throughout this bot. What's the proper way of doing what I'm attempting?


[hr]


After applying K's suggestions, here's the following code, example usage, and output.

Code:
[code]Module modUserInterface

    Public Sub addChat(ByVal myColor As System.Drawing.Color, ByVal myText As String)
        With frmMain.rtbOutput
            .SelectionStart = Len(.Text)
            .SelectionColor = Color.White
            .SelectedText = "[" & DateTime.Now.ToLongTimeString() & "] "
            .SelectionColor = myColor
            .SelectedText = myText & Environment.NewLine
            .SelectionStart = Len(.Text)
        End With
    End Sub

End Module[/code]

Usage:
[code]Public Class frmMain

    Private Sub frmMain_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        modUserInterface.addChat(Color.GreenYellow, "Welcome to .NET Bot by Joe[e2]!")
    End Sub

[...]

End Class[/code]

Output:
[quote][1:27:03 PM] Welcome to .NET Bot by Joe[e2]![/quote]
June 26, 2006, 7:19 PM
K
Tips:

Don't use anything from the Microsoft.VisualBasic namespace.  Those are there for conversion of legacy code.

Microsoft.VisualBasic.TimeString => DateTime.Now.ToString(optional format string)
Microsoft.VisualBasic.Chr(13) => Environment.NewLine

The warning you are getting is because you have named your variable "Color," which conflicts with the name of the type (if you have imported the System.Drawing namespace.  If you haven't imported that namespace, VB.NET must be super lax about things).

Either rename your variable, or change the Color.White to System.Drawing.Color.White.
June 26, 2006, 9:09 PM
JoeTheOdd
VB.NET is super lax about stuff.

That idea of conflicting names came to mind for a second, but I guess I never tested it.

Thanks!
June 26, 2006, 10:24 PM
dRAgoN
[quote author=J link=topic=15284.msg154988#msg154988 date=1151349589]
I've started writing a bot in VB8, so naturally, I had to write an addChat-type function.

[code]Module modUserInterface

    Public Sub addChat(ByVal Color As System.Drawing.Color, ByVal Text As String)
        With frmMain.rtbOutput
            .SelectionStart = Len(.Text)
            .SelectionColor = Color.White
            .SelectedText = "[" & Microsoft.VisualBasic.TimeString & "] "
            .SelectionColor = Color
            .SelectedText = Text & Microsoft.VisualBasic.Chr(13)
            .SelectionStart = Len(.Text)
        End With
    End Sub

End Module
[/code][/quote]
There's no need to use Len() on strings anymore lol do this.
[code]            .SelectionStart = .Text.Length[/code]
July 1, 2006, 9:04 PM
JoeTheOdd
Advantages?
July 1, 2006, 9:17 PM
dRAgoN
[quote author=J link=topic=15284.msg155126#msg155126 date=1151788651]
Advantages?
[/quote]
length is allready created in string your recounting a second time.
July 1, 2006, 9:27 PM
K
[quote author=l)ragon link=topic=15284.msg155129#msg155129 date=1151789241]
[quote author=J link=topic=15284.msg155126#msg155126 date=1151788651]
Advantages?
[/quote]
length is allready created in string your recounting a second time.

[/quote]

That and it makes more sense from an OO point of view.  "Length" is something that a string has, not an operation you apply to a string.
July 1, 2006, 11:01 PM
Quarantine
Plus it looks totally cool.
July 2, 2006, 6:22 PM

Search