Jump to content

How to save variable globally so can use later even if setting it is dissabled, like if the variable was saved in cache?


xuzo
 Share

Recommended Posts

How to save variable globally so can use later even if setting it is disabled, like if the variable was saved in cache?

Not sure how I can explain.

I want to be able to comment out some script, but still use the message box to display.

#include <MsgBoxConstants.au3>
Global $variable = "hello"
MsgBox($MB_OK, "Saved Variables",$variable)

Then I wan to run the message box ONLY, not setting the variable, since it's supposed to be set Globally?

#include <MsgBoxConstants.au3>
;Global $variable = "hello"
MsgBox($MB_OK, "Saved Variables",$variable)

The second one gives me an error:

==> Variable used without being declared.:

Thanks

Link to comment
Share on other sites

  • Developers

Do you want to save the value of a variable between script runs or during a single run?

For the first case you could use a IniRead() / IniWrite() and for the Latter just define a variable with a Global scope at the beginning of the script.

Jos 

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

"Do you want to save the value of a variable between script runs or during a single run?"

I think between scripts runs, but not sure how to word it...

I want the variable saved. even if it's commented out , every time I press F5

I want to do this:

1. Press F5 with this code:

#include <MsgBoxConstants.au3>
Global $variable = "hello"
MsgBox($MB_OK, "Saved Variables",$variable)

2. Modify the code commenting out the variable like this:

#include <MsgBoxConstants.au3>
;Global $variable = "hello"
MsgBox($MB_OK, "Saved Variables",$variable)

3. Press F5 and have the message box pop up without error, because I set variable in step 1.

 

Edited by xuzo
Link to comment
Share on other sites

I sure did

 

#include <MsgBoxConstants.au3>
#include <WinAPIFiles.au3>

Example()

Func Example()
    ; Create a constant variable in Local scope of the filepath that will be read/written to.
    Local Const $sFilePath = _WinAPI_GetTempFileName(@TempDir)

    ; Write the value of 'AutoIt' to the key 'Title' and in the section labelled 'General'.
    IniWrite($sFilePath, "General", "Title", "AutoIt")

    ; Read the INI file for the value of 'Title' in the section labelled 'General'.
    Local $sRead = IniRead($sFilePath, "General", "Title", "Default Value")

    ; Display the value returned by IniRead.
    MsgBox($MB_SYSTEMMODAL, "", "The value of 'Title' in the section labelled 'General' is: " & $sRead)

    ; Delete the key labelled 'Title'.
    IniDelete($sFilePath, "General", "Title")

    ; Read the INI file for the value of 'Title' in the section labelled 'General'.
    $sRead = IniRead($sFilePath, "General", "Title", "Default Value")

    ; Display the value returned by IniRead. Since there is no key stored the value will be the 'Default Value' passed to IniRead.
    MsgBox($MB_SYSTEMMODAL, "", "The value of 'Title' in the section labelled 'General' is: " & $sRead)

    ; Delete the INI file.
    FileDelete($sFilePath)
EndFunc   ;==>Example

I have no idea what any of this means...

Could anybody just paste a line of code or 2 to my existing example, so I can understand.

Need to get this working without an error:

#include <MsgBoxConstants.au3>
;Global $variable = "hello"
MsgBox($MB_OK, "Saved Variables",$variable)

I put Global in there, I but I don't understand the lingo, not even sure if I need read or write...

I take it displaying a message box is write, but assign value to variable is read? 

I have no clue!

Link to comment
Share on other sites

I have no idea what any of this means...

The comments are kind of self-explanatory, I should know as I wrote it! As for your question, I think you need to go back to basics and understand what variables actually are, because you seem to be missing a huge chunk of programming understanding when it comes to memory storage.

I also feel posting this is kind of going to confuse you even more, but what the heck...

#include <MsgBoxConstants.au3>
; Global $variable = "hello"
MsgBox($MB_OK, "Saved Variables", IniRead("IniFile.ini", "Storage", "Variable", ""))

IniWrite("IniFile.ini", "Storage", "Variable", "Hello")

; No comments added as you seem not to read them!

Edit: Oh and no need to post the example from the help file in the future please, we are aware of it's contents. Thanks.

Edited by guinness

UDF List:

 
_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_ArrayFilter/_ArrayReduce_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Link to comment
Share on other sites

Thank you but yes, I'm even more confused...so I simplified it to 2 lines and got rid of Message box, only console write for simplicity.

