Welcome to Dream.In.Code
Become a VB.NET Expert!

Join 149,404 VB.NET Programmers for FREE! Get instant access to thousands of VB.NET experts, tutorials, code snippets, and more! There are 2,189 people online right now. Registration is fast and FREE... Join Now!




change text to red if balance is negative

2 Pages V  1 2 >  
Reply to this topicStart new topic

change text to red if balance is negative, need to change text in a textbox if needed

chevywes
24 Jan, 2008 - 12:46 PM
Post #1

New D.I.C Head
*

Joined: 24 Jan, 2008
Posts: 44

Will try this post again, everything went blank on me.

I'm retired and thought I'd like to learn vs 2008 Express as a hobby. I'm running Vista Home Premiun.

This is my first post and hope not to bug you people too much.

Thanks for all your help I'm about to recieve

wes


CODE

Private Sub openChequeBook()

        Dim mo As String
        Dim a As Single
        Dim p As String
        Dim cbb As Single
        Dim d As Decimal
        Dim fn As String = "C:\\ChequeBook\purchases.txt"

        If System.IO.File.Exists(fn) = True Then
            Dim objReader As New System.IO.StreamReader(fn)
            Dim sp As String, text As String, bigtex As String
            sp = "                    " ''20 spaces
            text = ""
            bigtex = ""

            Do While objReader.Peek() <> -1
                mo = objReader.ReadLine
                a = objReader.ReadLine
                cbb = objReader.ReadLine
                p = objReader.ReadLine

                text = mo & sp
                text = text.Substring(0, 13)
                bigtex = bigtex & text
                text = String.Format("{0:c}", a) & sp
                text = text.Substring(0, 9)
                bigtex = bigtex & text
                text = String.Format("{0:c}", cbb) & sp
                text = text.Substring(0, 11)
                bigtex = bigtex & text
                text = p & sp
                text = text.Substring(0, 19)
                bigtex = bigtex & text & vbNewLine
            Loop
            objReader.Close()
            TextBox1.Text = bigtex
        Else
            MsgBox("File Does Not Exist")
        End If

    End Sub



EDIT: Please, next time, use code tags, like so ( code.gif ) smile.gif
Thanks

This post has been edited by PsychoCoder: 24 Jan, 2008 - 12:50 PM
User is offlineProfile CardPM
+Quote Post

PsychoCoder
RE: Change Text To Red If Balance Is Negative
24 Jan, 2008 - 12:52 PM
Post #2

using DIC.Core;
Group Icon

Joined: 26 Jul, 2007
Posts: 9,476



Thanked: 160 times
Dream Kudos: 9025
Expert In: VB, VB.Net, C#, SQL, ASP, ASP.Net, Web Development, HTML, CSS, Win32 API, Javascript, mySQL, J#, Boo.Net

My Contributions
You could accomplish that with a simple If statement, like so


CODE

If value < 0 Then
    Label1.ForeColor = Color.Red
    Label1.Text = "Your Text Here"
Else
    'All is normal
End If

User is offlineProfile CardPM
+Quote Post

chevywes
RE: Change Text To Red If Balance Is Negative
24 Jan, 2008 - 02:01 PM
Post #3

New D.I.C Head
*

Joined: 24 Jan, 2008
Posts: 44

QUOTE(PsychoCoder @ 24 Jan, 2008 - 01:52 PM) *

You could accomplish that with a simple If statement, like so


CODE

If value < 0 Then
    Label1.ForeColor = Color.Red
    Label1.Text = "Your Text Here"
Else
    'All is normal
End If



Thanks for the help,, but I get to many errors.

Sorry for being so ignorant.
wes
CODE

text = String.Format("{0:c}", cbb) & sp
                '''''''''''''''''''''''''''''''''''''''''''''''''''''''''
                ' this turns the whole text box to red
                ' negative balances are show in brackets with a minus sign
                If text.Substring(0, 1) = "(" Then
                    TextBox1.ForeColor = Color.Red
                Else
                    TextBox1.ForeColor = Color.Black
                End If
                '''''''''''''''''''''''''''''''''''''''''''''''''''''''''
                text = text.Substring(0, 11)
                bigtex = bigtex & text

User is offlineProfile CardPM
+Quote Post

Jayman
RE: Change Text To Red If Balance Is Negative
24 Jan, 2008 - 02:06 PM
Post #4

Student of Life
Group Icon

Joined: 26 Dec, 2005
Posts: 7,297



