使用Double数据类型进行下一循环搜索未知值。 [英] Using Double data type in for next loop to search for an unknown value.

查看:73
本文介绍了使用Double数据类型进行下一循环搜索未知值。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在制作一个程序,告诉我是否值(我不知道,但我知道范围(从0.00000001到1.0是否存在))。



该值以十进制表示。我使用了Double数据类型(不确定我是否应该使用此数据类型,因为我一直在使用float)。我在文本框中使用的测试数据是:



  invertYMouse:false  
mouseSensitivity:0 5
fov:0 0
gamma:0 37323943
saturation:0 0
renderDistance:5
guiScale:0





这是我正在做的代码:



 < span class =code-keyword>对于 a  As   Double  =  0  00000001    1 。 0  

If TextBox1.Text.Contains( gamma: + Convert.ToString(a))< span class =code-keyword>然后

MsgBox( 你的值为: + Convert.ToString(a))
退出 Sub
结束 如果

a = a + 0 00000001
下一步





每次运行我的代码时,它都会退出程序。关于这一点的帮助将非常感激。



问候,

Ammar Ahmad

解决方案

您需要识别步骤,否则只需添加一个,因为.0000001 + 1> 1.0,它将在一个循环后退出。



 对于 a < span class =code-keyword> As   Double  =  0  00000001     1  0  步骤  0  0000001  





并在底部摆脱a = a + ...







根据您的示例数据,这里有一种更简单的方法来查找不需要37,323,943循环的伽玛...如果他们的额外小数位超出您选择的位数,您的代码将会错过。



1.创建一个字符串数组。

2.拆分字符串(使用String.Split)根据行(Environment.NewLine)拆分它。

3.找到sta的元素带有gamma的rts

4.将它分成2个字符串(再次使用String.Split),这次仅在:上。

5.使用Double。解析解析上面#4的第二个元素并获取值。



没有理由循环查找匹配的每个可能的值......


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:

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:

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

解决方案

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

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...


这篇关于使用Double数据类型进行下一循环搜索未知值。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