Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
After weeks of banging my head on my desk (not really) I've found some code that has me really close to getting a working program. Sample of code at bottom.
I'm making a program to write input to file for input to another program. I have the output working fine but there are other things to do.
I have 50+ lines like this
writer.WriteLine("{0,3}{1,20}", "1", TextBox1.Text)
and I'm wondering is there a way to increment the textbox number to enter all the textboxes into an array? Something like below, except have TextBox1.Text increment to TextBox2.Text and so on.Dim tbox(70) As Integer
Dim num As Integer
For num = 1 To 69
tbox(num) = TextBox1.Text
NextThe textboxes will have numbers entered in them and I would like to force each number to have 4 decimal places past the period. Some will have no period while others will have up to 4 decimal places already. Can you do this?
I would like to check if the textbox is empty before writing it to file, if it is empty I'd like to skip it. I would guess an if statement would work but how do I check if the texbox is empty?
Sample of my code:
Public Class TSMOD
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim writer As IO.StreamWriter = _
New IO.StreamWriter("input_data.txt")
writer.WriteLine("{0,3}{1,20}", "1", TextBox1.Text)
*repeat last line 50 or so times with the two #1's incrementing each line (yeah i know inefficient)*
writer.Close()
End Sub
End Class
Thanks for any help.I'm also going to be researching saving and opening this so everything doesn't have to be re entered each time. But that is for later

Well a quick search found me this
If TextBox1.TextLength > 0 Then
for seeing if the text box is empty.Lets see what else I can find before people post here.
--------
well I just found an easy way of formatting my numbers to 4 decimal places.
writer.WriteLine("{0,3}{1,20}", num, (x).ToString("f4"))
where num some number and x is the entered value which is formatted to have 4 decimal places--------
also I'm using a different if statement to check if something was entered in a textbox
If IsNumeric(tbox(num)) Then
since all the values are supposed to be numbers--------
P.S. if you don't understand any of this hopefully I can paste a completed program some day.
--------
yet another edit:
I got some help from somebody at work and got thisDim controlctl As Windows.Forms.Control
For num = 1 To 69
For Each controlctl In Me.Controls
If controlctl.Name = "TextBox" & CStr(num) Then
tbox(num) = controlctl.Text
End If
Next controlctl
Next
This searches for all textboxes then sets the one that has the number as num in it's name in the array tboxwow i'll have to check if I need help anymore. lol

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |