• Welcome to Valhalla Legends Archive.
 

VB8 - Weird problem using constant color value?

Started by Joe[x86], June 26, 2006, 02:19 PM

Previous topic - Next topic

Joe[x86]

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

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


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

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?






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

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


Usage:
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


Output:
Quote[1:27:03 PM] Welcome to .NET Bot by Joe[e2]!
Quote from: brew on April 25, 2007, 07:33 PM
that made me feel like a total idiot. this entire thing was useless.

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.

Joe[x86]

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!
Quote from: brew on April 25, 2007, 07:33 PM
that made me feel like a total idiot. this entire thing was useless.

l)ragon

Quote from: J on June 26, 2006, 02:19 PM
I've started writing a bot in VB8, so naturally, I had to write an addChat-type function.

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
There's no need to use Len() on strings anymore lol do this.
            .SelectionStart = .Text.Length
*^~·.,¸¸,.·´¯`·.,¸¸,.-·~^*ˆ¨¯¯¨ˆ*^~·.,l)ragon,.-·~^*ˆ¨¯¯¨ˆ*^~·.,¸¸,.·´¯`·.,¸¸,.-·~^*

Joe[x86]

Quote from: brew on April 25, 2007, 07:33 PM
that made me feel like a total idiot. this entire thing was useless.

l)ragon

Quote from: J on July 01, 2006, 04:17 PM
Advantages?
length is allready created in string your recounting a second time.
*^~·.,¸¸,.·´¯`·.,¸¸,.-·~^*ˆ¨¯¯¨ˆ*^~·.,l)ragon,.-·~^*ˆ¨¯¯¨ˆ*^~·.,¸¸,.·´¯`·.,¸¸,.-·~^*

K

Quote from: l)ragon on July 01, 2006, 04:27 PM
Quote from: J on July 01, 2006, 04:17 PM
Advantages?
length is allready created in string your recounting a second time.


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.

Warrior

Quote from: effect on March 09, 2006, 11:52 PM
Islam is a steaming pile of fucking dog shit. Everything about it is flawed, anybody who believes in it is a terrorist, if you disagree with me, then im sorry your wrong.

Quote from: Rule on May 07, 2006, 01:30 PM
Why don't you stop being American and start acting like a decent human?