Private Posted April 22, 2007 Share Posted April 22, 2007 Hello All,I'm currently desgning a program that checks fiels from a CSV formatted fileFor 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: expandcollapse popupIf 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 Link to comment Share on other sites More sharing options...
GEOSoft Posted April 22, 2007 Share Posted April 22, 2007 (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 April 22, 2007 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!" Link to comment Share on other sites More sharing options...
PaulIA Posted April 22, 2007 Share Posted April 22, 2007 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 Link to comment Share on other sites More sharing options...
Private Posted April 22, 2007 Author Share Posted April 22, 2007 @ Geosoft Why whould i want to use the switch with endswitch? Would it go faster or... @PaulIA Thank you very much, this works great!!! I though so that my array was all string. Thanks for your help! Link to comment Share on other sites More sharing options...
GEOSoft Posted April 22, 2007 Share Posted April 22, 2007 @ GeosoftWhy whould i want to use the switch with endswitch? Would it go faster or... @PaulIAThank you very much, this works great!!! 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!" Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now