Originally posted by dr3amxstar
creating a matrix
Collapse
X
-
Originally posted by Killer42I 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 was also thinking of using streamreader so that i am able to store each byte in array. is there other alternative as well?Comment
-
Originally posted by dr3amxstaryes 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?
One important concept to keep in mind is to "encapsulat e" 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 languageComment
-
Originally posted by Killer42I 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 "encapsulat e" 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
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 bytesComment
-
Originally posted by dr3amxstarI 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
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...
[CODE=vb]
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[/CODE]Comment
-
Originally posted by Killer42Sure!
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...
[CODE=vb]
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[/CODE]
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 zeroComment
-
Code: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?Comment
-
OkAy this part works! Now i am going to move on to the automatic loading of files after the program finish reading one file :DComment
-
Code:Dim FileName As String FileName = Dir("C:\*.*") Do While FileName <> "" Debug.Print FileName FileName = Dir Loop
Comment
-
Originally posted by dr3amxstar...Hmm .. i would like to ask.. what does the line FileName = Dir Does?
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.Comment
-
Originally posted by dr3amxstarOkAy 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 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.Comment
-
Originally posted by Killer42If 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?Comment
-
Originally posted by dr3amxstarHmm 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?
The sample loop that I coded could be read like this...
Code: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
Originally posted by dr3amxstarIts quite a silly question but am i able to store the filename in array?
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.Comment
-
Originally posted by Killer42Yes.
The sample loop that I coded could be read like this...
Code: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
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.
Code: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
Comment
-
[CODE=vb]readerVar = IO.File.OpenTex t("D:\project1\ ANN\File(1)")[/CODE]should be...
[CODE=vb]readerVar = IO.File.OpenTex t("D:\project1\ ANN\" & File(1))[/CODE]
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.Comment
Comment