Jump to content

Text colour! Using "IF" command.

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
16 replies to this topic

#1
travy92

travy92

    Learning Programmer

  • Members
  • PipPipPip
  • 76 posts
Well basically i want to change the text colour depending on what response is chosen, this is my code so far:

Private Sub cmdCountry_Click()
Dim strLocation As String
Dim Answer As Integer



strLocation = InputBox("Enter your Country:", "Country")

If Answer = Australia Then
frmTest.ForeColor = vbGreen





Print "Hmm, "; strLocation; " is a nice place to live."
Print "What State/Suburb do you live in?"
End If
End Sub
---------------------------------------------------------------

If Answer = Australia Then
frmTest.ForeColor = vbGreen


This is the part that changes the font colour when the response/answer is Australia.

This is perfectly what i wanted BUT i want to make it so that when a different response/answer is written (I'm using inputbox), a different colour is chosen. Without having to type out like every answer in the world!

Sorry if this was a newbie question.

Thanks in advance! :eek:

#2
o0TheNerd0o

o0TheNerd0o

    Learning Programmer

  • Members
  • PipPipPip
  • 61 posts
Select case...?
Option Explicit
:cool:

#3
o0TheNerd0o

o0TheNerd0o

    Learning Programmer

  • Members
  • PipPipPip
  • 61 posts
Select case example:

strLocation = InputBox("Enter your Country:", "Country")

Select Case strLocation
Case "Australia"
frmTest.ForeColor = vbGreen
Case "America"
frmTest.ForeColor = vbBlue
Case Else
frmTest.ForeColor = vbRed
End Select
Option Explicit
:cool:

#4
Lop

Lop

    Speaks fluent binary

  • Members
  • PipPipPipPipPipPipPipPip
  • 1,172 posts
Select Case would be your easiest answer. You will have to type out every answer you want colored though.

#5
travy92

travy92

    Learning Programmer

  • Members
  • PipPipPip
  • 76 posts
Alright thanks!

#6
TcM

TcM

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 11,147 posts
Or you could use if..then..else but case is more appropriate in this case I think.

#7
o0TheNerd0o

o0TheNerd0o

    Learning Programmer

  • Members
  • PipPipPip
  • 61 posts
It can definitely be done with "If", "ElseIF", "Else", but that method is not practical. Select case is the ideal solution for this sort of input handling.
Option Explicit
:cool:

#8
TcM

TcM

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 11,147 posts
Agreed. But most likely new people use if..then..else as they find it more logical and can figure it out easily, but of course case is the best solution.

#9
o0TheNerd0o

o0TheNerd0o

    Learning Programmer

  • Members
  • PipPipPip
  • 61 posts
But you can't stay new forever. Part of becoming a "good" programmer, is to learn more/new methods of doing the same thing. It makes you well rounded when it comes to theory and logic.
Option Explicit
:cool:

#10
TcM

TcM

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 11,147 posts
Yup, agreed.. Thats what I do. And always use the best method that I know of.

#11
o0TheNerd0o

o0TheNerd0o

    Learning Programmer

  • Members
  • PipPipPip
  • 61 posts
I think thats what everyone tries to do. I mean, if you know one way is better than the other, why would you use any other method?

It says you are a programming god. Do you have any actual programming experience? Anything credible? College? Work? Anything?
Option Explicit
:cool:

#12
TcM

TcM

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 11,147 posts
Well the 'programming god' thing just depends on your forum post count. And yes, I have actual programming experience I know some programming languages, made some custom-made softwares just for personal use, and personal use only, Had computer Studies and programming at school, and I had the best programming project at school (was ranked the first) and now I'm continuing to study at the college. I have some websites too and Besides Programming I have a very good general computer knowledge.