creating a matrix

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Killer42
    Recognized Expert Expert
    • Oct 2006
    • 8429

    #16
    Originally posted by dr3amxstar
    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 :

    HKSEVAHRFKDLGRR N
    LLLHHHHHHHLLLHH HH

    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?

    Comment

    • dr3amxstar
      New Member
      • May 2007
      • 55

      #17
      Originally posted by Killer42
      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?

      Comment

      • Killer42
        Recognized Expert Expert
        • Oct 2006
        • 8429

        #18
        Originally posted by dr3amxstar
        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 "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

        Comment

        • dr3amxstar
          New Member
          • May 2007
          • 55

          #19
          Originally posted by Killer42
          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 "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
          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

          Comment

          • Killer42
            Recognized Expert Expert
            • Oct 2006
            • 8429

            #20
            Originally posted by dr3amxstar
            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...

            [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

            • dr3amxstar
              New Member
              • May 2007
              • 55

              #21
              Originally posted by Killer42
              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...

              [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]
              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

              Comment

              • dr3amxstar
                New Member
                • May 2007
                • 55

                #22
                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

                • dr3amxstar
                  New Member
                  • May 2007
                  • 55

                  #23
                  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

                  Comment

                  • dr3amxstar
                    New Member
                    • May 2007
                    • 55

                    #24
                    Code:
                    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?

                    Comment

                    • Killer42
                      Recognized Expert Expert
                      • Oct 2006
                      • 8429

                      #25
                      Originally posted by dr3amxstar
                      ...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.

                      Comment

                      • Killer42
                        Recognized Expert Expert
                        • Oct 2006
                        • 8429

                        #26
                        Originally posted by dr3amxstar
                        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.

                        Comment

                        • dr3amxstar
                          New Member
                          • May 2007
                          • 55

                          #27
                          Originally posted by Killer42
                          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?

                          Comment

                          • Killer42
                            Recognized Expert Expert
                            • Oct 2006
                            • 8429

                            #28
                            Originally posted by dr3amxstar
                            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...

                            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 dr3amxstar
                            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.

                            Comment

                            • dr3amxstar
                              New Member
                              • May 2007
                              • 55

                              #29
                              Originally posted by Killer42
                              Yes.

                              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
                              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?

                              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

                              • Killer42
                                Recognized Expert Expert
                                • Oct 2006
                                • 8429

                                #30
                                [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

                                Working...