|
-
Aug 30th, 2000, 06:08 AM
#1
Thread Starter
Lively Member
This has really taken my time to find out just why always the message box display "two"?. Can anybody tell me why?
Private Sub Command1_Click()
Dim s As String
s = Choose(3.4, "zero", "one", "two", "three", "four")
MsgBox s
End Sub
-
Aug 30th, 2000, 06:15 AM
#2
_______
<?>
Code:
s = Choose(3.4, "zero", "one", "two", "three", "four")
The choose function rounds out numbers and the first index,in your case 3.4 = 3. It therefore chooses your third choice which is two
index = 3.4
1st = zero
2nd = one
3rd = 2
4th = 3
5th = 5
if you change your index to 1 it will return zero and so on
"A myth is not the succession of individual images,
but an integerated meaningful entity,
reflecting a distinct aspect of the real world."
___ Adolf Jensen
-
Aug 30th, 2000, 06:15 AM
#3
transcendental analytic
3.4 is rounded to 3, and Choose first alternative is zero (it's option base is 1) so the third is "two"
Use  
writing software in C++ is like driving rivets into steel beam with a toothpick.
writing haskell makes your life easier:
reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.
-
Aug 30th, 2000, 06:18 AM
#4
Addicted Member
Hi,
It's because the elements in the Choose function start of at one. ie: Zero = element(1), one = element(2) etc..
Choose also rounds down on it's search.
Therefore your code will place the 3rd element (3.4 rounded down), "two", into String s.
Hope this helps
Shaun
[Cross posted..sorry Kedaman & HeSaidJoe)
Web/Application Developer
VB6 Ent (SP5), Win 2000,SQL Server 2000
-
Aug 30th, 2000, 06:23 AM
#5
Guru
Actually the Choose function doesn't care about what you put in Option Base - it's always one-based.
-
Aug 31st, 2000, 12:22 PM
#6
transcendental analytic
I know but so is Mid$, Instr$, Right$, Left$, Put# Get#, Seek and a lot of other functions, some controls and classes, the collection object, treeview, listview are typical optionbase 1 stuff
Use  
writing software in C++ is like driving rivets into steel beam with a toothpick.
writing haskell makes your life easier:
reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|