PDA

View Full Version : Need to know if a file is corrupt



Ago
10-25-2010, 01:00 AM
I have a csvfile where the user saves his settings for the macro.

The settings are

Altitude: Meter or Feet
Velocity: Km/h, M/s, Mph or feet/s

I can read and write to the file, but i cant figure out how to know if its corrupt or not.
The two settings are V(0) and V(1)


If V(0) <> "Meter" Or V(0) <> "Feet" Then
MsgBox "The Flysight settings file is corrupt, please delete it and open this file again"
Exit Sub
End If
If V(1) <> "Km/h" Or V(1) <> "M/s" Or V(1) <> "Mph" Or V(1) <> "Feet/s" Then
MsgBox "The Flysight settings file is corrupt, please delete it and open this file again"
Exit Sub
End If


The first if works (Meter/Feet) but V(1) does not.
When i hover the mouse on V(1) i see the value is "Km/h", if i add a watch and look at the value there it says "Km/h ".
What is that <Space>? A normal space does not work.

Bob Phillips
10-25-2010, 01:33 AM
Perhaps it is Chr(160)?

Ago
10-25-2010, 01:46 AM
No, that did not work either.

I tried to make a Case but i cant get that working either

Select Case V(0)
Case Not "Meter", "Feet"
Exit Sub
End Select
Select Case V(1)
Case Not "Km/h", "M/s", "Mph", "feet/s"
Exit Sub
End Select

I get type mismatch with the above code, if i remove the "" it seems to read them as variables

Is there any way i can get this to work?

I found out that if
str = Left(V(1), 4)
str would contain only "Km/h" but it seems my statement is flawed anyway.

Bob Phillips
10-25-2010, 02:10 AM
What exactly did not work, I just suggested what it might be, what did you do/try?

Bob Phillips
10-25-2010, 02:13 AM
Also, your Case logic seems flawed to me. Maybe try



Select Case V(0)
Case "Meter", "Feet"
Case Else
Exit Sub
End Select
Select Case V(1)
Case "Km/h", "M/s", "Mph", "feet/s"
Case Else
Exit Sub
End Select

Ago
10-25-2010, 02:26 AM
I think i got it working now, and i think i know why it didnt work.
It seems when the file is created it creates a new line and some other sign that is not visible.
By removing the two last characters it woks.
V(1) = Left(V(1), Len(V(1)) - 2)



So you cant use Case not? ok, i didnt know that.

Bob Phillips
10-25-2010, 02:38 AM
No, and even if you could, it would not make sense not for multiple entries. It is a bit like saying



If x <> "a" And x <> "b2" Then


that will always be True, as VBA doesnot short-circuit.

Can you post a workbook, I still suspect spaces?

shrivallabha
10-25-2010, 10:52 AM
This blank character can be Chr(0) it had once given me nightmares. The thread may not be exactly useful. But you may see the posts #11 to #13 specifically.
http://www.vbaexpress.com/forum/showthread.php?t=32670
Hope this helps