Click here to Skip to main content
15,899,754 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi, I am working on a program that tells if me the value (which is unknown to me but I know the range (which is from 0.00000001 To 1.0 is present or not)).

The value is in decimal. I have used the Double data type (not sure if I should be using this data type because I have been using float). The test data I am using in the textbox is:

CSS
invertYMouse:false
mouseSensitivity:0.5
fov:0.0
gamma:0.37323943
saturation:0.0
renderDistance:5
guiScale:0


Here is the code of what I am doing:

VB
For a As Double = 0.00000001 To 1.0

    If TextBox1.Text.Contains("gamma:" + Convert.ToString(a)) Then

        MsgBox("Your value is: " + Convert.ToString(a))
        Exit Sub
    End If

    a = a + 0.00000001
Next


Every time I run my code it simply exits the procedure. Help regarding this would be really appreciated.

Regards,
Ammar Ahmad
Posted

1 solution

You need to identify the step, otherwise it just adds one, since .0000001 + 1 > 1.0, it will exit after one loop.

VB
For a As Double = 0.00000001 To 1.0 Step 0.0000001


And get rid of the a = a + ... at the bottom.

[Edit]

Given your example data, here is an easier way to find gamma that doesn't require 37,323,943 loops... Plus your code will miss it if they have an extra decimal place beyond the one you selected.

1. Create a string array.
2. Split the string (using String.Split) to split it based on line (Environment.NewLine).
3. Find the element that starts with "gamma"
4. Split that into 2 strings (using String.Split again), only on the ":" this time.
5. Use Double.Parse to parse the second element of #4 above and get the value.

There is no reason to loop through every possible value looking for a match...
 
Share this answer
 
v3
Comments
Maciej Los 9-Jan-14 16:03pm    
+5
Ron Beyer 9-Jan-14 16:23pm    
Thanks!
CPallini 9-Jan-14 16:22pm    
5.
Ron Beyer 9-Jan-14 16:23pm    
Thanks!
Matt T Heffron 9-Jan-14 16:24pm    
+5 (you beat me to it...)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900