Computing.Net > Forums > Programming > Visual Basic: Array

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Visual Basic: Array

Reply to Message Icon

Name: jonase
Date: September 9, 2004 at 17:43:15 Pacific
OS: XP
CPU/Ram: 384 MB
Comment:

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




Sponsored Link
Ads by Google

Response Number 1
Name: StuartS
Date: September 10, 2004 at 03:43:20 Pacific
Reply:

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


0

Response Number 2
Name: jonase
Date: September 10, 2004 at 05:05:24 Pacific
Reply:

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



0

Response Number 3
Name: wizard-fred
Date: September 10, 2004 at 08:58:52 Pacific
Reply:

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 n

Simplest output but might be formatted differently depending upon how it is being read or being subsequently processed.
close #1


0

Response Number 4
Name: jonase
Date: September 10, 2004 at 18:36:02 Pacific
Reply:

Thanks Wizard-fred, I am going to do a trial and run and see how it goes!

jonase


0

Response Number 5
Name: jonase
Date: September 11, 2004 at 20:58:26 Pacific
Reply:

Hi

May I know what's "x$" meant? - jonase


0

Related Posts

See More



Response Number 6
Name: wizard-fred
Date: September 11, 2004 at 23:54:07 Pacific
Reply:

x$ = variable is of type string

Sorry but I don't normally program in VB. Since you are inputting into a text box.


0

Response Number 7
Name: jonase
Date: September 12, 2004 at 02:04:49 Pacific
Reply:

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 double

Input(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 Sub

Private 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....16

hmmm....it doesn't seems to work..


0

Response Number 8
Name: wizard-fred
Date: September 12, 2004 at 08:14:47 Pacific
Reply:

You subs should not be in the loop.

What do you get saved?

Array can be public.



0

Response Number 9
Name: basicdos
Date: September 16, 2004 at 12:36:48 Pacific
Reply:

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

For i = 1 To 4

Yourarray(RW, CLM) = TextBox1(i).Text
RW = RW + 1

Next
If CLM < 4 Then GoTo arrayfull

RW = 0
CLM = CLM + 1
GoTo nextcolumn


: arrayfull

End Sub



0

Response Number 10
Name: basicdos
Date: September 16, 2004 at 17:40:15 Pacific
Reply:

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 1

txtBxNum = 1 'set 1rst textbox
: nextcolumn 'a return label runs 4 times

For 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
Next

If CLM < 4 Then GoTo arrayfull
'check if 4th column was done then end

RW = 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 read

End Sub



0

Response Number 11
Name: jonase
Date: September 20, 2004 at 07:24:15 Pacific
Reply:

Thanks for the help, everyone!


0

Sponsored Link
Ads by Google
Reply to Message Icon

The Regulars CrystalReport's tooltip !



Post Locked

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


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: Visual Basic: Array

visual basic calculator www.computing.net/answers/programming/visual-basic-calculator/9776.html

Visual Basic (Vertical Scroll Bar) www.computing.net/answers/programming/visual-basic-vertical-scroll-bar-/1248.html

List Databses is Visual Basic 6 www.computing.net/answers/programming/list-databses-is-visual-basic-6/15612.html