Jump to content

Displaying a value from a macro


Recommended Posts

hey guys...again,

I'm trying to display a phone number which depends on what IP address the pc has. but I'm having trouble with. Seems like the value is not recognised from the macro @IPAddress1. How would I fix this ?

In this example, they are suppose to be more IP Address like 192.168.2.0 and so on. So if its 192.168.2.0 its a different number.

Local $iptelephone
Switch @IPAddress1
Case 192.168.1.0 to 192.168.1.255
  $iptelephone = "555-4444"
Case 192.168.2.0 to 192.168.2.255
$iptelephone = "555-5555"
EndSwitch

msgbox(0, Default, $iptelephone )

** Warning **Noobie ahead. handle with caution

Link to comment
Share on other sites

  • Moderators

bigbangnet,

The IPs are not "real" numbers so you cannot do it like that. :)

I suggest you split the IP and then check the specific section. Here is an example scripts: ;)

Local $iptelephone, $aIP[2] = ["192.168.1.111", "192.168.2.222"]

For $i = 0 To 1

    ; Simulate the macro
    $sIP = $aIP[$i]

    ; Split the IP on the dots
    $aSplit = StringSplit($sIP, ".")

    ; Now look for the 3rd section
    Switch $aSplit[3]
        Case "1"
            $iptelephone = "555-4444"
        Case "2"
            $iptelephone = "555-5555"
    EndSwitch

    MsgBox(0, Default, $iptelephone)

Next

All clear? ;)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

In the first line

Local $iptelephone, $aIP[2] = ["192.168.1.111", "192.168.2.222"]

what do the last 2 ip address represent ? Are these just 2 examples of ip address. but the important part is the 3rd number in that ip. This means if I have 20 different numbers I would have to type in 20 ip address in my array ?

Edited by bigbangnet

** Warning **Noobie ahead. handle with caution

Link to comment
Share on other sites

  • Moderators

bigbangnet,

Your original suggestion showed you wanted to discriminate only on the third section of the IP (192.168.1.0 to 192.168.1.255) - so those 2 IPs are representative of the 2 ranges, one with a .1 and one with a .2.

You press "OK" twice because the script runs through the loop twice so you can see that it discriminates between the 2 representative IPs. All you need for your script is this:

Local $iptelephone

$aSplit = StringSplit(@IPAddress1, ".")

Switch $aSplit[3]
    Case "1"
        $iptelephone = "555-4444"
    Case "2"
        $iptelephone = "555-5555"
EndSwitch

MsgBox(0, Default, $iptelephone )

Clear now? :)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

Not quite, If I run that script alone, the first phone number appears then the second number appears. This is not quite what I wanted. I just want the correct number to appear, not the whole list.

