vgt1 Posted October 24, 2018 Posted October 24, 2018 I'm new to AutoIt, and I'm not much of a programmer/code writer to begin with, and right now I'm having some trouble understanding the StringRegExp function. My actual goal that leads me to this question is to make a GUI which takes the place of a MsgBox, because I wanted a message box that was larger and easier to see. I made a function from the GUI example in the help file which I'm trying to resize based on the size of the text string that is passed to it. I had to do a rough estimation of line wraps based on the number of characters and the size I gave the window. That part works well enough for my needs. Unfortunately it doesn't seem to deal with line feeds. I thought if I could count the number of line feeds in a string, I could include that in the window height calculation. But I just don't get the StringRegExp function, nor do I understand the PCRE pattern thing. I hope someone can help explain it to me as you would explain it to a child. 1. First, is this GUI thing even the best method for getting a bigger message box? Here's a test script that I tried to use to count line feeds: local $text = "This is some"&@LF&"text with a few"&@LF&"line feeds to count." local $lines = StringRegExp($text,'*ANYCRLF',0) MsgBox(0,"",$lines) 2. The help file mentioned *ANYCRLF as finding any of three forms of line feed/carriage return. The above code returns 0 from StringRegExp. What do I put in the pattern to count line feeds? Thanks.
Simpel Posted October 25, 2018 Posted October 25, 2018 Hello @vgt1, welcome to the forum. To count the new lines try StringRegExp($text, “\R”, 0) that will count any unicode new line sequences (untested yet). There is a UDF by @Melba23 “ExtMsgBox” https://www.autoitscript.com/forum/topic/109096-extended-message-box-new-version-2-aug-18/. Maybe this is helpful and fitting to your needs. Simpel SciTE4AutoIt = 3.7.3.0 AutoIt = 3.3.14.2 AutoItX64 = 0 OS = Win_10 Build = 19044 OSArch = X64 Language = 0407/german H:\...\AutoIt3\SciTE H:\...\AutoIt3 H:\...\AutoIt3\Include (H:\ = Network Drive) Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind.
FrancescoDiMuro Posted October 25, 2018 Posted October 25, 2018 (edited) 50 minutes ago, Simpel said: To count the new lines try StringRegExp($text, “\R”, 0) That won't return the number of new line sequences because of the Pattern and the Flag. It will return 0 or 1 only if SRE matches \R, and nothing more. Respecting the Majesty and the Elegance of the SRE Patterns of @mikell, maybe this could do the trick: Global $strString = "This" & @CRLF & _ "is" & @CRLF & _ "a line" & @CRLF & _ "with" & @CRLF & _ "carriage returns" & @CRLF & _ "and line feeds" & @CRLF ConsoleWrite("Original string = " & $strString & @CRLF & _ "Replaced string = " & StringRegExpReplace($strString, "(.*)(\r\n)", "$1 ") & @CRLF & _ "Number of Replacement (@extended) = " & @extended & @CRLF) Cheers Edited October 25, 2018 by FrancescoDiMuro Click here to see my signature: Spoiler ALWAYS GOOD TO READ: Forum Rules Forum Etiquette
Simpel Posted October 25, 2018 Posted October 25, 2018 @FrancescoDiMuro you’re right. @vgt1: (*anycrlf) is just an option how to look for new line sequences if you are looking. So you’re pattern is returning 0 because there is nothing you are searching for. You are setting an option only. Simpel SciTE4AutoIt = 3.7.3.0 AutoIt = 3.3.14.2 AutoItX64 = 0 OS = Win_10 Build = 19044 OSArch = X64 Language = 0407/german H:\...\AutoIt3\SciTE H:\...\AutoIt3 H:\...\AutoIt3\Include (H:\ = Network Drive) Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind.
iamtheky Posted October 25, 2018 Posted October 25, 2018 regex is not necessary for this task local $text = "This is some"&@LF&"text with a few"&@LF&"line feeds to count." StringReplace($text , @LF , @LF) msgbox(0, '' , @extended) ,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-. |(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/ (_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_) | | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) ( | | | | |)| | \ / | | | | | |)| | `--. | |) \ | | `-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_| '-' '-' (__) (__) (_) (__)
mikell Posted October 25, 2018 Posted October 25, 2018 (edited) As Simpel said ExtMsgbox by Melba23 is a nice solution OTOH, Melba also built StringSize.au3 . This UDF allows to size on the fly any label depending on the size of the string inside Using it you might create custom message boxes of various self-adaptative sizes The approach could be : check the size of the string => size the label => size the gui => show the gui Edited October 25, 2018 by mikell link added
dmob Posted October 25, 2018 Posted October 25, 2018 16 hours ago, vgt1 said: I because I wanted a message box that was larger and easier to see. Really, save yourself the trouble and use Melba23's ExtMsgBox. It will fulfill your need and a lot more; it's fully customisable.
vgt1 Posted October 25, 2018 Author Posted October 25, 2018 Thanks, the ExtMsgBox does it for me. Now I just need to do/find something for input boxes, but those I can probably make a constant size since I have a smaller variety of messages to display for inputs and no line feeds in them.
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