Ghost21 Posted January 22, 2008 Posted January 22, 2008 computer:user:45ms $splitdata = StringSplit($pcdata, ":") $PC = $splitdata[1] $USER = $splitdata[2] $PING = $splitdata[3] but if it doesn't find a : it errors out.. I was thinking something like if @error <> 0 then exitloop . doesn't seem to be working ???
stampy Posted January 22, 2008 Posted January 22, 2008 Assuming $pcdata = 'computer:user:45ms' it worked for me. Are you sure your variable is a string and has a colon in it?
Ghost21 Posted January 22, 2008 Author Posted January 22, 2008 Assuming $pcdata = 'computer:user:45ms' it worked for me. Are you sure your variable is a string and has a colon in it?well it works great if that syntax is like that but if I put like dsfhlsdhdlsfh it crashes the program
BrettF Posted January 22, 2008 Posted January 22, 2008 (edited) well it works great if that syntax is like that but if I put like dsfhlsdhdlsfh it crashes the programIf IsArray ($splitdata) Then... Edited January 22, 2008 by Bert Vist my blog!UDFs: Opens The Default Mail Client | _LoginBox | Convert Reg to AU3 | BASS.au3 (BASS.dll) (Includes various BASS Libraries) | MultiLang.au3 (Multi-Language GUIs!)Example Scripts: Computer Info Telnet Server | "Secure" HTTP Server (Based on Manadar's Server)Software: AAMP- Advanced AutoIt Media Player | WorldCam | AYTU - Youtube Uploader Tutorials: Learning to Script with AutoIt V3Projects (Hardware + AutoIt): ArduinoUseful Links: AutoIt 1-2-3 | The AutoIt Downloads Section: | SciTE4AutoIt3 Full Version!
picaxe Posted January 22, 2008 Posted January 22, 2008 The help file says Return Value If no delimiters were found @error is set to 1, the count is 1 ($array[0]) and the full string is returned ($array[1]).So I don't think "IsArray($splitdata)" will work. "@error <> 0 exit loop" should work. Are you checking @error immediately after StringSplit or saving it in a var for later checking. Or else try checking for $splitdata[0]=1 And $splitdata[1]==$pcdata
MHz Posted January 22, 2008 Posted January 22, 2008 $splitdata = StringSplit($pcdata, ":") $PC = $splitdata[1] $USER = $splitdata[2] $PING = $splitdata[3]You expect 3 elements and $splitdata[0] will contain the count of all elements in the array, so 4 elements is what you need to check for by using UBound() or by checking the value of $splitdata[0]. You can also check @error to whether the StringSplit failed and if it did, then indexing the array above $splitdata[1] would cause error. Failure returns the complete string in $splitdata[1]. $pcdata = '1:2:3' $splitdata = StringSplit($pcdata, ":") If UBound($splitdata) = 4 Then $PC = $splitdata[1] $USER = $splitdata[2] $PING = $splitdata[3] MsgBox(0, '', $PC & @CRLF & $USER & @CRLF & $PING) EndIf How you decide to check depends on your requirement.
weaponx Posted January 22, 2008 Posted January 22, 2008 $pcdata = '1:2:3' If StringInStr($pcdata, ":") Then $splitdata = StringSplit($pcdata, ":") If UBound($splitdata) = 4 Then $PC = $splitdata[1] $USER = $splitdata[2] $PING = $splitdata[3] MsgBox(0, '', $PC & @CRLF & $USER & @CRLF & $PING) EndIf Else ;Error EndIf
Ghost21 Posted January 22, 2008 Author Posted January 22, 2008 $pcdata = '1:2:3' If StringInStr($pcdata, ":") Then $splitdata = StringSplit($pcdata, ":") If UBound($splitdata) = 4 Then $PC = $splitdata[1] $USER = $splitdata[2] $PING = $splitdata[3] MsgBox(0, '', $PC & @CRLF & $USER & @CRLF & $PING) EndIf Else ;Error EndIf Thanks for the great help everyone... I will have to look into Ubound somemore..
WiValdiBB Posted February 12, 2019 Posted February 12, 2019 I noticed nearly the same problem, and did additional check if colon exist If not StringInStr($pcdata, ":") Then
iamtheky Posted February 13, 2019 Posted February 13, 2019 (edited) edit: more complete example showing behavior with various numbers of colons (including none) and made the msgbox title useful. #include<array.au3> $str = "computer:user:45ms" ;~ $str = "computer:user45ms" ;~ $str = "computeruser45ms" local $arr[0] for $i = 0 to _ArrayAdd($arr , $str , 0 , ":") msgbox(0, $i + 1 & ' of ' & ubound($arr), $arr[$i]) next Edited February 13, 2019 by iamtheky FrancescoDiMuro 1 ,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-. |(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/ (_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_) | | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) ( | | | | |)| | \ / | | | | | |)| | `--. | |) \ | | `-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_| '-' '-' (__) (__) (_) (__)
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