对于下一个VB.NET,Power1值为零 [英] Power1 value is zero after for next VB.NET

查看:68
本文介绍了对于下一个VB.NET,Power1值为零的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Dim Guc1....Guc59 as decimal

Guc1=Val(TextBox5.Text)*Val(Textbox98.Text)
  . 
  .
  .
Guc59=Val(TextBox42.Text)*Val(Textbox12.Text)

For i = 1 To 59 Step 2

        Dim txt As TextBox = CType(TabControlPanel1.Controls("TextBoxX" & i), TextBox)
        Dim guc As Decimal = CType(("Guc".ToString & i), Decimal)

        Hız1 = Val(txt.Text) * RollinRadius * 3.14 * 3.6 / (Val(TextBox1.Text) * Val(TextBox33.Text) * 30)


        Power1 = guc * 3.14 / (30 * 1000) *2  *3)

        ListBox2.Items.Add(Power1)


    Next





我尝试过:



你能帮我解决一下Power1 zerp问题。

我认为ctype在这里是不正确的。



What I have tried:

Could you please help me to solve Power1 zerp issue.
I think ctype is incorrect here.

推荐答案

稍微解释一下对你的问题有用...



我会做以下事情:

- 而不是使用59个单独的变量(Guc1 ... Guc59)使用数组(Dim Guc(59) as decimal)

现在你可以索引循环中的每个Array-Element。

- 你真的很确定吗?每个文本框包含一个数值?



但是 - 你的代码看起来像这样:

A little more explaining would be useful for your question ...

I would do the following :
- instead of using 59 seperate Variables (Guc1 ... Guc59) use an Array (Dim Guc(59) as decimal)
now you are able to index each Array-Element inside your loop.
- are you really sure that each Textbox contains a numeric value ?

However - your code could look like this :
Dim Guc (59) as decimal

Guc(1) = Val(TextBox5.Text)*Val(Textbox98.Text)
.
.
.
Guc(59) = Val(TextBox42.Text)*Val(Textbox12.Text)

For i = 1 To 59 Step 2
   Dim txt As TextBox = CType(TabControlPanel1.Controls("TextBoxX" & i), TextBox)
   Hız1 = Val(txt.Text) * RollinRadius * 3.14 * 3.6 / (Val(TextBox1.Text) * Val(TextBox33.Text) * 30)

   Power1 = guc(i) * 3.14 / (30 * 1000) *2 *3)  ' <== instead of 3.14 you could also use Math.Pi

   ListBox2.Items.Add(Power1)
Next





附加:

如果你给你的文本框(以及其他控件)名称与输入相对应, ,你会更容易理解和阅读。

你认为,你会在几个月内知道哪些输入被制作成TextBox42(例如)?



Additional :
If you give your Textboxes (and also other controls) names which correspond to the input, which is made into them, your will become much more understandable and readable.
Do you think, that you will know in a few months which input is to be made into TextBox42 (for example) ?

这篇关于对于下一个VB.NET,Power1值为零的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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