Sign in to follow this  
Followers 0
Private

Check if array variabel is an integer

5 posts in this topic

Hello All,

I'm currently desgning a program that checks fiels from a CSV formatted file

For each line i have to check if a value is correcto to a certein complexibility.

for example i have attached a file that should be checked.

Now the problem is:

I have the check if for example $y = 1 is a integer but my code:

If IsInt ($aZending_Laadadres[$y]) = 0 Then
                    _SP_Write_Log($sFilename, $x, $y, "Line identifier is an alphanumeric character, should be numeric /  1")oÝ÷ Ù7¥É¶­¶«zÛ«)ཀྵnzêºH°íªê-Æ¥Á¬¬Ñ«"¶+yø§yÖ¬j{¦z¸r«iË^­«,'{ayªëk&òºÈ§«­¢+Ù}ÉÉå¥ÍÁ±ä ÀÌØíi¹¥¹}1ÉÌ°ÅÕ½ÐìÅÕ½Ðì¤oÝ÷ Ù©Ýjëh×6msgBox (0, "", $aZending_Laadadres[$y])oÝ÷ Øz0q©âµ·©¢Ë"nW(^(ºW[yªi­ç"j×jëh×6#include <file.au3>
#include <array.au3>
#Include <Date.au3>

$aRecords  = ""
$sFilename = "C:\200704201631144.txt"
$nErrors   = 0

FileDelete ("C:\Controle_EDI_KLG.log")

If Not _FileReadToArray($sFilename, $aRecords) Then
    MsgBox(4096, "Error - KLG Europe", "An error occured while opening the specified file" & @CRLF & @CRLF & @CRLF & _
            "Filename  : " & $sFilename & @CRLF & _
            "Error        : " & @error)
    Exit
EndIf

For $x = 1 To $aRecords[0]
    $aSplit = StringSplit($aRecords[$x], ";")
        Select
            Case $aSplit[1] = 0
                _SP_Controle_Header($aSplit)
            Case $aSplit[1] = 1
                _SP_Controle_Dossier($aSplit)
            Case $aSplit[1] = 2
                _SP_Controle_Zending_Laadadres($aSplit)
            Case $aSplit[1] = 3
                _SP_Controle_Zending_Losadres($aSplit)
            Case $aSplit[1] = 4
                _SP_Controle_Zendingsregel($aSplit)
            Case $aSplit[1] = 5
                _SP_Controle_Zending_Statussen($aSplit)
            Case $aSplit[1] = 6
                _SP_Controle_Zending_Redundant($aSplit)
            Case $aSplit[1] = 7
                _SP_Controle_Zendingsregel_Adr($aSplit)
            Case $aSplit[1] = 8
                _SP_Controle_Zendingsregel_Barcodes($aSplit)
            Case $aSplit[1] = 9
                _SP_Controle_Trailer($aSplit)
        EndSelect
Next
    
    
Func _SP_Controle_Header($aHeader)
EndFunc

Func _SP_Controle_Dossier($aDossier)
EndFunc

Func _SP_Controle_Zending_Laadadres($aZending_Laadadres)
        
    For $y = 1 to $aZending_Laadadres[0]
        Select
            Case $y = 1     ; Recordsoort           n/  1
                If IsInt ($aZending_Laadadres[$y]) = 0 Then
                    _SP_Write_Log($sFilename, $x, $y, "Line identifier is an alphanumeric character, should be numeric /  1")
                EndIf
                
                If StringLen ($aZending_Laadadres[$y]) > 1 Then
                    _SP_Write_Log($sFilename, $x, $y, "Line identifier is larger then 1 character")
                EndIf
            Case $y = 2     ; Zendingskenmerk       a/  3
                $aZending_Laadadres[$y] = StringReplace ($aZending_Laadadres[$y], '"', "")
                
                If StringLen ($aZending_Laadadres[$y]) > 3 Then
                    _SP_Write_Log($sFilename, $x, $y, "Shipment brand is larger then 3 character")
                EndIf               
                
                If $aZending_Laadadres[$y] = "" Then
                    _SP_Write_Log($sFilename, $x, $y, "Shipment brand is not filled")
                EndIf
                
            Case $y = 3     ; Type zending          a/ 10
                $aZending_Laadadres[$y] = StringReplace ($aZending_Laadadres[$y], '"', "")
                
                If StringLen ($aZending_Laadadres[$y]) > 10 Then
                    _SP_Write_Log($sFilename, $x, $y, "Shipment type is larger then 10 numeric character")
                EndIf

                If $aZending_Laadadres[$y] = "" Then
                    _SP_Write_Log($sFilename, $x, $y, "Shiptment type is not filled")
                EndIf               
            Case $y = 4     ; Incasso derden        n/  1
                If StringLen ($aZending_Laadadres[$y]) > 1 Then
                    _SP_Write_Log($sFilename, $x, $y, "Incasso derden is larger then 1 character")
                EndIf
            Case $y = 5     ; Opdrachtgevercode     a/ 10
                $aZending_Laadadres[$y] = StringReplace ($aZending_Laadadres[$y], '"', "")
                If StringLen ($aZending_Laadadres[$y]) > 10 Then
                    _SP_Write_Log($sFilename, $x, $y, "Clientcode is larger then 10 character")
                EndIf

                If $aZending_Laadadres[$y] = "" Then
                    _SP_Write_Log($sFilename, $x, $y, "Client code is not filled")
                EndIf
        EndSelect
    Next    
    
EndFunc

Func _SP_Controle_Zending_Losadres($aZending_Losadres)
EndFunc

Func _SP_Controle_Zendingsregel($aZendingsregel)
EndFunc

Func _SP_Controle_Zending_Statussen($aZending_Statussen)
EndFunc

Func _SP_Controle_Zending_Redundant($aZending_Redundant)
EndFunc

Func _SP_Controle_Zendingsregel_Adr($aZendingsregel_Adr)
EndFunc

Func _SP_Controle_Zendingsregel_Barcodes($aZendingsregel_Barcodes)
EndFunc

Func _SP_Controle_Trailer($aTrailer)
EndFunc

Func _SP_Write_Log($sErrFilename, $nErrLine, $sErrPosition, $sErrError)
    If $nErrors = 0 Then
        FileWriteLine ("C:\Controle_EDI_KLG.log", "Timestamp" & ";" & "Filename" & ";" & "Line no." & ";" & "Position" & ";" & "Description")
        $nErrors = $nErrors + 1
    EndIf
    
    FileWriteLine ("C:\Controle_EDI_KLG.log", _Now() & ";" & $sErrFilename & ";" & $nErrLine & ";" & $sErrPosition & ";" & $sErrError )
    $nErrors = $nErrors + 1
EndFunc

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Try changing IsInt() to IsNumber()

Also you can clean up your code by changing those Select/EndSelect statements to Switch/EndSwitch

Switch $aSplit[1]

Case 1

Do whatever

EndSwitch

Switch $Y

Case 1

Do whatever

EndSwitch

Edited by GEOSoft

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Share this post


Link to post
Share on other sites

The problem is with IsInt. If you check the help file, you'll see that it shows in the example that it will return 0 if you pass it a string. You need to remember that you're dealing with an array of strings. If you want to check if a string is all digits, use the StringIsDigit function. If it passes StringIsDigit, then it's safe to use the string as an integer.


Auto3Lib: A library of over 1200 functions for AutoIt

Share this post


Link to post
Share on other sites

@ Geosoft

Why whould i want to use the switch with endswitch?

Would it go faster or...

@PaulIA

Thank you very much, this works great!!! :shocked:

I though so that my array was all string. Thanks for your help!

Share this post


Link to post
Share on other sites

@ Geosoft

Why whould i want to use the switch with endswitch?

Would it go faster or...

@PaulIA

Thank you very much, this works great!!! :shocked:

I though so that my array was all string. Thanks for your help!

In your case it just makes the code cleaner and easier to read.

I've fount that Switch is often preferable to Select.

@PaulIA......... D__N!!!! I knew I had that wrong. That's the problem with keeping my development system unavailable to the network system, I can't quickly check things. Although if I had half a brain I could keep a link to my online AutoIt help page in favorites. :">


George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0