Jump to content

Stringsplit ip address


spymare
 Share

Recommended Posts

hi.

i stringsplit my public ip address. But if there's no internet connection, it of course can't

stringsplit it, so it gives an error. How can i prevent that? and make it show the msgbox instead?

here's my code:

#include <Inet.au3>

#include <Array.au3>

#include <Process.au3>

$test = (_getip())

$arrayTemp = StringSplit($test,".")

$sFirstTwoBytes= $arrayTemp[1] & "." & $arrayTemp[2]

if _getip() = "192.38.13.111" Then

$outlook = _RunDos("start outlook.exe /c ipm.note /m helpdesk@bio.dtu.dk")

Else

MsgBox(16,"Error","You computer is not connected to System Biologi network")

endif

Edited by spymare
Link to comment
Share on other sites

By testing if the _getip() function failed in some way.

- could return a empty string in that case.

- or a @error value, other than zero, indication a failure.

Ps: Try using Autoit tags instead of Quote tags on code parts.

(Square Blue [A] button, first icon on 3th line. (not available in fast message edit mode -> [use full editor] )

Edited by MvGulik

"Straight_and_Crooked_Thinking" : A "classic guide to ferreting out untruths, half-truths, and other distortions of facts in political and social discussions."
"The Secrets of Quantum Physics" : New and excellent 2 part documentary on Quantum Physics by Jim Al-Khalili. (Dec 2014)

"Believing what you know ain't so" ...

Knock Knock ...
 

Link to comment
Share on other sites

hi.

i stringsplit my public ip address. But if there's no internet connection, it of course can't

stringsplit it, so it gives an error. How can i prevent that? and make it show the msgbox instead?

here's my code:

Try This:

#include <Inet.au3>
#include <Array.au3>
#include <Process.au3>

$test = (_getip())
If Not @Error Then ;If not connected @Error = 1
     $arrayTemp = StringSplit($test,".")
     $sFirstTwoBytes= $arrayTemp[1] & "." & $arrayTemp[2]

     If _GetIp() = "192.38.13.111" Then $outlook = _RunDos("start outlook.exe /c ipm.note /m helpdesk@bio.dtu.dk")
Else
     MsgBox(16,"Error","You computer is not connected to System Biologi network")
EndIf

Dating a girl is just like writing software. Everything's going to work just fine in the testing lab (dating), but as soon as you have contract with a customer (marriage), then your program (life) is going to be facing new situations you never expected. You'll be forced to patch the code (admit you're wrong) and then the code (wife) will just end up all bloated and unmaintainable in the end.

Link to comment
Share on other sites

the problem is getip will never match: $sFirstTwoBytes since, it splits: $iptobesplit so now the ip address is:

192.38 and not 192.38.13.111

should be like this:

$iptobesplit = ("192.38.13.111")

$test = (_getip())

If Not @Error Then ;If not connected @Error = 1

$arrayTemp = StringSplit($test,".")

$sFirstTwoBytes= $arrayTemp[1] & "." & $arrayTemp[2] & $iptobesplit

If _GetIp() = $sFirstTwoBytes Then $outlook = _RunDos("start outlook.exe /c ipm.note /m helpdesk@bio.dtu.dk")

Else

MsgBox(16,"Error","You computer is not connected to System Biologi network")

EndIf

Edited by spymare
Link to comment
Share on other sites

the problem is getip will never match: $sFirstTwoBytes since, it splits: $iptobesplit so now the ip address is:

192.38 and not 192.38.13.111

should be like this:

$iptobesplit = ("192.38.13.111")

$test = (_getip())

If Not @Error Then ;If not connected @Error = 1

$arrayTemp = StringSplit($test,".")

$sFirstTwoBytes= $arrayTemp[1] & "." & $arrayTemp[2] & $iptobesplit

If _GetIp() = $sFirstTwoBytes Then $outlook = _RunDos("start outlook.exe /c ipm.note /m helpdesk@bio.dtu.dk")

Else

MsgBox(16,"Error","You computer is not connected to System Biologi network")

EndIf

Once again, as MvGulik pointed out, please use code tags, it makes it a lot easier to read. As for your problem, look in the help file for either StringInStr or StringLeft and they will provide you with what you need since you've successfully confused my tired brain. Edited by LurchMan

Dating a girl is just like writing software. Everything's going to work just fine in the testing lab (dating), but as soon as you have contract with a customer (marriage), then your program (life) is going to be facing new situations you never expected. You'll be forced to patch the code (admit you're wrong) and then the code (wife) will just end up all bloated and unmaintainable in the end.

Link to comment
Share on other sites

the reason why i did not quote my code was because google chrome does not show the icons to do it.. so i installed firefox, that works :graduated:.

i got to this, it works :(, thank you all for you help.

#include <Inet.au3>

#include <Array.au3>

#include <Process.au3>

$test = (_getip())

If @Error Then ;If not connected @Error = 1

MsgBox(16,"Error","You computer is not connected to System Biologi network")

Else

endif

$arrayTemp = StringSplit($test,".")

$sFirstTwoBytes= $arrayTemp[1] & "." & $arrayTemp[2]

If $sFirstTwoBytes = ("192.38") Then

$outlook = _RunDos("start outlook.exe /c ipm.note /m helpdesk@bio.dtu.dk")

Else

MsgBox(16,"Error","You computer is not connected to System Biologi network")

EndIf

good christmas :D

Link to comment
Share on other sites

Can anyone answer me how to ignore errors?

If there's no internet connection, and i run my script, it comes with this error:

C:\Users\bicadm-mi\Desktop\New folder (2)\New AutoIt v3 Script.au3 (12) : ==> Array variable has incorrect number of subscripts or subscript dimension range exceeded.:

$sFirstTwoBytes= $arrayTemp[1] & "." & $arrayTemp[2]

$sFirstTwoBytes= $arrayTemp[1] & "." & ^ ERROR

>Exit code: 1 Time: 1.126

that's because it can't split the ip address, since it don't got a ip address.

Is it possible to ignore errors?

Link to comment
Share on other sites

Can anyone answer me how to ignore errors?

If there's no internet connection, and i run my script, it comes with this error:

that's because it can't split the ip address, since it don't got a ip address.

Is it possible to ignore errors?

The very first set of code I posted will not do the string split if there is nothing to split, hence "avoiding the error".

Dating a girl is just like writing software. Everything's going to work just fine in the testing lab (dating), but as soon as you have contract with a customer (marriage), then your program (life) is going to be facing new situations you never expected. You'll be forced to patch the code (admit you're wrong) and then the code (wife) will just end up all bloated and unmaintainable in the end.

Link to comment
Share on other sites

1) LurchMan already provided you with a way of getting your code to deal with your exception case.

2) How about changing those

tags into [autoit] tags before posting you message. (Or do you also have some keyboard problems preventing you from doing that.)

If @error then DoNothing()

:graduated:

Edited by MvGulik

"Straight_and_Crooked_Thinking" : A "classic guide to ferreting out untruths, half-truths, and other distortions of facts in political and social discussions."
"The Secrets of Quantum Physics" : New and excellent 2 part documentary on Quantum Physics by Jim Al-Khalili. (Dec 2014)

"Believing what you know ain't so" ...

Knock Knock ...
 

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...