Computing.Net > Forums > Programming > Array subtraction in VB.NET

Array subtraction in VB.NET

Reply to Message Icon

Original Message
Name: AJJ
Date: August 22, 2004 at 12:25:27 Pacific
Subject: Array subtraction in VB.NET
OS: Windows XP
CPU/Ram: Athlon 2000XP
Comment:

Hi folks,

Quick question for all you Visual Basic.NET developers - is it possible to read in number values from two seperate text files into two seperate arrays and subtract the two array values from each other, and output these values to a text file.

Conceptually:

i.e. arrayoutput(index) = array1input(index) - array2input(index)

where index value = 0 to arraylimit-1

If it IS possible (and I believe it must be), could someone point me in the right direction - I've tried numerous different ways, but I think I might be making things too difficult for myself.

Thanks in advance.

AJ


Report Offensive Message For Removal


Response Number 1
Name: elric
Date: August 23, 2004 at 08:08:01 Pacific
Reply: (edit)

G'day,

I think that you have already written the psuedo code yourself.
You could try something like this:
DIM array1[SizeOfArray]
DIM array2[SizeOfArray]
DIM arrayout[SizeOfArray]

FOR x = 0 to SizeOfArray ;(arraylimit-1)
arrayout[x]=array1[x]-array2[x]
next x

Not sure if that is exactly syntactically correct for VB.NET but you get the idea I hope.
regards,
Elric


Report Offensive Follow Up For Removal

Response Number 2
Name: BasicDosHlp
Date: August 23, 2004 at 19:15:43 Pacific
Reply: (edit)


'' The below code is basic code it can be run in Q basic as a dos command.exe
" or from a Visual Basic command button click
'''Copy and paste it into a text file to view it properly
'' in Visual Basic with the use of text boxes and variables the data can be sent to the files from user input
''' but for now it is a simple display of working with text files

''First create two text files and put a column,list of numbers in them say 10 random numbers in each file like this
10
2
45
35
etc...

name them .... File1.txt and File2.txt
save them in the folder that the program is being created in or in the C: root if in the C\: root
the "C:\File1.txt" path must be fully named

''(paste the below code into a command click operation )


Close '''Precaution close all open files

Open "File1.txt" for input as #1 ''Opens the existing file for reading
Open "File2.txt" for input as #2 ''Opens the existing file for reading
Cpen "File3.txt" for output as #3 ''Opens the existing file for writing,
''Output will create the file if it does not exist will overwrite it if it does exist
do '''start of loop
' below code Places data from text file in the variables in temporary RAM memory as variable copya and copyb
Input #1, copya ''''''copy info from first line of File1
Input #2, copyb '''copy info first line of File2

copyc= copya+copyb ''add 2 variables create third variable
write #3, copyc ''''writes the variable data to the first line "file3.txt

Loop until eof(1)=true or eof(2)=true ''numbers are taken from the text files one row at a time
" until the end of file is reached then the loop is exited

Close '''close all open files
End


My Page has many quick explainations of basic commands
Feel free to contribute Or enlighten me with code examples that are not on my page
I am particularly interested in learning hardware periph


Report Offensive Follow Up For Removal







Use following form to reply to current message:

   Name: From My Computing.Net Settings
 E-Mail: From My Computing.Net Settings

Subject: Array subtraction in VB.NET

Comments:

 


  Homepage URL (*): 
Homepage Title (*): 
         Image URL: 
 
Data Recovery Software




Have you ever used OpenOffice?

Yes, as my main suite.
Yes, occationally.
Yes, but only once.
No, never.


View Results

Poll Finishes Today.
Discuss in The Lounge