Docfxit Posted March 18, 2019 Posted March 18, 2019 I'm getting an error in this script: Opt("WinWaitDelay",100) Opt("WinTitleMatchMode",4) Opt("WinDetectHiddenText",1) Opt("MouseCoordMode",0) TrayTip("clears any tray tip","",0) AutoItSetOption("TrayIconDebug", 1) ;0-off #include "OSVersion.au3" Run('C:\Dnload\9xAddons\TestThis.exe') MsgBox("","Test","$ProgramFiles - " & $ProgramFiles & @CRLF & "_OSVersion() - " & _OSVersion()) Exit This is the error I am getting: The variables should be defined in the #include "OSVersion.au3" Func _OSVersion() Global $OSVersion Local $sWinVer = FileGetVersion('winver.exe') $OS_Version = @OSVersion $servicepack_version = StringReplace(@OSServicePack, "Service Pack ", "SP") If @error = -1 Then $servicepack_version = "" ConsoleWrite($OS_Version & $servicepack_version & StringRegExpReplace(@OSArch, '(X86)', '') & @CRLF) ConsoleWrite(@OSArch & @CRLF) If $OSVersion = 'Win7' Or $OSVersion = 'Win7SP1' Or $OSVersion = 'Win7X64' Or $OSVersion = 'Win7SP1x64' Then $ProgramFiles = "C:\Programs\" Else $ProgramFiles = "C:\Program Files\" EndIf Return $OS_Version & $servicepack_version & StringRegExpReplace(@OSArch, '(X86)', '') EndFunc ;==>_OSVersion What do I need to do to resolve the error? Thanks, Docfxit
BigDaddyO Posted March 18, 2019 Posted March 18, 2019 your setting the global variable inside a function, so it won't exist until after you call that function. Try moving that Global $OSVersion to that top of your "OSVersion.au3" file. it shouldn't throw the error anymore, but it will be blank until after you call the function so I'm not sure if it would show in your MsgBox.
Docfxit Posted March 18, 2019 Author Posted March 18, 2019 (edited) Thanks for the reply... I tried this in "OSVersion.au3": Global $OSVersion, $ProgramFiles Func _OSVersion() Local $sWinVer = FileGetVersion('winver.exe') $OS_Version = @OSVersion $servicepack_version = StringReplace(@OSServicePack, "Service Pack ", "SP") If @error = -1 Then $servicepack_version = "" ConsoleWrite($OS_Version & $servicepack_version & StringRegExpReplace(@OSArch, '(X86)', '') & @CRLF) ConsoleWrite(@OSArch & @CRLF) If $OSVersion = 'Win7' Or $OSVersion = 'Win7SP1' Or $OSVersion = 'Win7X64' Or $OSVersion = 'Win7SP1x64' Then $ProgramFiles = "C:\Programs\" Else $ProgramFiles = "C:\Program Files\" EndIf Return $OS_Version & $servicepack_version & StringRegExpReplace(@OSArch, '(X86)', '') EndFunc ;==>_OSVersion Moving Global $OSVersion outside the function and adding $ProgramFiles fixed the problem. Edited March 18, 2019 by Docfxit
Moderators JLogan3o13 Posted March 18, 2019 Moderators Posted March 18, 2019 You moved the Global to the top, but are still declaring it Globally first line in your function.... Docfxit 1 "Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball How to get your question answered on this forum!
Docfxit Posted March 18, 2019 Author Posted March 18, 2019 2 minutes ago, JLogan3o13 said: You moved the Global to the top, but are still declaring it Globally first line in your function.... Thanks for noticing that. I removed it from the function. I'm still getting the same error.
LarsJ Posted March 18, 2019 Posted March 18, 2019 Maybe it's $ProgramFiles that's the problem? Docfxit and BrewManNH 2 Controls, File Explorer, ROT objects, UI Automation, Windows Message MonitorCompiled code: Accessing AutoIt variables, DotNet.au3 UDF, Using C# and VB codeShell menus: The Context menu, The Favorites menu. Shell related: Control Panel, System Image ListsGraphics related: Rubik's Cube, OpenGL without external libraries, Navigating in an image, Non-rectangular selectionsListView controls: Colors and fonts, Multi-line header, Multi-line items, Checkboxes and icons, Incremental searchListView controls: Virtual ListViews, Editing cells, Data display functions
Docfxit Posted March 18, 2019 Author Posted March 18, 2019 Moving Global $OSVersion outside the function and adding $ProgramFiles fixed the problem. Thanks a bunch guys. You saved my day. I have the include file inside a ton of scripts. Now I need to figure out a way to remove that code from a ton of scripts and add #include to them. Thanks, Docfxit
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