VB6 Msflexgrid to a .dat file

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • wilder1926
    New Member
    • Aug 2009
    • 5

    VB6 Msflexgrid to a .dat file

    Hello everybody.

    As a new member to vb6, I need your help to ajust a code that will transfer all grid data to a .dat file.

    Code:
    Dim MyFreeFile As Integer
    Dim icol As Integer
    Dim irow As Integer
    Dim MyString As String
    MyFreeFile = FreeFile
    Open "C:\Documents and Settings\All Users\Desktop\ord" For Output As MyFreeFile
    For irow = 1 To MSFlexGrid1.Rows - 1    'Start from top to bottom
        For icol = 0 To MSFlexGrid1.Cols - 1    'Start from left to Right
            MyString = MyString & MSFlexGrid1.TextMatrix(irow, icol) & _
                IIf((icol = MSFlexGrid1.Cols - 1), "", ",")     'Add value in mystring for each column in Flexgrid
        Next
        Print #MyFreeFile, MyString  'Print to notepad
        MyString = ""   'Reset MyString
    Next
    
    Close MyFreeFile
    Now, what's missing and i dont now how to do it is:

    msflexgrid exemple:
    Column 1 line 1 of Grid = "H"
    Column 2 line 1 of Grid = "A"
    Column 3 line 1 of Grid = "HOST"
    Column 4 line 1 of Grid = "08989" etc.

    Position in the .dat file:
    Column 1 line 1 of Grid = Position 1
    Column 2 line 1 of Grid = Position 2
    Column 3 line 1 of Grid = Position 3
    Column 4 line 1 of Grid = Position 9.

    At the end, the result would be
    "HAHOST 08989"


    How can i do this please?

    Thanks again
  • debasisdas
    Recognized Expert Expert
    • Dec 2006
    • 8119

    #2
    you want to write to which fie (location ) ?

    What is the error message with your code ?

    Comment

    • wilder1926
      New Member
      • Aug 2009
      • 5

      #3
      Actually, i don't have any error. But i have a txt file on my desktop and it transfer the msflexgrid data in that file.

      At this moment, it transfer like that:
      H,A,HOST,8989,, ,200908280700,2 00908281200,200 908280700,20090 8281200,03,,,,, ,COL,,,,,,,M,,, ,,,,,,,,,,,,,P, ,M03004005300,5 3.64,380.00,19, ,,,88,,,,,,
      But i want to change for something like this for example:

      HAHOST 8989 200908280700 200908281200 200908280700 200908281200 03 COL M P M03004005300 53.64 380.00 19 88
      Some thing that look like that.

      Comment

      • debasisdas
        Recognized Expert Expert
        • Dec 2006
        • 8119

        #4
        remove the , from your code

        Comment

        • wilder1926
          New Member
          • Aug 2009
          • 5

          #5
          it's done.

          Now i need to put each columns from the MSFlexgrid at the good position in the dat file.

          msflexgrid exemple:
          Column 1 line 1 of Grid = "H"
          Column 2 line 1 of Grid = "A"
          Column 3 line 1 of Grid = "HOST"
          Column 4 line 1 of Grid = "08989" etc.

          Position in the .dat file:
          Column 1 line 1 of Grid = Position 1
          Column 2 line 1 of Grid = Position 2
          Column 3 line 1 of Grid = Position 3
          Column 4 line 1 of Grid = Position 9.

          At the end, the result would be
          "HAHOST 08989"

          Comment

          • debasisdas
            Recognized Expert Expert
            • Dec 2006
            • 8119

            #6
            what exactly you mean by good position in the dat file.

            Comment

            • wilder1926
              New Member
              • Aug 2009
              • 5

              #7
              msflexgrid exemple:
              Column 1 line 1 of Grid = "H"
              Column 2 line 1 of Grid = "A"
              Column 3 line 1 of Grid = "HOST"
              Column 4 line 1 of Grid = "08989" etc.

              Position in the .dat file:
              Column 1 line 1 of Grid = Position 1 in the txt file
              Column 2 line 1 of Grid = Position 2 in the txt file
              Column 3 line 1 of Grid = Position 3 in the txt file
              Column 4 line 1 of Grid = Position 9 in the txt file

              At the end, the result would be:
              "HAHOST 08989"

              Comment

              • debasisdas
                Recognized Expert Expert
                • Dec 2006
                • 8119

                #8
                what is the output that you are getting now ?

                Comment

                • wilder1926
                  New Member
                  • Aug 2009
                  • 5

                  #9
                  With the code above, all value are one beside the other value, split by a ","

                  Comment

                  • debasisdas
                    Recognized Expert Expert
                    • Dec 2006
                    • 8119

                    #10
                    remove the , and add CHR(13) to the end of string.

                    Comment

                    Working...