change text to red if balance is negative

need to change text in a textbox if needed

  • (2 Pages)
  • +
  • 1
  • 2

19 Replies - 5238 Views - Last Post: 26 January 2008 - 07:09 PM Rate Topic: -----

#1 chevywes  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 44
  • Joined: 24-January 08

change text to red if balance is negative

Post icon  Posted 24 January 2008 - 01:46 PM

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


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: ) :)
Thanks

This post has been edited by PsychoCoder: 24 January 2008 - 01:50 PM


Is This A Good Question/Topic? 0
  • +

Replies To: change text to red if balance is negative

#2 PsychoCoder  Icon User is offline

  • Google.Sucks.Init(true);
  • member icon

Reputation: 1641
  • View blog
  • Posts: 19,853
  • Joined: 26-July 07

Re: change text to red if balance is negative

Posted 24 January 2008 - 01:52 PM

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


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


Was This Post Helpful? 0
  • +
  • -

#3 chevywes  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 44
  • Joined: 24-January 08

Re: change text to red if balance is negative

Posted 24 January 2008 - 03:01 PM

View PostPsychoCoder, on 24 Jan, 2008 - 01:52 PM, said:

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


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

Was This Post Helpful? 0
  • +
  • -

#4 Jayman  Icon User is offline

  • Student of Life
  • member icon

Reputation: 418
  • View blog
  • Posts: 9,532
  • Joined: 26-December 05

Re: change text to red if balance is negative

Posted 24 January 2008 - 03:06 PM

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: tags when posting your code.
Was This Post Helpful? 0
  • +
  • -

#5 ferrari12508  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 3
  • View blog
  • Posts: 1,115
  • Joined: 02-November 07

Re: change text to red if balance is negative

Posted 24 January 2008 - 05:17 PM

A simple If statement would help here
If d < 0 then
textbox1.color = color.red
else if d>= 0 then
textbox1.color = color.black
end if
textbow.1.text = d


Was This Post Helpful? 0
  • +
  • -

#6 chevywes  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 44
  • Joined: 24-January 08

Re: change text to red if balance is negative

Posted 24 January 2008 - 05:38 PM

View Postferrari12508, on 24 Jan, 2008 - 05:17 PM, said:

A simple If statement would help here
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 ]
Was This Post Helpful? 0
  • +
  • -

#7 ferrari12508  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 3
  • View blog
  • Posts: 1,115
  • Joined: 02-November 07

Re: change text to red if balance is negative

Posted 24 January 2008 - 06:49 PM

View Postchevywes, on 24 Jan, 2008 - 06:38 PM, said:

View Postferrari12508, on 24 Jan, 2008 - 05:17 PM, said:

A simple If statement would help here
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

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.
Was This Post Helpful? 0
  • +
  • -

#8 chevywes  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 44
  • Joined: 24-January 08

Re: change text to red if balance is negative

Posted 24 January 2008 - 07:14 PM

View Postchevywes, on 24 Jan, 2008 - 07:09 PM, said:

View Postferrari12508, on 24 Jan, 2008 - 06:49 PM, said:

View Postchevywes, on 24 Jan, 2008 - 06:38 PM, said:

View Postferrari12508, on 24 Jan, 2008 - 05:17 PM, said:

A simple If statement would help here
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

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
Was This Post Helpful? 0
  • +
  • -

#9 chevywes  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 44
  • Joined: 24-January 08

Re: change text to red if balance is negative

Posted 25 January 2008 - 09:25 AM

View Postchevywes, on 24 Jan, 2008 - 07:14 PM, said:

View Postchevywes, on 24 Jan, 2008 - 07:09 PM, said:

View Postferrari12508, on 24 Jan, 2008 - 06:49 PM, said:

View Postchevywes, on 24 Jan, 2008 - 06:38 PM, said:

View Postferrari12508, on 24 Jan, 2008 - 05:17 PM, said:

A simple If statement would help here
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

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

	
		 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 January 2008 - 09:28 AM

Was This Post Helpful? 0
  • +
  • -

#10 PsychoCoder  Icon User is offline

  • Google.Sucks.Init(true);
  • member icon

Reputation: 1641
  • View blog
  • Posts: 19,853
  • Joined: 26-July 07

Re: change text to red if balance is negative

Posted 25 January 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
Was This Post Helpful? 0
  • +
  • -

#11 chevywes  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 44
  • Joined: 24-January 08

Re: change text to red if balance is negative

Posted 25 January 2008 - 09:40 AM

View PostPsychoCoder, on 25 Jan, 2008 - 09:29 AM, said:

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
Was This Post Helpful? 0
  • +
  • -

#12 Jayman  Icon User is offline

  • Student of Life
  • member icon

Reputation: 418
  • View blog
  • Posts: 9,532
  • Joined: 26-December 05

Re: change text to red if balance is negative

Posted 25 January 2008 - 11:21 AM

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?
Was This Post Helpful? 0
  • +
  • -

#13 chevywes  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 44
  • Joined: 24-January 08

Re: change text to red if balance is negative

Posted 25 January 2008 - 11:29 AM

View Postjayman9, on 25 Jan, 2008 - 11:21 AM, said:

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?


yes it does.

I have tried all the solutions and I keep getting errors saying that one thing or another is not a member of string.

I'll try all the solutions again one last time.

Then I think I'll just give up.

wes
Was This Post Helpful? 0
  • +
  • -

#14 Jayman  Icon User is offline

  • Student of Life
  • member icon

Reputation: 418
  • View blog
  • Posts: 9,532
  • Joined: 26-December 05

Re: change text to red if balance is negative

Posted 25 January 2008 - 12:10 PM

You CANNOT change the color of a variable. That is what you keep trying to do.

You apparently are not understanding, so perhaps a visual aid will help.

I have two TextBoxes called TextBox1 and TextBox2 and there are two buttons on this form called Button1 and Button2.

Here is the code for this simple example:
Public Class Form1

	Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
		Me.TextBox1.ForeColor = Color.Red
	End Sub

	Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
		Me.TextBox2.BackColor = Color.Red
	End Sub
End Class


Do you now see how am I changing the TextBox, not the actual text itself?

Look at the screen shot and you will see the result of setting the ForeColor property and the BackColor property of a TextBox.

Attached image(s)

  • Attached Image

Was This Post Helpful? 0
  • +
  • -

#15 chevywes  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 44
  • Joined: 24-January 08

Re: change text to red if balance is negative

Posted 25 January 2008 - 12:19 PM

View Postjayman9, on 25 Jan, 2008 - 12:10 PM, said:

You CANNOT change the color of a variable. That is what you keep trying to do.

You apparently are not understanding, so perhaps a visual aid will help.

I have two TextBoxes called TextBox1 and TextBox2 and there are two buttons on this form called Button1 and Button2.

Here is the code for this simple example:
Public Class Form1

	Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
		Me.TextBox1.ForeColor = Color.Red
	End Sub

	Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
		Me.TextBox2.BackColor = Color.Red
	End Sub
End Class


Do you now see how am I changing the TextBox, not the actual text itself?

Look at the screen shot and you will see the result of setting the ForeColor property and the BackColor property of a TextBox.


Thanks for all your help. I see what you mean. I was just trying to show the numbers in red if someone over drew on thier account (simply me ), but I see it can't be done not even with string maniputation.

Thanks again for all your help
wes
Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2