I have included my complete script so you know what I mean. In short it displays a picture fullscreen, they click the button to quit it, then it sends a silent email (which they don't know of course). I get that email here with the suppose number to call. But the only phone number I get is the first one in my body.

#region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Res_requestedExecutionLevel=asInvoker
#endregion ;**** Directives created by AutoIt3Wrapper_GUI ****
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <Inet.au3>

$FrmNouveauPc = GUICreate("Nouveau Pc", @DesktopWidth, @DesktopHeight, 0, 0, $WS_POPUP)
GUISetBkColor(0x0066CC)
$Pic1 = GUICtrlCreatePic("192.168.1.126clientsappsScriptAutoItImagesCallMIS.jpg", 0, 0, @DesktopWidth, @DesktopHeight)
GUICtrlSetState($Pic1, $GUI_DISABLE)
$BtnQuitter = GUICtrlCreateButton("Exit / Quitter", @DesktopWidth / 2 - 50, @DesktopHeight / 2 + 200, 100, 50, $BS_CENTER)
GUICtrlSetResizing(-1, $GUI_DOCKBOTTOM)
GUISetState(@SW_SHOW)

Local $iptelephone, $aIP[21] = ["192.168.1.111", "192.168.11.222", "192.168.12.222", "192.168.13.222", "192.168.14.222","192.168.15.222", "192.168.16.222", "192.168.17.222", "192.168.18,222", "192.168.109.222", "192.168.110.222", "192.168.111.222", "192.168.112.222", "192.168.113.222", "192.168.114.222", "192.168.115.222", "192.168.116.222", "192.168.117.222", "192.168.118.222", "192.168.119.222","192.168.120.222"]

For $i = 0 To 1

    ; Simulate the macro
    $sIP = $aIP[$i]
    ; Split the IP on the dots
    $aSplit = StringSplit($sIP, ".")
    ; Now look for the 3rd section

Switch $aSplit[3]
Case "1"
  $iptelephone = "555-4040"
Case "11"
$iptelephone = "12121"
Case "12"
$iptelephone = "000"
Case "13"
$iptelephone = "999"
Case "14"
$iptelephone = "888"
Case "15"
$iptelephone = "777"
Case "16"
$iptelephone = "111"
Case "17"
$iptelephone = "222"
Case "18"
$iptelephone = "222"
Case "109"
$iptelephone = "333"
Case "110"
$iptelephone = "444"
Case "111"
$iptelephone = "555"
Case "112"
$iptelephone = "666"
Case "113"
$iptelephone = "6546554"
Case "114"
$iptelephone = "7654"
Case "115"
$iptelephone = "5755"
Case "116"
$iptelephone = "67676"
Case "117"
$iptelephone = "57669"
Case "118"
$iptelephone = "6440"
Case "119"
$iptelephone = "45407"
Case "120"
$iptelephone = "343430"
EndSwitch
While 1
Sleep(10)
$nMsg = GUIGetMsg()
Switch $nMsg
Case $BtnQuitter
MsgBox(64, "Avertissement", "blah blah. " & Chr(13) & Chr(13) & "blah blah gain")
Local $ip = @IPAddress1
Local $pcname = @ComputerName
Local $s_SmtpServer = "xxxxx.com"
Local $s_FromName = $pcname
Local $s_FromAddress = "mail@mail.com"
Local $s_ToAddress = "missupport@xxxxx.com"
Local $s_Subject = "blah blah"
Local $as_Body[3]
$as_Body[0] = $pcname
$as_Body[1] = $ip
$as_Body[2] = "please call " & $iptelephone & " blah blah"
Local $Response = _INetSmtpMail($s_SmtpServer, $s_FromName, $s_FromAddress, $s_ToAddress, $s_Subject, $as_Body, @ComputerName, -1)
Local $err = @error
Exit
Case $GUI_EVENT_CLOSE
Exit
EndSwitch
WEnd
next

** Warning **Noobie ahead. handle with caution

Link to comment
Share on other sites

never mind, I replied too fast. I looked at your last script and modified it to mine and it works correctly now. thanks for your help.

and... I love and hate you (I'm jealous lol)...how the *//& you know all that . Seems like you know it by heart. Well continue your awesome work.

** Warning **Noobie ahead. handle with caution

Link to comment
Share on other sites

  • Moderators

bigbangnet,

If I run that script alone, the first phone number appears then the second number appears. This is not quite what I wanted. I just want the correct number to appear, not the whole list

Of course both numbers appear - the idea of the example was to show you that the code could distinguish betwen the 2 cases. That is why I put the 2 representative IPs into an array. :)

Your script could look like this:

#region ;**** Directives created by AutoIt3Wrapper_GUI ****
    #AutoIt3Wrapper_Res_requestedExecutionLevel=asInvoker
#endregion ;**** Directives created by AutoIt3Wrapper_GUI ****
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <Inet.au3>

$FrmNouveauPc = GUICreate("Nouveau Pc", 500, 500)
GUISetBkColor(0x0066CC)
$Pic1 = GUICtrlCreatePic("192.168.1.126clientsappsScriptAutoItImagesCallMIS.jpg", 0, 0, @DesktopWidth, @DesktopHeight)
GUICtrlSetState($Pic1, $GUI_DISABLE)
$BtnQuitter = GUICtrlCreateButton("Exit / Quitter", 10, 10, 100, 50, $BS_CENTER)
GUICtrlSetResizing(-1, $GUI_DOCKBOTTOM)
GUISetState(@SW_SHOW)

; Get IP
$ip = @IPAddress1
; Split the IP on the dots
$aSplit = StringSplit($ip, ".")
; Now look for the 3rd section
Switch $aSplit[3]
    Case "1"
        $iptelephone = "555-4040"
    Case "11"
        $iptelephone = "12121"
    Case "12"
        $iptelephone = "000"
    Case "13"
        $iptelephone = "999"
    Case "14"
        $iptelephone = "888"
    Case "15"
        $iptelephone = "777"
    Case "16"
        $iptelephone = "111"
    Case "17"
        $iptelephone = "222"
    Case "18"
        $iptelephone = "222"
    Case "109"
        $iptelephone = "333"
    Case "110"
        $iptelephone = "444"
    Case "111"
        $iptelephone = "555"
    Case "112"
        $iptelephone = "666"
    Case "113"
        $iptelephone = "6546554"
    Case "114"
        $iptelephone = "7654"
    Case "115"
        $iptelephone = "5755"
    Case "116"
        $iptelephone = "67676"
    Case "117"
        $iptelephone = "57669"
    Case "118"
        $iptelephone = "6440"
    Case "119"
        $iptelephone = "45407"
    Case "120"
        $iptelephone = "343430"
EndSwitch

While 1
    ;Sleep(10) ; No need if you have a GUIGetMsg in the loop
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $BtnQuitter
            MsgBox(64, "Avertissement", "blah blah. " & Chr(13) & Chr(13) & "blah blah gain")
            ;Local $ip = @IPAddress1 ; Already set above
            Local $pcname = @ComputerName
            Local $s_SmtpServer = "xxxxx.com"
            Local $s_FromName = $pcname
            Local $s_FromAddress = "mail@mail.com"
            Local $s_ToAddress = "missupport@xxxxx.com"
            Local $s_Subject = "blah blah"
            Local $as_Body[3]
            $as_Body[0] = $pcname
            $as_Body[1] = $ip
            $as_Body[2] = "please call " & $iptelephone & " blah blah"

            ConsoleWrite($ip & " - " & $iptelephone & @CRLF)

            ;Local $Response = _INetSmtpMail($s_SmtpServer, $s_FromName, $s_FromAddress, $s_ToAddress, $s_Subject, $as_Body, @ComputerName, -1)
            Local $err = @error
            Exit
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
WEnd

I have added a couple of comments. ;)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

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...