Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
Hi,
I have a user interface that contains 4x4 matrix (ie. 16 text boxes). Each text box will ask the user to key in a floating point number (eg. 0.25). May I know what's the code like so that I can save these floating values into an array and save this array in a .txt file?
Thanks in advance.
jonase

How you actually do it depends on how the text boxes are created.
Are they 16 individual boxs, Tex1, Test2, Text3, etc. Foure arrays of four text boxes r a single array of 16 text Boxes.
If the boxes are in a control array you can use the Join command to combine them into a single string variable. You then uses its companion, Split to split the string into its individual part.
Or you could just save the contents of each individual box into succsesive records.
Look up Open to see how to create and open a text file and Write to save your values.
Stuart

HI Stuart,
it is a single array of 16 text boxes.
What I meant is when I enter a value (eg, 0.323) in textbox01, it will save into Array[0],and when I enter a value (eg, 0.479) in textbox02, this value will save into Array[1]...etc.and in the .txt file, it should look like this (16 of them):
0.323 0.479 ... etc
jonase

Declare an Array(16) Single or Double
Input(n) x$
Array(n) = val(x$)
open "file.txt" for output as #1
for n = 1 to 16
print #1, Array(n);
next nSimplest output but might be formatted differently depending upon how it is being read or being subsequently processed.
close #1

x$ = variable is of type string
Sorry but I don't normally program in VB. Since you are inputting into a text box.

HI Wizard-fred,
I am just having trouble on how to implement
the code because it seems like I have to declare this array globally (Public):I am not sure the code is right or wrong...
=========================================
Public arrayAC(16) as doubleInput(n) x$
Array(n) = val(x$)open "file.txt" for output as #1
for n = 1 to 16
Private Sub Text1_Change() //Text box 1 will store eg, 0.333 into arrayAC(1)print #1, arrayAC(n);
next n
Close #1
End SubPrivate Sub Text2_Change() //Text box 2 will
store eg, 0.258 into arrayAC(2)print #1, arrayAC(n);
next n
Close #1
End Sub
=========================================
I just want each text box's data store into
arrayAC 1,2,3....16hmmm....it doesn't seems to work..

the below code will loop until all sixteen array elements are filled form the sixteen textboxes that were created as a "textbox array"
you might have to adjust the start and finnish numbers of the array row "RW" and columns "CLM" (to whether they start at zero or one)Private Sub Command1_Click()
RW = 0
CLM = 1
: nextcolumnFor i = 1 To 4
Yourarray(RW, CLM) = TextBox1(i).Text
RW = RW + 1Next
If CLM < 4 Then GoTo arrayfullRW = 0
CLM = CLM + 1
GoTo nextcolumn
: arrayfullEnd Sub

Sorry didnt account for all the text boxes
Private Sub Command1_Click()
RW = 0 'set array row element to 0
CLM = 1 'set array column element to 1txtBxNum = 1 'set 1rst textbox
: nextcolumn 'a return label runs 4 timesFor i = 1 To 4 'each column has 4 rows
Yourarray(RW, CLM) = TextBox1(txtBxNum).Text
RW = RW + 1 'stay in column move down a row
txtBxNum = txtBxNum +1 'increment next text Box
NextIf CLM < 4 Then GoTo arrayfull
'check if 4th column was done then endRW = 0 'Reset to top of array row
CLM = CLM + 1 'increment next array column
GoTo nextcolumn 'go back to for next loop
: arrayfull 'label jump after 4th column is readEnd Sub

![]() |
The Regulars
|
CrystalReport's tooltip !
|

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