Thanked: 66 times
Dream Kudos: 500
Expert In: Everything

My Contributions
Post the errors that you are getting, it makes our lives much easier to help you debug your code.

As Psychocoder already mentioned please use code.gif tags when posting your code.
User is offlineProfile CardPM
+Quote Post

ferrari12508
RE: Change Text To Red If Balance Is Negative
24 Jan, 2008 - 04:17 PM
Post #5

D.I.C Lover
Group Icon

Joined: 2 Nov, 2007
Posts: 1,112



Thanked: 2 times
Dream Kudos: 150
My Contributions
A simple If statement would help here
CODE

If d < 0 then
textbox1.color = color.red
else if d>= 0 then
textbox1.color = color.black
end if
textbow.1.text = d

User is offlineProfile CardPM
+Quote Post

chevywes
RE: Change Text To Red If Balance Is Negative
24 Jan, 2008 - 04:38 PM
Post #6

New D.I.C Head
*

Joined: 24 Jan, 2008
Posts: 44

QUOTE(ferrari12508 @ 24 Jan, 2008 - 05:17 PM) *

A simple If statement would help here
CODE

If d < 0 then
textbox1.color = color.red
else if d>= 0 then
textbox1.color = color.black
end if
textbow.1.text = d



Sorry that doesn't work either

it says that " color is not a member System.Windows.Form.Textbox" and that text is not a member of double.

Do I have to declare my variables as double, they;er declared as Single now

wes

