Results 1 to 6 of 6

Thread: Dynamic array, loss of decimal point after redim

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Mar 2001
    Location
    The Netherlands
    Posts
    184

    Dynamic array, loss of decimal point after redim

    Hi all

    I have got a dynamic array declared as :

    public tmpChase() as single

    It is going to be a multidimensional array and the data is being read from a standerd "," (comma???) delimeted text file. I read the data using :

    VB Code:
    1. Nr = FreeFile
    2.     Open strOpen For Input As #Nr
    3.         Do While Not EOF(Nr)
    4.             'Array aanpassen
    5.            
    6.             ReDim Preserve tmpChase(MaxChannels, tmpMaxStep)
    7.            
    8.             For i = 0 To MaxChannels
    9.                 Input #Nr, Inputstring
    10.                 tmpChase(i, tmpMaxStep) = CSng(Inputstring)
    11.             Next i
    12.            
    13.             tmpMaxStep = tmpMaxStep + 1
    14.         Loop
    15.     Close #Nr

    so the code reads goes to the first line in the text file, reads al the values and then goes to the next line. Before it starts to read again the array is made bigger and i use Preserve because i want to keep the old data. No problems with the code so far and everything works alright.

    Except when the values that are being read contain a decimal point. When i check they array right after a field is being read then i get the correct answer (let''s say 1.5). But when i later on test again i loose the decimal value and only get 5. I think this has something to do with Redim Preserve. But they array has been declared as single, so it shouldn't be a problem

    Regards,

    per-i

  2. #2

    Thread Starter
    Addicted Member
    Join Date
    Mar 2001
    Location
    The Netherlands
    Posts
    184
    Hi, maybee found somthing...

    I am based in the Netherlands and we us a "," character for a decimal numbers. But in they text file I use the "." character for decimal numbers. Is there some way to assure that the value is being treated as a decimal number? I already tried Csng(Inputstring)

    regards,

    per-i

  3. #3
    Fanatic Member
    Join Date
    Dec 2003
    Posts
    703
    If the values are correct when you read them in, it's not an issue with the file..
    Last edited by azteched; Feb 12th, 2004 at 11:49 AM.
    an ending

  4. #4
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373
    Originally posted by per-i
    Hi, maybee found somthing...

    I am based in the Netherlands and we us a "," character for a decimal numbers. But in they text file I use the "." character for decimal numbers. Is there some way to assure that the value is being treated as a decimal number? I already tried Csng(Inputstring)

    regards,

    per-i
    using . or , is a system setting of windows. Why not change the delimiter to a semi colon and use commas for decimals

    either that or after you read the data in from the file, do a replace function on it to replace . with , so when you perform the Csng function it will work properly

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Mar 2001
    Location
    The Netherlands
    Posts
    184
    The values are correct when i read them in. I now know that the problem is with they . and , character. Because when i manually enter a value 1.5 it turns it into 15 and 1,5 stays 1,5

    greetz,

    per-i

  6. #6

    Thread Starter
    Addicted Member
    Join Date
    Mar 2001
    Location
    The Netherlands
    Posts
    184
    Hi kleinma,

    you certainly are a bussy person on this forum ;-) Changing the . and , character in my windows settings isn't a good option. Because some other programs will stop working then.

    i tried the replace function but i must be doing something wrong. Keep getting errors. Out of my head... i used...


    Inputstring = replace(inputstring, "." , ",", ,vbCompareText

    btw, i posted something to your answer from yesterday about the color palletes. Did you have the change to look at it?

    greetzz,

    per-i

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width