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:
Text colour! Using "IF" command.
Started by travy92, Sep 07 2007 02:22 AM
16 replies to this topic
#1
Posted 07 September 2007 - 02:22 AM
|
|
|
#2
Posted 07 September 2007 - 08:11 AM
#3
Posted 07 September 2007 - 08:12 AM
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
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:
:cool:
#4
Posted 07 September 2007 - 04:50 PM
Select Case would be your easiest answer. You will have to type out every answer you want colored though.
#5
Posted 07 September 2007 - 05:03 PM
Alright thanks!
#6
Posted 08 September 2007 - 02:40 AM
Or you could use if..then..else but case is more appropriate in this case I think.
#7
Posted 08 September 2007 - 10:35 AM
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:
:cool:
#8
Posted 09 September 2007 - 02:04 AM
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
Posted 17 September 2007 - 03:32 PM
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:
:cool:
#10
Posted 18 September 2007 - 07:01 AM
Yup, agreed.. Thats what I do. And always use the best method that I know of.
#11
Posted 18 September 2007 - 07:11 AM
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?
It says you are a programming god. Do you have any actual programming experience? Anything credible? College? Work? Anything?
Option Explicit
:cool:
:cool:
#12
Posted 18 September 2007 - 12:45 PM
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.


Sign In
Create Account


Back to top









