Hi.. Im new to visual basic 2005 express edition and need some help. I am currently doing a project on developing Artifical Neural Network and is kind of stuck
First of all, i need to store values from 3 textbox into a matrix and then multiply it with another matrix ( Standard number). Can anyone tell me how do i go about doing it?
Thanks!
50 5611
There may be better ways, but the simplest would be to store them in an array, then use a loop to run through the array and do the multiplication. For more than one dimension, just use nested loops.
There may be better ways, but the simplest would be to store them in an array, then use a loop to run through the array and do the multiplication. For more than one dimension, just use nested loops.
Hihi thanks for the help! I did thought of arrays too but im dealing with matrix size of up to 40 x 273. Do you mind given me an example of how to create a array of more then one dimension using nested loops?
- Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
-
Dim myarray(0 To 39, 0 To 272) As Long
-
Dim lngcounter&, x&, y& ' & means ' as long'
-
-
'set values with value of counter
-
For x = 0 To 39
-
For y = 0 To 272
-
myarray(x, y) = lngcounter
-
lngcounter = lngcounter + 1
-
Next 'y
-
Next 'x
-
-
-
'print out values in array
-
For x = 0 To 39
-
For y = 0 To 272
-
Debug.Print("x" & x & "," & "y" & y & "=" & myarray(x, y))
-
Next 'y
-
Next 'x
-
-
-
'multiply two values
-
Debug.Print(myarray(20, 20) & " * " & myarray(30, 30) & "=" & myarray(20, 20) * myarray(30, 30))
x0,y0=0
x0,y1=1
x0,y2=2
x0,y3=3
.....
x39,y270=10917
x39,y271=10918
x39,y272=10919
5480 * 8220=45045600
Thanks Dan.
I'd just like to point out that the type declaration characters like "&" are basically the old way of doing it, and generally not recommended. "As Long" makes for code that's much easier to read.
Thanks Dan.
I'd just like to point out that the type declaration characters like "&" are basically the old way of doing it, and generally not recommended. "As Long" makes for code that's much easier to read.
Yeah but I don't like typing it multiple times and I did include what it meant :)
Yeah but I don't like typing it multiple times and I did include what it meant :)
Fair enough.
I wasn't correcting you, it was just meant as a bit of a heads-up to the OP. Which way you do it is pretty much a matter of personal preference, as long as they're both supported. I think we can safely assume that the results are exactly the same either way.
- Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
-
Dim myarray(0 To 39, 0 To 272) As Long
-
Dim lngcounter&, x&, y& ' & means ' as long'
-
-
'set values with value of counter
-
For x = 0 To 39
-
For y = 0 To 272
-
myarray(x, y) = lngcounter
-
lngcounter = lngcounter + 1
-
Next 'y
-
Next 'x
-
-
-
'print out values in array
-
For x = 0 To 39
-
For y = 0 To 272
-
Debug.Print("x" & x & "," & "y" & y & "=" & myarray(x, y))
-
Next 'y
-
Next 'x
-
-
-
'multiply two values
-
Debug.Print(myarray(20, 20) & " * " & myarray(30, 30) & "=" & myarray(20, 20) * myarray(30, 30))
x0,y0=0
x0,y1=1
x0,y2=2
x0,y3=3
.....
x39,y270=10917
x39,y271=10918
x39,y272=10919
5480 * 8220=45045600
Hihi Thanks alot for all the help! I used just a single dimension previously until i saw ur code and found out that its better. But may i know what is the difference between one dimension and 2 dimension?
Hihi Thanks alot for all the help! I used just a single dimension previously until i saw ur code and found out that its better. But may i know what is the difference between one dimension and 2 dimension?
Well, it's just like the difference between a list and a grid. In a one-dimensional array each element is identified by one index. In a two-dimensional array, each is identified by two indices. So any time you have a series of values which are dependent on two things (such as an X and Y coordinate), a two-dimensional array may be a convenient way to store them.
It is usual to think of, and graphically represent, a two-dimensional array as a square, with coordinates like those used in a street directory map, or on a computer screen, or a spreadsheet. A three-dimensional array is typically shown as representing a position within a cube. But in fact you can have pretty much any number of dimensions in an array - they just get harder to visualise, the more you have.
Thanks to all of the help given , i have been able to draft out the body for my artificial neural network. But the problem i encountered now is how to feed in inputs from files to my program automatically. I have 13 files each looking like this
HKSEVAHRFKDLGEENFKALVLIAFAQYLQQCPFEDHVKLVHKSEVAHRF KDLGEENFKALVLIAFAQYLQQCP -> Input
LLLHHHHHHHHHHHHHHHHHHHHHHHHHHLLLLLHHHHHHHLLLHHHHHH HHHHHHHHHHHHHHHHHHHHLLLL -> desired output
HKSEVAHRFKDLGEENFKALVLIAFAQYLQQCPFEDHVKLVHKSEVAHRF KDLGEENFKALVLIAFAQYLQQCP -> Input
LLLHHHHHHHHHHHHHHHHHHHHHHHHHHLLLLLHHHHHHHLLLHHHHHH HHHHHHHHHHHHHHHHHHHHLLLL -> desired output
(whole pages full of sets of 2 lines)
This are my training sets
The alphabets are amino acid and are to be converted to 21 bits using sparse code. I have to create a window size of 13 ( input is 13 at one time), where by the desired output of the middle amino acid will be used for calculation in the middle of the program.
How do i go about to let my program automatically load the file(total of 13 such files) from my computer drive, make it window slide 13 at a time and i will take the desired output of the middle of the 13 inputs( convert all the sparse coding for processing). *6 x will have to be included at the start so that the first alphabet can be at the middle. Should i store all this is a 2 dimensional array? Is this confusing?
...Is this confusing?
Yes!
Sorry, but I got completely lost.
I'm having great difficulty understanding the goal. But from what I have seen, if we can get past that, I'd say the actual code will be fairly simple.
Yes!
Sorry, but I got completely lost.
I'm having great difficulty understanding the goal. But from what I have seen, if we can get past that, I'd say the actual code will be fairly simple.
Haha i also dont know what i am blabbering. Maybe to simplify :
1) how do i read files from my directory on my computer to the program?
2) Does the program reads line by line? How do i make it read the second line or third automatically after the first line is completed
3) Is there a code that actually enable the program to open and read another new file after it is done with the current file.
3) is there a function that does sliding from one word to another? because at any one time i only want 13 alphabets from that long string and after one loops it moves to the next alphabet like this :
For every 13 alphabet in the first row ( first line)(store all 13 in array), i also want the number 7 alphabet out of the 13 alphabet in the second row (second line). thats why i have to process one by one because in one loop there can be only one desired output(alphabets in second row) and 13 inputs( alphabets in first row)
Thanks a thousand!
Haha i also dont know what i am blabbering. Maybe to simplify :
1) how do i read files from my directory on my computer to the program?
2) Does the program reads line by line? How do i make it read the second line or third automatically after the first line is completed
3) Is there a code that actually enable the program to open and read another new file after it is done with the current file.
3) is there a function that does sliding from one word to another? because at any one time i only want 13 alphabets from that long string and after one loops it moves to the next alphabet like this :
<img>
For every 13 alphabet in the first row ( first line)(store all 13 in array), i also want the number 7 alphabet out of the 13 alphabet in the second row (second line). thats why i have to process one by one because in one loop there can be only one desired output(alphabets in second row) and 13 inputs( alphabets in first row)
Thanks a thousand!
Hm... well, I feel I'm gradually progressing toward an understanding. Certainly the file handling sounds simple enough.
Actually, this is good timing. I've just recently put a couple of samples in the Articles section that show how to read a text file. One reads line by line, the other reads it in one go, into one big string. Check out the index at the top of the section. Perhaps you can give me some feedback on whether the code samples are actually any use. It's hard for me to judge, since I wrote them.
Also, as far as looping through the files, there are a couple of techniques you can use.
There's the built-in Dir() function. When you pass it a string, it will return the name of the first file that matches. Pass it nothing, it will look for the next one. For example, this code displays the names of all files in the C: drive root directory (though hopefully there wouldn't be very many. - Dim FileName As String
-
FileName = Dir("C:\*.*")
-
Do While FileName <> ""
-
Debug.Print FileName
-
FileName = Dir
-
Loop
Then there is FilesystemObject. To use this, you must add a reference to Microsoft Scripting Runtime to your project. And it's a little more complex to work with. But it offers a lot of useful functionality when working with drives, folders and files.
As for processing one file after another, the above Do While loop could just as easily be calling a routine to do something with the files, rather than just printing their names to the debugging window. (One thing to keep in mind with this sort of technique is that Dir returns only the filename, no path.)
I'm still having some trouble with the "alphabet" thing. For starters, what is it that you are referring to as "an alphabet"? When you say, for instance, " For every 13 alphabet in the first row" do you mean for every 13 characters?
I'm still having some trouble with the "alphabet" thing. For starters, what is it that you are referring to as "an alphabet"? When you say, for instance, "For every 13 alphabet in the first row" do you mean for every 13 characters?
Haha all this seems like stranger to me but i will go and learn! Really thanks for your advice and thanks for guiding me to the right path!
Haha i think "alphabets" is the same as characters? Because in my notepad it does not contain normal words or sentences. It is filled with this :
HKSEVAHRFKDLGRRN
LLLHHHHHHHLLLHHHH
This is not in any wierd language but just that each alphabets represent an amino acid. I will have to program it such that it takes in 13 "alphabets" or characters at one time, then during the second loop it will shift one alphabets to the right and take in another 13 characters. haha do i make sense?
Hi i went to the code you posted. I am quite slow at understanding so need some help there. Correct me if im wrong, does it LineNo = LineNo + 1 means that it automatically gets the next line instead of keep typing a lot of these :
StrVar = readerVar.ReadLine
StrVar = readerVar.ReadLine
What is FileNo = FreeFile?
Where is the part in the code that allows me to put in the directory or file name to be included in my program. Hope what i say make sense!
Haha all this seems like stranger to me but i will go and learn! Really thanks for your advice and thanks for guiding me to the right path!
Haha i think "alphabets" is the same as characters? Because in my notepad it does not contain normal words or sentences. It is filled with this :
HKSEVAHRFKDLGRRN
LLLHHHHHHHLLLHHHH
This is not in any wierd language but just that each alphabets represent an amino acid. I will have to program it such that it takes in 13 "alphabets" or characters at one time, then during the second loop it will shift one alphabets to the right and take in another 13 characters. haha do i make sense?
I guess that's reasonably straightforward. You want to deal with the first 13 bytes (might be easier if we call them that) from the record. Then the 2nd to 14th bytes. Then the 3rd to 15th bytes, and so on. Correct?
I guess that's reasonably straightforward. You want to deal with the first 13 bytes (might be easier if we call them that) from the record. Then the 2nd to 14th bytes. Then the 3rd to 15th bytes, and so on. Correct?
yes yes thats it! and after that line ended the program will automatically move to the next line.
I was also thinking of using streamreader so that i am able to store each byte in array. is there other alternative as well?
yes yes thats it! and after that line ended the program will automatically move to the next line.
I was also thinking of using streamreader so that i am able to store each byte in array. is there other alternative as well?
I tend to just use the built-in statements such as Open and Line Input# to read a text file line-by-line. However, that's because I've never learned how to work with things like streamreader. So I can't really advise you which way to go.
One important concept to keep in mind is to "encapsulate" or "modularise" your code where possible. In other words, keep the parts of your code fairly independent of each other, so they can be easily replaced.
For example, if you set up your code to read a file line by line, ideally it should pass each line to a separate routine which does the work with them. The inner workings shouldn't be too tightly intertwined with the file-reading code. That way, you can easily change your mind about how to read the file, or how to do the processing of the lines, without affecting the rest of the code.
Unfortunately I don't have the time right now, or I'd have a look at how streamreaders work.
In any case, as long as it provides what you want, which way you go is really a matter of personal preference.
P.S. Definition - alphabet: a character set that includes letters and is used to write a language
I tend to just use the built-in statements such as Open and Line Input# to read a text file line-by-line. However, that's because I've never learned how to work with things like streamreader. So I can't really advise you which way to go.
One important concept to keep in mind is to "encapsulate" or "modularise" your code where possible. In other words, keep the parts of your code fairly independent of each other, so they can be easily replaced.
For example, if you set up your code to read a file line by line, ideally it should pass each line to a separate routine which does the work with them. The inner workings shouldn't be too tightly intertwined with the file-reading code. That way, you can easily change your mind about how to read the file, or how to do the processing of the lines, without affecting the rest of the code.
Unfortunately I don't have the time right now, or I'd have a look at how streamreaders work.
In any case, as long as it provides what you want, which way you go is really a matter of personal preference.
P.S. Definition - alphabet: a character set that includes letters and is used to write a language
I am really glad enough that you actually took some time off ur busy schedule to guide me along!
Points taken! But if i does it your way, when i read the line by line, is it possible to assign each bytes to array?
EFTGGRABC
assign E to array(0)
assign F to array(1)
assign T to array(2)
and so on till the 13th bytes
I am really glad enough that you actually took some time off ur busy schedule to guide me along!
Points taken! But if i does it your way, when i read the line by line, is it possible to assign each bytes to array?
EFTGGRABC
assign E to array(0)
assign F to array(1)
assign T to array(2)
and so on till the 13th bytes
Sure!
While there are certainly more sophisticated (and efficient) ways to do it, one very simple method is just to loop through, using Mid() function to retrieve each character from the string, and place it in the array. Quick sample... -
Dim S As String, L As Long
-
Dim Char(1 To 16) As String * 1 ' Or perhaps As Byte
-
S = "This is a string"
-
For L = 1 To 16
-
Char(L) = Mid$(S, L, 1)
-
Next
Sure!
While there are certainly more sophisticated (and efficient) ways to do it, one very simple method is just to loop through, using Mid() function to retrieve each character from the string, and place it in the array. Quick sample... -
Dim S As String, L As Long
-
Dim Char(1 To 16) As String * 1 ' Or perhaps As Byte
-
S = "This is a string"
-
For L = 1 To 16
-
Char(L) = Mid$(S, L, 1)
-
Next
Thanks! I think it should work but there is some errors:
Dim Char(1 To 16) As String* 1
When i debug, it says that Array lower bound can only be zero
So i change it to zero but this code
For L = 1 To 16
Char(L)=Mid$(S,L,1)
When i change to L = 0 To 16
It stated Start must be bigger then zero
- Public Class Form1
-
-
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
-
Dim source As String = "XXXXXXAEFGHIW"
-
Dim characters As String = _
-
"ACDEFGHIKLMNPQRSTVYWX"""
-
Dim sparse() As String = { _
-
"100000000000000000000", _
-
"010000000000000000000", _
-
"001000000000000000000", _
-
"000100000000000000000", _
-
"000010000000000000000", _
-
"000001000000000000000", _
-
"000000100000000000000", _
-
"000000010000000000000", _
-
"000000001000000000000", _
-
"000000000100000000000", _
-
"000000000010000000000", _
-
"000000000001000000000", _
-
"000000000000100000000", _
-
"000000000000010000000", _
-
"000000000000001000000", _
-
"000000000000000100000", _
-
"000000000000000010000", _
-
"000000000000000001000", _
-
"000000000000000000100", _
-
"000000000000000000010", _
-
"000000000000000000000"}
-
-
Dim result As New System.Text.StringBuilder
-
Dim counter As Integer
-
Dim position As Integer
-
-
For counter = 0 To 12
-
position = characters.IndexOf(Char.ToUpper( _
-
source.Chars(counter)))
-
-
result.AppendLine(sparse(position))
-
-
Next counter
-
-
Dim Line As String = (result.ToString())
-
-
Dim S As String, L As Long
-
Dim Numbers(0 To 272) As String
-
S = Line
-
For L = 1 To 272
-
Numbers(L) = Mid$(S, L, 1)
-
Next
-
-
End Sub
-
End Class
In this code, my purpose is to convert the bytes in "source" to their respective sparse codes accordingly to their characters.
After converting, i want to store each "binary" in the same array but i am not able to do so. Am i on the right track?
OkAy this part works! Now i am going to move on to the automatic loading of files after the program finish reading one file :D
- Dim FileName As String
-
FileName = Dir("C:\*.*")
-
Do While FileName <> ""
-
Debug.Print FileName
-
FileName = Dir
-
Loop
Hmm .. i would like to ask.. what does the line FileName = Dir Does?
...Hmm .. i would like to ask.. what does the line FileName = Dir Does?
If you call the Dir function with no arguments, it just keeps returning the next filename matching what you previously asked for. So when I ask for "C:\*.*" it will return the first file in the C:\ directory. Then each subsequent call to Dir with no arguments will return another file, until there are no more. When that happens, the condition While FileName <> "" causes us to drop out of the loop.
Keep in mind this is all VB6 code, and may not entirely match your version - I apologise for that, but it's the best I can do at the moment. Generally the concepts will be OK (I hope), but the details of syntax may vary.
OkAy this part works! Now i am going to move on to the automatic loading of files after the program finish reading one file :D
I'm glad to hear that (yes, I'm reading the thread in reverse order - sorry about that).
I couldn't follow your code, as it's in "Dotnetese". Or to put it another way, it's too advanced for me. :)
Guess it's about time I started updating to a later version.
If you call the Dir function with no arguments, it just keeps returning the next filename matching what you previously asked for. So when I ask for "C:\*.*" it will return the first file in the C:\ directory. Then each subsequent call to Dir with no arguments will return another file, until there are no more. When that happens, the condition While FileName <> "" causes us to drop out of the loop.
Keep in mind this is all VB6 code, and may not entirely match your version - I apologise for that, but it's the best I can do at the moment. Generally the concepts will be OK (I hope), but the details of syntax may vary.
Hmm does it mean with this code i am able to call out the file one at a time? Am i able to deal with one file first, and after i am done with this file (pass to sub routine and back)then proceed to another file whereby the program will do automatically?
Its quite a silly question but am i able to store the filename in array?
Hmm does it mean with this code i am able to call out the file one at a time? Am i able to deal with one file first, and after i am done with this file (pass to sub routine and back)then proceed to another file whereby the program will do automatically?
Yes.
The sample loop that I coded could be read like this... - Get the first filename matching "C:\*.*"
-
As long as we haven't run out of file names...
-
Print it
-
Get the next matching file name
-
End of Loop
Its quite a silly question but am i able to store the filename in array?
Sure. It's a string - you can do whatever you like with it.
In cases like these, the best way to go is to try it and see what happens. Play around with it, to get a feel for what you can do.
Yes.
The sample loop that I coded could be read like this... - Get the first filename matching "C:\*.*"
-
As long as we haven't run out of file names...
-
Print it
-
Get the next matching file name
-
End of Loop
Sure. It's a string - you can do whatever you like with it.
In cases like these, the best way to go is to try it and see what happens. Play around with it, to get a feel for what you can do.
Hi im sorry to keep bothering you! I used your code and it works ! Thanks a thousand. I have stored it in a array but the problem now is that i am unable to load it after i pass it to another line. Am i doing it the right way? - Public Class Form1
-
-
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
-
Dim FileName As String
-
Dim x As Integer = 0
-
Dim File(12) As String
-
FileName = Dir("D:\project1\ANN\*Chain*")
-
Do While FileName <> ""
-
-
File(x) = FileName
-
x += 1
-
FileName = Dir()
-
Loop
-
-
-
Dim readerVar As IO.StreamReader
-
Dim StrVar As String
-
Dim n As Integer
-
-
-
-
readerVar = IO.File.OpenText("D:\project1\ANN\File(1)")
-
-
StrVar = readerVar.ReadLine
- readerVar = IO.File.OpenText("D:\project1\ANN\File(1)")
should be... - readerVar = IO.File.OpenText("D:\project1\ANN\" & File(1))
The colour-coding in the VB code here shows why. In your code, the "File(1)" is simply part of the string, so you are trying to open a file which is actually called "File(1)". Chances are, this is not the correct name.
- readerVar = IO.File.OpenText("D:\project1\ANN\File(1)")
should be... - readerVar = IO.File.OpenText("D:\project1\ANN\" & File(1))
The colour-coding in the VB code here shows why. In your code, the "File(1)" is simply part of the string, so you are trying to open a file which is actually called "File(1)". Chances are, this is not the correct name.
I tried and it works .. Thanks A Lot!! Now there is progression in my program :D Thanks for your time and guidance!!
hey may of already been suggested but u may want to look into a 3d array,
dim array(x, y, z) as long 'where x and y= dimensions of your matrix, and z= how many matrixes you have, that way you can just multiply the planes of the 3d array nice and efficient, and only 1 array is used
hey may of already been suggested but u may want to look into a 3d array,
dim array(x, y, z) as long 'where x and y= dimensions of your matrix, and z= how many matrixes you have, that way you can just multiply the planes of the 3d array nice and efficient, and only 1 array is used
Thanks for that advice i will try it out! One last question! - Dim FileName As String
-
-
Dim File(12) As String
-
FileName = Dir("D:\project1\ANN\*Chain*")
-
Do While FileName <> ""
-
-
File(x) = FileName
-
x += 1
-
FileName = Dir()
-
-
Loop
-
-
-
-
Dim readerVar As IO.StreamReader
-
Dim source1, source2, Line1, Line2 As String
-
Dim n, i As Integer
-
Dim matrixA(0 To 273) As String
-
Dim Desired(0 To 3) As String
-
i = 0
-
-
-
For i = 0 To 12
-
-
readerVar = IO.File.OpenText("D:\project1\ANN\" & File(12))
-
-
Do While (readerVar.Peek <> -1)
-
-
source1 = readerVar.ReadLine
-
source2 = readerVar.ReadLine
-
source1 = ("XXXXXX" & source1 & "XXXXXX")
-
For n = 0 To (source1.Length - 13)
-
-
Line1 = source1.Substring(n, 13)
-
Line2 = source2.Substring(n, 1)
-
Sparsecode(Line1, matrixA)
-
SSE(Line2, Desired)
-
-
-
-
Next
-
-
Loop
-
-
Next
[Do While (readerVar.Peek <> -1)] --> Doesnt this line suppose to terminate the loop when it comes to the end of the file and have no more line to read? In my program it just went on reading the lines over and over again when i wanted it to open another new file when it has finish reading all the line in one file.
I'm going to let Killer answer your question because he is more familar with your code.
I just wanted to let you know that there is a Matrix Algebra package at http://www.codeproject.com/cs/librar...operations.asp. I just downloaded it and looked at the code, if you have two matrix objects A and B, then he has overloaded the * so that you can just code
Matrix C = A * B
This should help you when you get the I/O fixed up. --Sam
Thanks for the link, Sammy.
Unfortunately, I've never used IO.File.OpenText in my life. I work in VB, and unless I have a specific need to play with the FileSystemObject, I just use the built-in Open statement, then Line Input to grab each line, until EOF(filenum) = True.
I guess you need to double-check the doco on the Peek property. Don't overlook the possible significance of reading two lines between Peeks. A couple of things to keep in mind... - Perhaps the return value changes if you keep on reading, after hitting the end of the file? (This is why the two reads may be significant).
- Is it possible that the last line has no delimiter and this is confusing the ReadLine method?
I guess you need to double-check the doco on the Peek property. Don't overlook the possible significance of reading two lines between Peeks. A couple of things to keep in mind...- Perhaps the return value changes if you keep on reading, after hitting the end of the file? (This is why the two reads may be significant).
- Is it possible that the last line has no delimiter and this is confusing the ReadLine method?
Well, i read on on peek property and nothing was wrong about it. through trial and error, i actually removed this line For i = 0 To 12 and the it works. It stop repeating. But then came another problem. This line is suppose to enable my program to open the next file automatically once it is done with the previous file. Did i write my code wrongly?
.I just wanted to let you know that there is a Matrix Algebra package at http://www.codeproject.com/cs/librar...operations.asp. I just downloaded it and looked at the code, if you have two matrix objects A and B, then he has overloaded the * so that you can just code
Matrix C = A * B
This should help you when you get the I/O fixed up. --Sam
Thanks a thousand! Once im able to solve this part i will be able to move on to the body of my code. i actually started from the body and have used loops for matrix multiplication and it look quite wierd. I guess i will look into that. :D
I cleaned up your code. I have not figured out you input files, so this is not tested. See if this works better. -
' Get List of files
-
Dim FileName As String
-
Dim Files As List(Of String)
-
FileName = Dir("D:\project1\ANN\*Chain*")
-
Do While FileName <> ""
-
Files.Add(FileName)
-
FileName = Dir()
-
Loop
-
' Read files
-
Dim readerVar As IO.StreamReader
-
Dim source1, source2, Line1, Line2 As String
-
Dim n, i As Integer
-
Dim matrixA(0 To 273) As String
-
Dim Desired(0 To 3) As String
-
For Each FileName In Files
-
readerVar = IO.File.OpenText("D:\project1\ANN\" & FileName)
-
Do While (readerVar.Peek > -1)
-
source1 = readerVar.ReadLine
-
source2 = readerVar.ReadLine
-
source1 = ("XXXXXX" & source1 & "XXXXXX")
-
For n = 0 To (source1.Length - 13)
-
Line1 = source1.Substring(n, 13)
-
Line2 = source2.Substring(n, 1)
-
Sparsecode(Line1, matrixA)
-
SSE(Line2, Desired)
-
Next n
-
Loop
-
Next FileName
-
I cleaned up your code. I have not figured out you input files, so this is not tested. See if this works better. -
' Get List of files
-
-
FileName = Dir("D:\project1\ANN\*Chain*")
-
Do While FileName <> ""
-
Files.Add(FileName)
-
FileName = Dir()
-
Loop
I tried compiling but it stated Variable 'Files' is used before it has been assigned a value. A null reference exception could result at runtime.
I have 13 input files in my directory D:\project1 which i would like the program to read them automatically once the program is done with the previous file. I tried using arrays but it didnt work..
You forgot my line 3:
Dim Files As List(Of String)
- Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
-
' Get List of files
-
Dim FileName As String
-
Dim Files As List(Of String)
-
FileName = Dir("D:\project1\ANN\*Chain*")
-
Do While FileName <> ""
-
Files.Add(FileName)
-
FileName = Dir()
-
Loop
-
' Read files
-
Dim readerVar As IO.StreamReader
-
Dim source1, source2, Line1, Line2 As String
-
Dim n As Integer
-
Dim matrixA(0 To 273) As String
-
Dim Desired(0 To 3) As String
-
For Each FileName In Files
-
readerVar = IO.File.OpenText("D:\project1\ANN\" & FileName)
-
Do While (readerVar.Peek > -1)
-
source1 = readerVar.ReadLine
-
source2 = readerVar.ReadLine
-
source1 = ("XXXXXX" & source1 & "XXXXXX")
-
For n = 0 To (source1.Length - 13)
-
Line1 = source1.Substring(n, 13)
-
Line2 = source2.Substring(n, 1)
-
Sparsecode(Line1, matrixA)
-
SSE(Line2, Desired)
-
Next n
-
Loop
-
Next FileName
yup i did include all in but it told me that error
Sorry, my bad. Line 4 should be
Dim Files As New List(Of String)
After i change that line ,the program is able to compile but not able to run. It came up with this error at this line - Line2 = source2.Substring(n, 1)
error: object reference not set to an instance of an object.
What does it mean?
After i change that line ,the program is able to compile but not able to run. It came up with this error at this line - Line2 = source2.Substring(n, 1)
error: object reference not set to an instance of an object.
What does it mean?
Probably the second line is empty. When it fails, look at source2 and see what it contains. Also look at the FileName and then that file.
All my files have at least 2 lines. I added this line ListBox1.Items.Add(FileName) to check whether it is able to print all my file names but it resulted in this error - FileName = Dir("F:\Documents\ANN\*Chain*")
-
Do While FileName <> ""
-
-
Files.Add(FileName)
-
FileName = Dir()
-
ListBox1.Items.Add(FileName)
-
Loop
Error : AruguementNull Exception was unhandled.
value cannot be null
parameter name: item
You need to switch lines 5 and 6; on the last iteration FileName will be null.
You need to switch lines 5 and 6; on the last iteration FileName will be null.
Sorry for keep asking! I swop and its back to this problem
Line2 = source2.Substring(n, 1)
error: object reference not set to an instance of an object.
Sorry for keep asking! I swop and its back to this problem
Line2 = source2.Substring(n, 1)
error: object reference not set to an instance of an object.
- Check the file
- What is in source2
- What is len(source2)
- What is n
- Dim FileName As String
-
Dim Files As New List(Of String)
-
FileName = Dir("D:\project1\ANN\*Chain*")
-
Do While FileName <> ""
-
-
Files.Add(FileName)
-
ListBox1.Items.Add(Files)
-
-
FileName = Dir()
-
-
Loop
I run this code and got this as output
[Collection] - 13 of this
Is this the output i should get from the few lines?
oops.. I forgot to say a very big thank you for all the help given!!! Special Thanks to Killer42 and SammyB ! :D
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Ivan Voras |
last post by:
Is there a nice(r) way of creating a list of uniform values? I'm currently
using: list('0'*N), which makes a string and then chops it up into a list. I
need it to create a NxN matrix:
matrix = ...
|
by: Ben Ingram |
last post by:
Hi all,
I am writing a template matrix class in which the template parameters are
the number of rows and number of columns. There are a number of reasons
why this is an appropriate tradeoff for...
|
by: Tony Johansson |
last post by:
Hello Experts!!
I have two small classes called Intvektor and Matris shown below and a main.
Class Intvektor will create a one dimension array of integer by allocate
memory dynamically as you...
|
by: Bushido Hacks |
last post by:
I've come up with a good set of Matrix codes recently when I cam to a
road block. I would like to know if I should destroy an object to
create a new object with new dimmensions.
class Matrix{...
|
by: Darleen |
last post by:
I am seeking conceptual here on how to get started with a "3D Matrix"
in Access. We run a training center which holds multiple classes in
multiple cities at multiple times. So I need to create a...
|
by: Jan Callewaert |
last post by:
When compiling a library with the intel compiler icpc, I get the following
warning:
ld: warning: creating a DT_TEXTREL in object
This happens with icc-9.0.030 and ld-2.16.1. However, this...
|
by: tshad |
last post by:
I am trying to set up an Image authorization where you type in the value
that is in a picture to log on to our site.
I found a program that is supposed to do it, but it doesn't seem to work.
...
|
by: crescent_au |
last post by:
Hi all,
I'm doing some research online on creating php-based multi-level
marketing (MLM) system. It seems like a complicated system to build as
I need to create one from scratch. I'd like to...
|
by: John |
last post by:
Hi there,
I need to create a rectangle between two points so that I can check what
is inside it using Contains(). The problem I am having is how to make the
rectangle be able to cope with the...
|
by: victory2006 |
last post by:
i need help to make a board such as this:
-----------Col 0--Col 1--Col 2
Row 0------1------1--------0
Row 1------0------0--------1
Row 2------1------1--------1
(Please ignore the dashes,...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
| |