two very silly questions below – they’ve just thrown me completely – please could you point me to which is correct and if you have time tell me why the others arent’. Thanks – you have no idea how much this will help me. I’m trying to teach myself VB and got this book of Amazon with questions but no answers and no where to find the answers.
1. Which of the following is a valid If…then…else statement?
a) pricelabel.text >0 andalso pricelabel.text<10
b) sales >500D orelse <800D
c) number >100 AndAlso number <=1000
d) state.ToUpper() = “Sydney” OrElse state.ToUpper = “Melbourne”
2. Assume you want to compare the string contained in the text property of firstNameTextbox with John, which of the following conditions should you use in the If…then…else statement? (Be sure the condition with handle John, JOHN, john, etc).
a) firstNameTextbox.text = toUpper (“JOHN”)
b) firstNameTextbox.text.toUpper() = “John”
c) firstNameTextbox.text.toUpper() = “JOHN”
d) toUpper(firstname.text) = “JOHN”
Thanks so much – I’m trying to teach myself and just keep getting stuck. Thanks a lot.
1a: is wrong because you are comparing strings to integers.
1b: is wrong because you are not comparing 800D with anything.
1d: is wrong because you will never get a match because you are converting everthing to upper case and comparing with a mixed case string.
1c: is the answer.
2a: will match upper case JOHN only.
2b: will never match since since you are converting the text to uppercase and comparing with a mixed case string.
2d: will match for uppercase JOHN only.
2c: since it converts the text to uppercase and compares with an uppercase string is the answer since it will match all combinations.