Solved VB program ran on XP but does not run on Windows 7?

May 5, 2014 at 18:18:41
Specs: Windows 7 PRO, Intel core 2 duo 2.33GHZ(E6650), 4 gig ram
I have a .vbs script (Visual Studio 2008) that ran on XP but does not run on Windows 7 PRO. The PC died after running 24/7 since 1998 as a Home Control PC, and the new one has Win7.

I get the following error:

Script: GetIP.vbs
Line: 50
Char: 20
Error: Invalid procedure call or argument: "Mid"
Code: 800A0005
Source: Microsoft VBScript runtime error

Line 50 is as follows:
If varStart And varStop Then strIP = Mid(strHTML, varStart, varStop - varStart)

I just copied the script to my Vista machine and it ran perfectly.

Any thoughts?
Don

Here is the entire script"

Const ForReading = 1
Const ForAppending = 8
Dim ipLog, objHTTP, strHTML, varStart
Dim varStop, strIP, strCurrIP, objFSO
Dim txtFile, strLine, objShell

' Log for tracking external IP addresses
ipLog = "IP.txt"

' Get current external IP address from web
Set objHTTP = CreateObject("MSXML2.XMLHTTP")
Call objHTTP.Open("GET", "http://checkip.dyndns.org", False)
objHTTP.Send()
strHTML = objHTTP.ResponseText

' Extarct IP from HTML if HTML was recieved
If strHTML <> "" Then
varStart = InStr(1, strHTML, "Current IP Address:", vbTextCompare) + 19
If varStart Then varStop = InStr(varStart, strHTML, "</body>", vbTextCompare)
If varStart And varStop Then strIP = Mid(strHTML, varStart, varStop - varStart)
Else
strIP = "Unavailable"
End If
' Remove preceeding or trailing spaces
strCurrIP = Trim(strIP)

' Check for log file and last log entry
Set objFSO = CreateObject("Scripting.FileSystemObject")
If Not (objFSO.FileExists(ipLog)) Then
' If log file doesn't exist create it
Set txtFile = objFSO.CreateTextFile(ipLog, True)
strIP = ""
Else
' Get last external IP address entry from log file
Set txtFile = objFSO.OpenTextFile(ipLog, ForReading)
Do Until txtFile.AtEndOfStream
strLine = txtFile.ReadLine
If Len(strLine) > 0 Then
strIP = strLine
End If
Loop

End If
txtFile.Close

' Extarct last external IP from log file entry
If strIP <> "" Then
varStart = 1
varStop = InStr(varStart, strIP, ",", vbTextCompare) - 1
If varStop Then strIP = Mid(strIP, varStart, varStop - varStart)
' Remove preceeding or trailing spaces
Trim(strIP)
Else
strIP = "Unavailable"
End If

' Check if external IP has changed
If strCurrIP = strIP Then
Else
' If changed log to file and display IP
Set txtFile = objFSO.OpenTextFile(ipLog, ForAppending)
txtFile.Write(strCurrIP)
txtFile.Close
End If

' Clear variables
Set ipLog = Nothing
Set objHTTP = Nothing
Set strHTML = Nothing
Set varStart = Nothing
Set varStop = Nothing
Set strIP = Nothing
Set strCurrIP = Nothing
Set objFSO = Nothing
Set txtFile = Nothing
Set strLine = Nothing
Set objShell = Nothing


See More: VB program ran on XP but does not run on Windows 7?

Report •


✔ Best Answer
May 6, 2014 at 07:09:38
varStop = InStr(varStart, strIP, ",", vbTextCompare) - 1
I suspect you're not finding a comma, so your varStop ends up as -1. This would mean you're trying to grab -2 characters, on the Mid line, and Mid's calling you out on it.

How To Ask Questions The Smart Way



#1
May 5, 2014 at 19:56:07
Is your wn-7 64-bit? If so, that would be my diagnosis, and first test is try it on a 32-bit version of win-seven and see if it flies. Meantime, I'll politely refrain from regaling you with my opinions regarding 64-bit OS'.

Report •

#2
May 5, 2014 at 23:05:27
I think 32/64 bit is a red herring.

Try printing the 3 parameters of the "mid" function just before the call to check if they are valid.


Report •

#3
May 6, 2014 at 04:27:39
Sorry, it is a 32 bit, like the old XP

Report •

Related Solutions

#4
May 6, 2014 at 04:38:32
It runs perfectly on my 64bit machine with Vista, will check see what happens when I print the values
Thanks

Report •

#5
May 6, 2014 at 07:09:38
✔ Best Answer
varStop = InStr(varStart, strIP, ",", vbTextCompare) - 1
I suspect you're not finding a comma, so your varStop ends up as -1. This would mean you're trying to grab -2 characters, on the Mid line, and Mid's calling you out on it.

How To Ask Questions The Smart Way


Report •

#6
May 6, 2014 at 19:01:19
I copied and ran your script, and found that, indeed, Razor had nailed it to the bulls-eye: You have a reference to a comma that is never created (but how did it work on the previous runs is my question?) You need to decide on comma-delim or line-breaks, then stick with it. Your script writes with no linebreak and no comma (txtfile.write vs txtfile.writeline or, if you want commas: txtfile.write strIP&","
Whichever way you prefer, as long as you're consistant, your script should work, once you've made this transition.
To obtain the last instance, you can use n=txtfile.readall:p=instrrev(n,vbcrlf,,1) as a shortcut to obtain the last delimited item.

message edited by nbrane


Report •

Ask Question