Incorrect results calculated from MSFlexGrid

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Mas Juliza Alias
    New Member
    • Aug 2010
    • 67

    Incorrect results calculated from MSFlexGrid

    hi, i use codes from Guido Geurs "Read and display specific data_v5.3.zip" from my previous thread below:
    http://bytes.com/topic/visual-basic/answers/896473-read-display-specific-data-text-file-into-listbox-using-vb-6-a#post3621111

    the data used is "Datum_0.tx t" but the results in Form_Calculate are incorrect (see attachment). they should be 0.0, 41.0, 92.9, 157.0, 234.5, 326.7. i don't know what was wrong. Guido Geurs, i really need your help here... thank you.
    Attached Files
  • Guido Geurs
    Recognized Expert Contributor
    • Oct 2009
    • 767

    #2
    I'm using VB6 SP6 on XP SP3.
    Is it possible to attach Your compilation of the program in Bytes so I can do a test on my PC and see of I also get the wrong results?

    Is it possible to do a test on an other PC with XP ?

    Can You set a breakpoint in the program on the calculation and watch what is happening with the values of "Val(ARRAYDATA( ARRAYDATAidx - 1).CUTVOL" and "Val(.TextMatri x(ARRAYDATAidx - 1, 1))" ?

    Comment

    • Mas Juliza Alias
      New Member
      • Aug 2010
      • 67

      #3
      i'm using Vista. is that the problem?how if there are users of this program using Vista. will they get the wrong results though? i just use the program from your last attached file from previous thread. i am not yet compile it with my program since i got the incorrect results.

      the problem is all PCs in this room are using Vista. but if that is the real problem i'll find PC with XP from outside.

      i am sorry that i don't familiar with this breakpoint. i read through about breakpoint from books and try to set it in the program but somehow i don't get what to see from it. can you explain about it in simpler words? sorry for my limited knowledge.

      Comment

      • Guido Geurs
        Recognized Expert Contributor
        • Oct 2009
        • 767

        #4
        Attached is a document, explaining the use of Breakpoint(s).
        Attached Files

        Comment

        • Guido Geurs
          Recognized Expert Contributor
          • Oct 2009
          • 767

          #5
          I have done some tests in Vista and I have also the bad results.
          It's solved when You change the code from "Val" to "CSng" in the calculation.

          Code:
                   MSFlexGrid1.AddItem ARRAYDATA(ARRAYDATAidx).DEPTH1 & vbTab & _
                      CStr(Format(CSng(ARRAYDATA(ARRAYDATAidx - 1).CUTVOL) + _
                      CSng(.TextMatrix(ARRAYDATAidx - 1, 1)), "#.0"))

          Comment

          • Mas Juliza Alias
            New Member
            • Aug 2010
            • 67

            #6
            thank you for the explanation of breakpoints. it is much understandable than from the books!

            i have changed the Val to CSng. it does solve the incorrect numbers but they are not in the form that they should be. the answer in Calculation form appears
            0.0
            410,0
            929,0
            1570,0
            2345,0
            3267,0

            where they should be
            0.0
            41.0
            92.9
            157.0
            234.5
            326.7

            how can we fix this? by the way, can you briefly explain the different between using Val and CSng? how can CSng solve the incorrect answers?

            thank you for your help...

            Comment

            • Guido Geurs
              Recognized Expert Contributor
              • Oct 2009
              • 767

              #7
              When the string "41.0" is interpreted as 410 then it means that the decimal symbol DOT isn't recognized as border between units and decimals in the CSng() function.
              The "decimal simbol" is different in the "Regional and Language Options" and the data in the document.
              See attached GIF files Region1.gif and Region2.gif.
              How to modify: see GIFs Region3.gif and Region4.gif or build in the program a function with Replace(...) so the user can change the DOTs to COMMAs and vice versa.
              I have also searched the internet and found a lot of calls of users who had problems with VB6 on Vista.
              Maybe it's better to change to VB.net if all the users are on Vista ?

              Comment

              • Mas Juliza Alias
                New Member
                • Aug 2010
                • 67

                #8
                i am sorry but you have not attached any file in your post. i can't find the GIF files you mentioned.
                Last edited by Mas Juliza Alias; Dec 6 '10, 02:49 AM. Reason: spelling

                Comment

                • Mas Juliza Alias
                  New Member
                  • Aug 2010
                  • 67

                  #9
                  i changed the decimal symbol from COMMA to DOT in the Regional and Language Option and i get the number form that i needed!! thanks to YOU! :)

                  Comment

                  • Guido Geurs
                    Recognized Expert Contributor
                    • Oct 2009
                    • 767

                    #10
                    Sorry, here they are.
                    Instead of always changing the regional setting, it's also possible to let the user change the data in the list with a command button with a For...next and the function Replace().


                    Code:
                    Private Sub ComRegional_Click()
                    Dim ROWidx As Integer
                    Dim COLidx As Integer
                       With MSFlexGrid1
                          For ROWidx = 1 To .Rows - 1
                             For COLidx = 0 To .Cols - 1
                                If .TextMatrix(ROWidx, COLidx) <> vbNullString Then
                                   .TextMatrix(ROWidx, COLidx) = Replace(.TextMatrix(ROWidx, COLidx), ".", "C")
                                   .TextMatrix(ROWidx, COLidx) = Replace(.TextMatrix(ROWidx, COLidx), ",", ".")
                                   .TextMatrix(ROWidx, COLidx) = Replace(.TextMatrix(ROWidx, COLidx), "C", ",")
                                End If
                             Next
                          Next
                       End With
                    End Sub
                    Attached Files

                    Comment

                    Working...