AnonymousX

[Solved] Comment out a function for subsequent executions

11 posts in this topic

#1 ·  Posted (edited)

Hello,

 

I'm working on having a program that when executed a message box will pop up informing the user on how it is to be used. It will offer a choice to not display the message again. The only way I was able to think of achieving this is by using the  _FileWriteToLine function, which would require me to know the line in which to comment out this message box. I want the code to be more rust though then just saying change line "X" as if in the future more code gets added this line might change. I was trying to find another function that returns the line in the file it is one but couldn't find such a thing. Here is what I'm thinking:

 

#include <File.au3>

;======Main=====


UserMSG();#UserMSG()#
FunStuff()

;======Functions=====

Func UserMSG()

$infomsg = MsgBox(4,"Info","Bla bla bla" & @CRLF & @CRLF & "Never see this again press ""YES""")

$MSGFuncLineNum = *****Return line number with string "#UserMSG()#"*****

If $infomsg == 6 Then
    _FileWriteToLine("test.au3",$MSGFuncLineNum,"#cs")
    _FileWriteToLine("test.au3",$MSGFuncLineNum+2,"#ce")
EndIf

endFunc;UserMSG()

Func FunStuff()
EndFunc

 

Edited by AnonymousX

Share this post


Link to post
Share on other sites



Or you just write something to the users HKCU or to AppData, registry is generally better for this type of thing:

#include <File.au3>

;======Main=====


UserMSG();#UserMSG()#
FunStuff()

;======Functions=====

Func UserMSG()
If RegRead('HKCU\Software\MyProgram', 'Show Message') = 0 Then Return
$infomsg = MsgBox(4,"Info","Bla bla bla" & @CRLF & @CRLF & "Never see this again press ""YES""")
If $infomsg == 6 Then RegWrite('HKCU\Software\MyProgram', 'Show Message', 'REG_DWORD', 0)

endFunc;UserMSG()

Func FunStuff()
EndFunc

 

1 person likes this

Share this post


Link to post
Share on other sites

Why would you use a registry for showing a message box or not?

@AnonymousX just use an ini file, or some kind of blank file

#include <MsgBoxConstants.au3>

If (FileExists(@ScriptDir & "\ShowMsg") = False) Then
    If (MsgBox(4,"Info","Bla bla bla" & @CRLF & @CRLF & "Never see this again press ""YES""") = $IDYES) Then
        FileClose(FileOpen(@ScriptDir & "\ShowMsg", 10))
    EndIf
EndIf

Use an ini file if you want to save other settings for your program.

Share this post


Link to post
Share on other sites

@InunoTaishou - Why wouldn't you?  Most software will write to the HKCU registry to say that Eula has been read or Start-up message has been shown.  A flag is a flag, however there are some differences between system flags and user flags.  If this program is to be run by multiple users, by using your Ini method none of the other users that logon will see that message.

Share this post


Link to post
Share on other sites

If you write the Ini-file into the users @AppDataDir then this should work for multiple users.

1 person likes this

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

@water Agree, I mentioned that in my original post but thought registry was an easier way to go.

 

Share this post


Link to post
Share on other sites

Thanks for input. I'll have to look into that further, never used Ini-files or HKCU before. 

I figured out what I was originally trying to do, as well. Here is the code for anyone else in the future:

#include <File.au3>

;======Main=====


UserMSG();#usermsg#
FunStuff()

;======Functions=====

Func UserMSG()

$infomsg = MsgBox(4,"Info","Bla bla bla" & @CRLF & @CRLF & "Never see this again press ""YES""")

$MSGFuncLineNum = Findlinenum()

If $infomsg == 6 Then
    _FileWriteToLine(@scriptname,$MSGFuncLineNum,"#cs")
    _FileWriteToLine(@scriptname,$MSGFuncLineNum+2,"#ce")
EndIf

endFunc;UserMSG()

Func Findlinenum();Used to find line with usermsg()
    $All_linecount = _FileCountLines(@ScriptName)

For $i = $All_linecount To 1 Step -1
    If StringInStr(FileReadLine(@ScriptName, $i), "#usermsg#") Then
        $linenum = $i
    EndIf
Next

Return $linenum
EndFunc

Func FunStuff()
EndFunc

 

Share this post


Link to post
Share on other sites

 

On 1/28/2017 at 6:21 AM, Subz said:

@InunoTaishou - Why wouldn't you?  Most software will write to the HKCU registry to say that Eula has been read or Start-up message has been shown. 

If you actually tear apart modern day applications, you will find that app-specific configuration information is not stored in HKCU per best practices. If stored anywhere it would be in HKLM; HKCU is reserved for "personalization" of an application by a single user. Most applications would use .ini or other config files, stored in a central location, as suggested by InunoTaishou


√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites

@JLogan3o13 - The OP wrote: " I'm working on having a program that when executed a message box will pop up informing the user on how it is to be used. It will offer a choice to not display the message again. "  If this message is only meant for only one user then @InunoTaishou solution would work fine, the solution I offered was for "personalization" of an application by a single user.

Share this post


Link to post
Share on other sites

#10 ·  Posted

I understand what the OP is after; I was responding to your sweeping generalization that most software writes to HKCU. I also don't see a EULA as personalization. Regardless, the OP has several ways now to accomplish what he is after.


√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites

#11 ·  Posted

My suggestion was based upon the OP, i.e. that user-centric flags should be set in the users profile and that HKCU and AppDataDir are the most common places for these, if that's a sweeping generalization then so be it.

Share this post


Link to post
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