['''''''''''''''''''''''''''''''''''''''''''''''''''''
text = String.Format("{0:c}", cbb) & sp
value = cbb
If value < 0 Then
Label1.ForeColor = Color.Red
Label1.Text = text
Else
'All is normal
End If
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''
text = text.Substring(0, 11)
bigtex = bigtex & text ]


User is offlineProfile CardPM
+Quote Post

ferrari12508
RE: Change Text To Red If Balance Is Negative
24 Jan, 2008 - 05:49 PM
Post #7

D.I.C Lover
Group Icon

Joined: 2 Nov, 2007
Posts: 1,112



Thanked: 2 times
Dream Kudos: 150
My Contributions
QUOTE(chevywes @ 24 Jan, 2008 - 06:38 PM) *

QUOTE(ferrari12508 @ 24 Jan, 2008 - 05:17 PM) *

A simple If statement would help here
CODE

If d < 0 then
textbox1.color = color.red
else if d>= 0 then
textbox1.color = color.black
end if
textbow.1.text = d



Sorry that doesn't work either

it says that " color is not a member System.Windows.Form.Textbox" and that text is not a member of double.


No, that was just me making a dumbass mistake
CODE


If d < 0 then
d.tostring
d.color = color.red
else if d>= 0 then
d.tostring
d.color = color.red
end if
textbow.1.text = d


Sorry i messed that up, I dont have VS on the computer im using right now and i cant get it. this in turn means that all this code has to be tested in my head and my head is a very scary place.
User is offlineProfile CardPM
+Quote Post

chevywes
RE: Change Text To Red If Balance Is Negative
24 Jan, 2008 - 06:14 PM
Post #8

New D.I.C Head
*

Joined: 24 Jan, 2008
Posts: 44

QUOTE(chevywes @ 24 Jan, 2008 - 07:09 PM) *

QUOTE(ferrari12508 @ 24 Jan, 2008 - 06:49 PM) *

QUOTE(chevywes @ 24 Jan, 2008 - 06:38 PM) *

QUOTE(ferrari12508 @ 24 Jan, 2008 - 05:17 PM) *

A simple If statement would help here
CODE

If d < 0 then
textbox1.color = color.red
else if d>= 0 then
textbox1.color = color.black
end if
textbow.1.text = d



Sorry that doesn't work either

it says that " color is not a member System.Windows.Form.Textbox" and that text is not a member of double.


No, that was just me making a dumbass mistake
CODE


If d < 0 then
d.tostring
d.color = color.red
else if d>= 0 then
d.tostring
d.color = color.red
end if
textbow.1.text = d


Sorry i messed that up, I dont have VS on the computer im using right now and i cant get it. this in turn means that all this code has to be tested in my head and my head is a very scary place.




The error I get now is that Color is not a member of Decimal

Boy!!
I didn't think that this would cause such a big problem ... Sorry everybody.

Thanks for all your help .

I'll keep trying

wes
User is offlineProfile CardPM
+Quote Post

chevywes
RE: Change Text To Red If Balance Is Negative
25 Jan, 2008 - 08:25 AM
Post #9

New D.I.C Head
*

Joined: 24 Jan, 2008
Posts: 44

QUOTE(chevywes @ 24 Jan, 2008 - 07:14 PM) *

QUOTE(chevywes @ 24 Jan, 2008 - 07:09 PM) *

QUOTE(ferrari12508 @ 24 Jan, 2008 - 06:49 PM) *

QUOTE(chevywes @ 24 Jan, 2008 - 06:38 PM) *

QUOTE(ferrari12508 @ 24 Jan, 2008 - 05:17 PM) *

A simple If statement would help here
CODE

If d < 0 then
textbox1.color = color.red
else if d>= 0 then
textbox1.color = color.black
end if
textbow.1.text = d



Sorry that doesn't work either

it says that " color is not a member System.Windows.Form.Textbox" and that text is not a member of double.


No, that was just me making a dumbass mistake
CODE


If d < 0 then
d.tostring
d.color = color.red
else if d>= 0 then
d.tostring
d.color = color.red
end if
textbow.1.text = d


Sorry i messed that up, I dont have VS on the computer im using right now and i cant get it. this in turn means that all this code has to be tested in my head and my head is a very scary place.




The error I get now is that Color is not a member of Decimal

Boy!!
I didn't think that this would cause such a big problem ... Sorry everybody.

Thanks for all your help .

I'll keep trying

wes



Since I use a substring to place the text in the text box is there any way that I can change the color of a substring since the negative numbers are in brackets, I thought ( this getting dangerous - me thinking ) I would try just changing the color of the substring, or am I out in left field some where lost again
wes

CODE

    
         If cbb < 0 Then
                    text = text.Substring(0, 10)
                    text.Forecolor = Color.Red
                Else
                    text = text.Substring(0, 9)
                    text.Forecolor = Color.Black
                End If



The error I get is that Forecolor is not a member of string.

How can I change this

Thanks for all your Help
wes

This post has been edited by PsychoCoder: 25 Jan, 2008 - 08:28 AM
User is offlineProfile CardPM
+Quote Post

PsychoCoder
RE: Change Text To Red If Balance Is Negative
25 Jan, 2008 - 08:29 AM
Post #10

using DIC.Core;
Group Icon

Joined: 26 Jul, 2007
Posts: 9,476



Thanked: 160 times
Dream Kudos: 9025
Expert In: VB, VB.Net, C#, SQL, ASP, ASP.Net, Web Development, HTML, CSS, Win32 API, Javascript, mySQL, J#, Boo.Net

My Contributions
You're trying to set the ForeColor of a string, which isn't going to happen as there is no ForeColor Property for the String class. You should be setting the ForeColor of the textbox the text will be displayed in
User is offlineProfile CardPM
+Quote Post

chevywes
RE: Change Text To Red If Balance Is Negative
25 Jan, 2008 - 08:40 AM
Post #11

New D.I.C Head
*

Joined: 24 Jan, 2008
Posts: 44

QUOTE(PsychoCoder @ 25 Jan, 2008 - 09:29 AM) *

You're trying to set the ForeColor of a string, which isn't going to happen as there is no ForeColor Property for the String class. You should be setting the ForeColor of the textbox the text will be displayed in



I don't want the whole text box in red, just my negative number which is in brackets.

This programing is getting more FRUSTRATED by the minute.

I want the text changed not the text box, hope somebody makes a better programing language soon.

I'll keep struggling away, Thanks For all your efforts

wes
User is offlineProfile CardPM
+Quote Post

Jayman
RE: Change Text To Red If Balance Is Negative
25 Jan, 2008 - 10:21 AM
Post #12

Student of Life
Group Icon

Joined: 26 Dec, 2005
Posts: 7,297



Thanked: 66 times
Dream Kudos: 500
Expert In: Everything

My Contributions
The problem here is that you don't seem to understand that setting the ForeColor property of a textbox only affects the color of the text as it is displayed in the TextBox, NOT the textbox itself.

Have you even tried using the solution that everyone here has been trying to help you with?

The BackColor property is used to change the entire TextBox to red, while leaving the text the default color of black.

You can not directly change the color of text, you can only change the way it is displayed in a control.

Does that make sense?
User is offlineProfile CardPM
+Quote Post

2 Pages V  1 2 >
Fast ReplyReply to this topicStart new topic
Time is now: 1/7/09 10:28AM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live VB.NET Help!

VB.NET Tutorials

Reference Sheets

VB.NET Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month