How can I clean up this code?

max67933

New member
Joined
Aug 16, 2013
Messages
1
Programming Experience
Beginner
Okay, I got bored and decided to make a hiscores app for 07 runescape, gonna have comparing and all and well I got to the comparing part.. and this is the code I used (To make colors etc.. green if your higher red if your lower and or cyan if you're the same level) and the code looks messy)

        If lblAtk.Text > Label9.Text Then
            lblAtk.ForeColor = Color.Green
            Label9.ForeColor = Color.Red
        ElseIf Attack_label.Text < Label9.Text Then
            lblAtk.ForeColor = Color.Red
            Label9.ForeColor = Color.Green
        Else
            lblAtk.ForeColor = Color.Cyan
            Label9.ForeColor = Color.Cyan
        End If


        If lblStr.Text > Label31.Text Then
            lblStr.ForeColor = Color.Green
            Label31.ForeColor = Color.Red
        ElseIf lblStr.Text < Label31.Text Then
            lblStr.ForeColor = Color.Red
            Label31.ForeColor = Color.Green
        Else
            lblStr.ForeColor = Color.Cyan
            Label31.ForeColor = Color.Cyan
        End If


        If lblDef.Text > Label31.Text Then
            lblDef.ForeColor = Color.Green
            Label31.ForeColor = Color.Red
        ElseIf Defense_label.Text < Label31.Text Then
            lblDef.ForeColor = Color.Red
            Label31.ForeColor = Color.Green
        Else
            lblDef.ForeColor = Color.Cyan
            Label31.ForeColor = Color.Cyan
        End If


        If lblRan.Text > Label26.Text Then
            lblRan.ForeColor = Color.Green
            Label26.ForeColor = Color.Red
        ElseIf lblRan.Text < Label26.Text Then
            lblRan.ForeColor = Color.Red
            Label26.ForeColor = Color.Green
        Else
            lblRan.ForeColor = Color.Cyan
            Label26.ForeColor = Color.Cyan
        End If


        If lblCon.Text > Label12.Text Then
            lblCon.ForeColor = Color.Green
            Label12.ForeColor = Color.Red
        ElseIf lblCon.Text < Label12.Text Then
            lblCon.ForeColor = Color.Red
            Label12.ForeColor = Color.Green
        Else
            lblCon.ForeColor = Color.Cyan
            Label12.ForeColor = Color.Cyan
        End If



I would love to do in an array like this
Yes I know the below code is Java, No I can't figure out how to do it in vb.. I've tried all night lol :s
(The Below code is also used for my Java-Version Hiscores, doesn't offer much.. :l lol gotta work on it too :p )

private static final int[][] POS = { 
        {55,43,46,14}, //Overall
        {25,71,23,14}, //Attack
        {22,122,23,14}, //Defence
        {23,96,23,14}, //Strength
        {66,71,23,14}, //Hitpoints
        {25,147,23,14}, //Ranged
        {23,173,23,14}, //Prayer
        {23,200,23,14}, //Magic
        {118,143,23,14}, //Cooking
        {118,200,23,14}, //Woodcutting
        {66,200,23,14}, //Fletching
        {119,122,23,14}, //Fishing
        {118,173,23,14}, //Firemaking
        {66,173,23,14}, //Crafting
        {118,96,23,14}, //Smithing
        {118,70,23,14}, //Mining
        {66,122,23,14}, //Herblore
        {66,96,23,14}, //Agility
        {66,146,23,14}, //Thieving
        {66,225,23,14}, //Slayer
        {118,225,23,14}, //Farming
        {23,225,23,14}, //Runecrafting
        {66,250,23,14}, //Hunter
        {22,250,23,14} //Construction
        };


P.S I am new to vbdotnetforums, I've been trying to figure this out for a bit now, still can't could anyone please help me?
 
The reason why noone replied to this, I guess, is we haven't really got a clue what's going on. I've no idea what Runescape is, or why your Label11.Text would be alphabetically after (when you compare strings with > you should be aware that "2" is greater than "17") some other label text and that makes it green or cyan.

Take it back a step and more clearly define what it is youre actually doing. If you can expalin it to us you'll be better able to work it out yourself
 

Latest posts

Back
Top