1. I run this code with F5, first shows up

Global $variable = "text"
ConsoleWrite ( $variable )

2. I run this code with F5, it doesn't show up, error. I know why, but I don't know how to put the code so that on the first step the script "remembers" the value of the varialble.

;Global $variable = "text"
ConsoleWrite ( $variable )

I need the code so that on the second F5 run, console right will display "text" even if it's commented out. 

That's the ONLY thing I'm trying to achieve. I don't know how to insert the ini write and ini read properly

Sorry, but I have no programming experience, and yes indeed, I'm missing huge gaps, but I don't know where to start, Visual Basics for dummies? C++, no idea!

Here are some ways I tried:

Global $variable = "text"
ConsoleWrite (IniWrite("IniFile.ini" $variable)
Global $variable = "text"
ConsoleWrite (IniWrite "IniFile.ini" $variable)

Ect...just guessing game..

Edited by xuzo
Link to comment
Share on other sites

  • Developers

Well, maybe you need to stop guessing and start opening the helpfile to look at the provided examples showing the correct syntax in simple examples.
It is unlikely someone will/can write a script for you that does exact;y what you want and hope you don't simply start running stuff you don't understand first.

Jos

Edited by Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

  • Developers

My mother doesn't want to start scripting at her age (85). Do you seriously want to be compared with her?  ;)
Since you seem to have the desire to start with scripting yourself, you will have to invest first!

Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

My mother doesn't want to start scripting at her age (85).

That would be awesome though!

@xuzo

Think like a program. So you want to comment out a variable but still display that variable, despite it not existing at all in memory. Do you see why you theory is flawed?

UDF List:

 
_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_ArrayFilter/_ArrayReduce_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Link to comment
Share on other sites

I do make a big effort. This code works, but if I change the variable value, I need to run it twice so the value gets, changed...so it's not quite working right

#include <MsgBoxConstants.au3>
Global $my_variable = "text"
MsgBox($MB_OK, "Saved Variables", IniRead("IniFile.ini", "Storage", "Variable", ""))
IniWrite("IniFile.ini", "Storage", "Variable", $my_variable)

Additionally, I think it would be wiser to use console write as less parameters are involved.

I also tried to convert this example to console write:

 
#include <MsgBoxConstants.au3>
Global $my_variable = "text"
IniRead("IniFile.ini", "Storage", "Variable", "")
ConsoleWrite IniWrite("IniFile.ini", "Storage", "Variable", $my_variable)

 

Edited by xuzo
Link to comment
Share on other sites

Additionally, I think it would be wiser to use console write as less parameters are involved

For the help file examples? No, because not everyone uses SciTE or has the ability to see the standard output stream.

By the way your last example is buggy as you're missing parentheses.

Edited by guinness

UDF List:

 
_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_ArrayFilter/_ArrayReduce_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Link to comment
Share on other sites

"Think like a program. So you want to comment out a variable but still display that variable, despite it not existing at all in memory. Do you see why you theory is flawed?"

yes, I understand

So does the variable get saved to the .ini file? Where is the .ini file?

And then fetches the variable and displays as read?

I kind of understand the concept, but can't even code a simple console write example...help!

Can you try running this? I added a parentheses, not working

#include <MsgBoxConstants.au3>
Global $my_variable = "text"
IniRead(("IniFile.ini", "Storage", "Variable", ""))
ConsoleWrite IniWrite("IniFile.ini", "Storage", "Variable", $my_variable)

 

Link to comment
Share on other sites

Global $my_variable = "text"

; IniFile.au3 is stored in the current working directory i.e where @ScriptFullPath is located
$sRead = IniRead("IniFile.ini", "Storage", "Variable", $my_variable)
ConsoleWrite($sRead & @CRLF)

; Prints either 1 or 0 << See help file for details
ConsoleWrite(IniWrite("IniFile.ini", "Storage", "Variable", $my_variable))

 

UDF List:

 
_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_ArrayFilter/_ArrayReduce_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Link to comment
Share on other sites

Thank you soooooo much guinness and everybody for trying to understand me...!

I tried your example, and it works, however, when I comment out the variable , I get an error again...my objective is to save the variable so it can be used again without being declared everytime

;Global $my_variable = "text"

; IniFile.au3 is stored in the current working directory i.e where @ScriptFullPath is located
$sRead = IniRead("IniFile.ini", "Storage", "Variable", $my_variable)
ConsoleWrite($sRead & @CRLF)

; Prints either 1 or 0 << See help file for details
ConsoleWrite(IniWrite("IniFile.ini", "Storage", "Variable", $my_variable))

Error code:

>"C:\Program Files (x86)\AutoIt3\SciTE\..\autoit3.exe" /ErrorStdOut "E:\populate\AutoIT_nov2015\set_global_variable.au3"    
"E:\populate\AutoIT_nov2015\set_global_variable.au3" (4) : ==> Variable used without being declared.:
$sRead = IniRead("IniFile.ini", "Storage", "Variable", $my_variable)
$sRead = IniRead("IniFile.ini", "Storage", "Variable", ^ ERROR
>Exit code: 1    Time: 0.06382

I understand the first comment, I can see that an .ini file has been created. I looked into it and I understand now ;)  But the second comment about print 1 or 0 I don't, and still can't make this work....

Edited by xuzo
Link to comment
Share on other sites

; IniFile.au3 is stored in the current working directory i.e where @ScriptFullPath is located
$sRead = IniRead("IniFile.ini", "Storage", "Variable", "default")
ConsoleWrite($sRead & @CRLF)

BTW, you can't start any script (that I know of) where variables already exist without having been declared - that is impossible. The code above declares the variable $sRead as a global variable by default. If the variable appeared in local scope (wrapped in a function), then it would automatically be declared as a local variable. This is how AutoIt currently works.

In the code above; once the variable has automatically been declared, it is then assigned a value read from disk - located in the ini file. (see Edit below)

Edit

; Write the data to your ini file - run this code first.
IniWrite("IniFile.ini", "Storage", "Variable", "hello world")

Edit2
It is also possible to avoid using variables completely, but it's not at all efficient.

IniWrite("IniFile.ini", "Storage", "Variable", "hello world")
MsgBox(0, "", IniRead("IniFile.ini", "Storage", "Variable", ""))

 

Edited by czardas
Link to comment
Share on other sites

From what I understand, this is what i am trying to acheive:

A. declare variable
B. save variable value in .ini file
C. send the variable value in Notepad

Then run again:

;A. declare variable (comment out declare variable)
;B. save variable value in .ini file (no need for this step because taken on previous step A. ?)
C. send the variable value in Notepad

Repeat sending variable in notepad again and again on F5 

Here are the 4 version I tried (+ many, many, many more..! ), the 4th version works, but only with message box, not with console write or send.

I - This works:

Global $my_variable = "text"

IniRead("IniFile.ini", "Storage", "Variable", "")
IniWrite("IniFile.ini", "Storage", "Variable", $my_variable)
Local $hWnd = WinWait("[CLASS:Notepad++]", "", 10)
    WinActivate($hWnd)
    send ($my_variable)

II - This doesn't work:

;Global $my_variable = "text"

IniRead("IniFile.ini", "Storage", "Variable", "")
IniWrite("IniFile.ini", "Storage", "Variable", $my_variable)
Local $hWnd = WinWait("[CLASS:Notepad++]", "", 10)
    WinActivate($hWnd)
    send ($my_variable)

III - This works:

#include <MsgBoxConstants.au3>
Global $my_variable = "text"

MsgBox($MB_OK, "Saved Variables", IniRead("IniFile.ini", "Storage", "Variable", ""))
IniWrite("IniFile.ini", "Storage", "Variable", $my_variable)

IV - This works:

#include <MsgBoxConstants.au3>
;Global $my_variable = "text"

MsgBox($MB_OK, "Saved Variables", IniRead("IniFile.ini", "Storage", "Variable", ""))
IniWrite("IniFile.ini", "Storage", "Variable", $my_variable)

 

 

Edited by xuzo
Link to comment
Share on other sites

If you try to write a variable to notepad - it must first exist. If you don't create the variable - it doesn't exist. If you want to write information to notepad, the information has to come from somewhere. Go figure!

BTW - IV does not work.

Edited by czardas
Link to comment
Share on other sites

  • Developers

When doing an Iniread() you need to define in what variable you want to "receive" the retrieved value:

$varname=IniRead()

So in your case:

Global $my_variable=IniRead("IniFile.ini", "Storage", "Variable", "text")
IniWrite("IniFile.ini", "Storage", "Variable", $my_variable)
Local $hWnd = WinWait("[CLASS:Notepad++]", "", 10)
    WinActivate($hWnd)
    send ($my_variable)

Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

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