Home > Net >  Consult, how to simplify the code
Consult, how to simplify the code

Time:11-08

Beginners, baidu BBS to ask out text save
But if I have 500 textbox, can only write like this?
Failed in his own ideas for circulation,
Consult the bosses have what simplified method?

Dim PathUserData As String="d: \ 11111. TXT" 'text file is written to
Dim t the As System. IO. StreamWriter=New System. IO. StreamWriter (PathUserData, False, System. Text. Encoding. UTF8)
T.W riteLine (TextBox1. Text)
T.W riteLine (TextBox2. Text)
T.W riteLine (TextBox3. Text)
T.W riteLine (TextBox4. Text)
T.W riteLine (TextBox5. Text)
T.W riteLine (TextBox6. Text)
T.W riteLine (TextBox7. Text)
T.W riteLine (TextBox8. Text)
T.W riteLine (TextBox9. Text)
T.W riteLine (TextBox10. Text)
T.W riteLine (TextBox11. Text)
T.W riteLine (TextBox12. Text)
T.W riteLine (Label4. Text)

Tc lose ()

Dim As the sr System. IO. StreamReader=New System. IO. StreamReader (" d: \ 11111. TXT ", System. Text. The Encoding. The Default)
Dim line As String
Line=sr. ReadLine 'text file to read
Me. TextBox1. Text=line
The line=sr. ReadLine
Me. TextBox2. Text=line
The line=sr. ReadLine
Me. TextBox3. Text=line
The line=sr. ReadLine
Me. TextBox4. Text=line
The line=sr. ReadLine
Me. TextBox5. Text=line
The line=sr. ReadLine
Me. TextBox6. Text=line
The line=sr. ReadLine
Me. TextBox7. Text=line
The line=sr. ReadLine
Me. TextBox8. Text=line
The line=sr. ReadLine
Me. TextBox9. Text=line
The line=sr. ReadLine
Me. TextBox10. Text=line
The line=sr. ReadLine
Me. TextBox11. Text=line
The line=sr. ReadLine
Me. TextBox12. Text=line
The line=sr. ReadLine
Me. Label4. Text=line
The sr. The Close ()

CodePudding user response:

 
Dim As Integer I
For I=1 To 500
Dim (c) As the Control=Me. Controls. Find (" TextBox "& amp; I, False)
MessageBox. Show (c (0). The Text)
Next

CodePudding user response:

reference 1/f, big watermelon cut a piece of a kilo of reply:
 
Dim As Integer I
For I=1 To 500
Dim (c) As the Control=Me. Controls. Find (" TextBox "& amp; I, False)
MessageBox. Show (c (0). The Text)
Next

Bosses that it may not seem like I'm going to the code, I want to save 500 text will read, for example, I so long to write down this code can only be this order

CodePudding user response:

What is the purpose of the read and write an article, you? If the line according to the article, you can use a listbox, branch read to the controls, why so many textbox built?

CodePudding user response:

In fact a textbox also can implement, set its properties into multiple lines

CodePudding user response:


Such a GroupBox it's about more than 190, and then in the textbox six, count down to more than 1000
Then I save the input to the text in it, is a dynamic change all the time

CodePudding user response:

reference wind, 4/f, not just reply:
actually a textbox can also realize, its properties can be set to multi-line


Such a GroupBox it's about more than 190, and then in the textbox six, count down to more than 1000
Then I save the input to the text in it, is a dynamic has become
I can only repeat text1, text2... Write like this

CodePudding user response:

You can define a textbox array, loop array can not

CodePudding user response:

refer to 7th floor glen30 response:
can define textbox array, loop array can not yet

Baidu has written several, unsuccessful frontal
Can you give a short demonstration

CodePudding user response:

Better use nested form:
Create a new form, assuming the formA, inside a goup, put 6 textbox, in this form to write a few public function, such as clean up all the textbox, get the value, etc.
In the main form to formA nested in the above form, and then loop operation:
After filling the access to content, can call formA removal method, input again

Form the use of nested method may refer to:
https://developer.51cto.com/art/201001/179552.htm

CodePudding user response:

refer to three kilometers everyday 8 floor response:
Quote: refer to 7th floor glen30 response:
can define textbox array, loop array can not yet

Baidu has written several, unsuccessful frontal
Can you give a short demonstration


VB6.0 by use, there is a control array VB.net usage is different, looks like this scenario is not suitable for control array

CodePudding user response:

Directly in the spreadsheet file don't fill in more easily?
You can directly copy and paste, easier,

CodePudding user response:

The
11 references, the wind is not just reply:
directly in the spreadsheet file don't fill in more easily?
Can directly copy, paste, easier,

Itself has a large piece of wood are above format is good, hand wipe, some thinking of electronic energy saving

CodePudding user response:

references 9 f glen30 response:
better use nested form:
Create a new form, assuming the formA, inside a goup, put 6 textbox, in this form to write a few public function, such as clean up all the textbox, get the value, etc.
In the main form to formA nested in the above form, and then loop operation:
After filling the access to content, can call formA removal method, input again

Form the use of nested method may refer to:
https://developer.51cto.com/art/201001/179552.htm

Ok, I see, thanks

CodePudding user response:

refer to three kilometers everyday 5 floor response:

Such a GroupBox it's about more than 190, and then in the textbox six, count down to more than 1000
Then I save the input to the text in it, is a dynamic has become


nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull