Basic4ppc - Windows Mobile Development  

Go Back   Basic4ppc - Windows Mobile Development > Main Category > Questions & Help Needed
Home Register FAQ Members List Search Today's Posts Mark Forums Read

Questions & Help Needed Post any question regarding Basic4ppc.


ComboBox load problem


Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 04-11-2008, 03:46 PM
Newbie
 
Join Date: Aug 2007
Posts: 3
Default ComboBox load problem

Hi all,

I'm using Basic4PPC V6.05 and want to load a ComboBox with a series of items (sample code is below).

Sub App_Start
Form1.Show
For i = 1.01 To 12 Step 0.01
If i = 1.45 Then
ComboBox1.Add (i & " xxx")
Else
If i = 2.5 Then
ComboBox1.Add (i & " xxx")
Else
ComboBox1.Add(i)
End If
End If
Next i
ComboBox1.SelectedIndex = 399 ' default display = 5 = index 399
End Sub

If I run the above inside the IDE its fine but when compiled to either device or desktop the combobox loads ok to "2.27" and the next value becomes "2.2799999999".

The extra 0.009999999999's are then added to all subsequent items in the ComboBox.

Any suggestions to solve this problem?

Thanks in advance

mollin1
Reply With Quote
  #2 (permalink)  
Old 04-11-2008, 04:44 PM
Erel's Avatar
Administrator
 
Join Date: Apr 2007
Posts: 3,141
Default

You can use the Round method:
Code:
For i = 1.01 To 12 Step 0.01
i = Round(i,2)
...
Reply With Quote
  #3 (permalink)  
Old 04-11-2008, 04:45 PM
agraham's Avatar
Basic4ppc Expert
 
Join Date: Jul 2007
Location: Cheshire, UK
Posts: 1,697
Awards Showcase
Beta Tester Forum Contributer 
Total Awards: 2
Default

Use Round(i,2) to get the result you want. See Help->Main Help->Keywords->Math

What you are seeing is due to the fact that binary floating point numbers used for general purposes in computers cannot always exactly represent non-integer real decimal numbers. Where exact precision is needed computer languages offer special numeric types such as "Currency" or "Decimal" where the results of operations using such numbers is guaranteed to be as expected.

EDIT :- Damn, second again!
Reply With Quote
  #4 (permalink)  
Old 04-11-2008, 05:16 PM
Erel's Avatar
Administrator
 
Join Date: Apr 2007
Posts: 3,141
Default

LOL
However your answer is much more informative.
Reply With Quote
  #5 (permalink)  
Old 04-12-2008, 07:51 AM
Newbie
 
Join Date: Aug 2007
Posts: 3
Default

Many thanks for your high speed replies guys, both for the tip and the explanation...!

I'll try it out now...
Reply With Quote
  #6 (permalink)  
Old 04-12-2008, 08:16 AM
Newbie
 
Join Date: Aug 2007
Posts: 3
Default

Erel, agraham,

Success! thanks for your help.

m
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Load .csv to Table alexeew Questions & Help Needed 5 12-16-2007 09:01 AM
Program load stevefan Questions & Help Needed 1 12-07-2007 07:24 AM
ComboBox and ArrayList problem. kyto Questions & Help Needed 5 10-12-2007 10:15 AM
Load time BPak Questions & Help Needed 3 08-28-2007 04:27 AM
Load GPX-File mcflaytasche Questions & Help Needed 1 05-11-2007 10:01 AM


All times are GMT. The time now is 09:52 PM.


Powered by vBulletin® Version 3.6.12
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.1.0