0

I have the following script, but no success executing it without errors. I want to put a variable into a URL and ping that URL.

#include <Excel.au3>

$sFilePath1 = "D:\Desktop\1.xlsx"
$oExcel = _ExcelBookOpen($sFilePath1, 0)

For $i = 1 To 2 ; Loop
    Local $username = _ExcelReadcell($oExcel, $i, 1) ;Reading created Excel
    Local $iPing = Ping("http://blogsearch.google.co.in/ping?url="$username"&btnG=Submit+Blog&hl=en", 2500)

    If $iPing Then ; If a value greater than 0 was returned then display the following message.
            MsgBox(0, "STATUS", "Ping Successful", 1)
    Else
        MsgBox(0, "STATUS", "ERROR", 1)
    EndIf
Next
user4157124
  • 2,809
  • 13
  • 27
  • 42
user3282817
  • 9
  • 1
  • 2
  • 1
    Hi and welcome to SO. Please add some more details like the errors you're getting and desired output. – thomaux Feb 07 '14 at 08:57
  • Instead of "$username" it must take the url from excel and ping the whole url. – user3282817 Feb 07 '14 at 09:13
  • Local $iPing = Ping("http://blogsearch.google.co.in/ping?url="$username"&btnG=Submit+Blog&hl=en", 2500) Local $iPing = Ping("http://blogsearch.google.co.in/ping?url=www.facebook.com&btnG=Submit+Blog&hl=en", 2500) – user3282817 Feb 07 '14 at 09:14
  • What are you trying to achieve? Ping returns roundtrip time for a _domain_. Url directives (your variables) are irrelevant to `Ping()`; it simply returns your ping to `blogsearch.google.co.in`. HTTP and ICMP are different concepts. [Related](https://stackoverflow.com/questions/44338176/split-large-string-using-autoit/44339495#44339495). – user4157124 Jun 15 '17 at 14:08

3 Answers3

1

Concatenate the variable to the string:

$id = 21622809
MsgBox(0, '', "http://example.com/user/" & $id & "/blah_blah_blah")

Or enable the ExpandVarStrings option to use the variable:

$id = 21622809
Opt("ExpandVarStrings", 1)
MsgBox(0, "", "http://example.com/user/$id$/blah_blah_blah")
user4157124
  • 2,809
  • 13
  • 27
  • 42
DDMC
  • 396
  • 2
  • 11
0

Like Xenobiologist already said in comments to the question, this should just work fine:

#include <Excel.au3>

$sFilePath1 = "D:\Desktop\1.xlsx"
$oExcel = _ExcelBookOpen($sFilePath1, 0)
For $i = 1 To 2 ;Loop
    Local $username = _ExcelReadcell($oExcel, $i, 1) ;Reading created Excel
    Local $iPing = Ping("http://blogsearch.google.co.in/ping?url="&$username&"&btnG=Submit+Blog&hl=en", 2500)

    If $iPing Then ; If a value greater than 0 was returned then display the following message.
        MsgBox(0, "STATUS", "Ping Successful" ,1)
    Else
        MsgBox(0, "STATUS", "ERROR" ,1)
    EndIf
Next
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Teifun2
  • 338
  • 2
  • 15
0

As Teifun2 showed, you just need to write your text between quotes or dual quotes, and then put "&" between the last quote ad the variable, this way :

"I am writing this between double quotes at line # " & $i_Nbr & ' with simple quotes!' 
Vlu
  • 57
  • 4