|
-
Feb 12th, 2004, 10:16 AM
#1
Thread Starter
Addicted Member
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:
Nr = FreeFile
Open strOpen For Input As #Nr
Do While Not EOF(Nr)
'Array aanpassen
ReDim Preserve tmpChase(MaxChannels, tmpMaxStep)
For i = 0 To MaxChannels
Input #Nr, Inputstring
tmpChase(i, tmpMaxStep) = CSng(Inputstring)
Next i
tmpMaxStep = tmpMaxStep + 1
Loop
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
-
Feb 12th, 2004, 10:35 AM
#2
Thread Starter
Addicted Member
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
-
Feb 12th, 2004, 11:45 AM
#3
Fanatic Member
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
-
Feb 12th, 2004, 12:00 PM
#4
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
-
Feb 12th, 2004, 12:01 PM
#5
Thread Starter
Addicted Member
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
-
Feb 12th, 2004, 12:05 PM
#6
Thread Starter
Addicted Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|