Click here to Skip to main content
15,892,746 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
VB
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


What I have tried:

Could you please help me to solve Power1 zerp issue.
I think ctype is incorrect here.
Posted
Updated 10-Feb-17 22:48pm
v3

1 solution

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 :
VB
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


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) ?
 
Share this answer
 
v2
Comments
Member 12860952 11-Feb-17 4:57am    
Thank you very much @Ralf Meier, That solution is worked for me, using array is I think much more sensible.
Ralf Meier 11-Feb-17 14:41pm    
You're welcome.
Thanks for your vote ...

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