In a RichTextBox, when sending EM_LINEINDEX to get the index of the first character of a line, the index will be affected by soft line breaks. Consider the following text box:
Calling SendMessage hWnd, EM_LINEINDEX, 1, 0 will result in 25, while I would expect it to return 45 (line 1 should be "this is another line" not "and continues here").
Is there a way to get the real first char index of the second line using WinAPI calls?
This is from a working program. I play with right margin.
Sub mnuWordWrap_Click()
'On Error Resume Next
If txtNote.RightMargin = 0 Then
txtNote.RightMargin = &HFFFE&
mnuWordWrap.Checked = False
Else
txtNote.RightMargin = 0
mnuWordWrap.Checked = True
End If
txtNote.SetFocus
txtNote_SelChange
End Sub
In another program I do this, though this is Vista's RTF window (not a control so not the old ANSI version of RTF as in VB6)
If mnuViewWordWrap.Checked = True Then
Ret = SendMessageByVal(gRtfHwnd, EM_SETTARGETDEVICE, GetDC(gRtfHwnd), -1800)
If Ret = 0 Then ReportError "Form Resize", "Set Target Device"
Else
Ret = SendMessageByVal(gRtfHwnd, EM_SETTARGETDEVICE, GetDC(gRtfHwnd), 4000000)
If Ret = 0 Then ReportError "Form Resize", "Set Target Device"
End If
Related
I have a script that has a GUI and I have been running with a start button using the below code:
Case $StartButton
I would also like to try scheduling this using Windows TaskScheduler to run every morning at 8 AM EST. What would be the best way to add a condition to either start with the start button OR when TaskScheduler runs at 8 AM EST (or any specific time)? I am hesitant to just do 8 AM condition as it may increase processing a lot always looking at the time.
Essentially what I am looking to have happen is for my computer to auto-unlock (login?) using task scheduler and run this AutoIt script which has been compiled to exe.
FilePath is: C:\Users\robert\OneDrive\Desktop\TempFile.exe
Block of relevant code is below:
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
Case $Save
SaveOptions()
Case $StartButton
;TAB1 of GUI
If WinExists("[CLASS: QT373947473845]") Then
$oBlah = WinGetHandle("[CLASS: QT373947473845]")
$BSLoc = WinGetPos ("[CLASS: QT373947473845]")
If $BSLoc[0] <> 0 or $BSLoc[1] <> 0 or $BSLoc[2] <> 800 or $BSLoc[3] <> 600 Then
WinSetState ( $oBlah, "", #SW_MINIMIZE )
sleep(500)
WinActivate($oBlah)
WinWaitActive($oBlah)
WinMove($oBlah, "", 0, 0, 800, 600)
sleep(2000)
Else
WinActivate($oBlah)
WinWaitActive($oBlah)
sleep(2000)
EndIf
Endif
EndSwitch
WEnd
I have thousands of lines of other code within the case but I tried to limit it as that portion is irrelevant
The Case $StartButton is the line where I am trying to do an OR if run by TaskManager. I have read you cannot do an OR function within a switch case but if you do 2 cases without a break it is the same thing?
I read some documentation and saw I can add a “/prim1=value” to the end of the command line and it will pass the prim1 argument to $CmdLine[0] but I can’t seem to get it working properly.
Review the documentation.
Particularly this part:
So if you were to use the compiled executable by passing commandline
parameters:
myProg.exe param1 "This is a string parameter" 99
$CmdLine[0] ; this equals 3 (because there are 3 command line parameters)
$CmdLine[1] ; This contains "param1".
$CmdLine[2] ; This contains "This is a string parameter".
$CmdLine[3] ; This contains 99.
So then just modify the code so that it behaves differently if $CmdLine[1] = something.
As for the switch case: that is inside of a message loop for the GUI and the code in the Case $StartButton part of the switch block is run when the start button is pressed and $nMsg is equal to the control ID of the start button ($StartButton).
If you want to run this code at some other time what I would do it just move all of that code into its own function:
Func onStartClick()
; start button code here
Endfunc
And then just call onStartClick() in the switch block:
$nMsg = GUIGetMsg()
Switch $nMsg
Case $StartButton
onStartClick()
Case $someOtherButton
; someOtherButton code...etc
EndSwitch
And then you can also call this function if there is a particular command line param (place this code before the Switch...EndSwitch block, not inside it):
If $CmdLine[0] >= 1 And $CmdLine[1] = "param1" then
; other code to run when started with "program.exe param1"
onStartClick()
EndIf
So the entire thing would look like this:
Func onStartClick()
; start button code here
Endfunc
If $CmdLine[0] >= 1 And $CmdLine[1] = "param1" then
; other code to run when started with "param1"
onStartClick()
EndIf
$nMsg = GUIGetMsg()
Switch $nMsg
Case $StartButton
onStartClick()
Case $someOtherButton
; someOtherButton code...etc
EndSwitch
I have a file called worker.dat, and in that file, a list of information is stored as variables "Income","Promotion", "Age" etc.
And I want to read that information from the file and print on the screen.
So I used
Open App.Path & "worker.DAT" For Input As #1
and using the Print method, printed the information.
However for the sake of emphasis, I want to print some information in a bigger size and in different font etc.
So I wrote this.
Printer.FontSize = 16
Printer.Print "Income = "; Income
However this didn't work. Does anyone how to fix this problem?
Set the size on the font object:
Dim pt As Long
With Printer.Font
pt = .Size
Printer.Print "default text"
.Size = 16
Printer.Print "larger text"
.Size = pt
.Bold = True
Printer.Print "bold ";
.Bold = False
Printer.Print "in default size"
Printer.EndDoc
End With
I am automating a software installation in Windows7 using AutoIt.
During the installation, in between if a error window appears. I want to click ENTER.
If the error window not appears then I should NOT do anything. Simply its should go to the next section.
I have tried "WinActive and WinWaitActive" But its waiting for the window to appear. If window not appears its not going to the next screen.
Any idea how to handle this situation?
Do a while loop:
$w = 0
While($w = 0)
If(WinActive("ERROR WINDOW"))Then
Send("{ENTER}")
$w = 1
ElseIf(ControlGetText("YOUR WINDOW", "", "[CLASS:Static; INSTANCE:2]") <> "SOME TEXT") Then
$w = 1
;and something else
EndIf
Sleep(1000)
WEnd
AdlibRegister() is the right choice. From the help file:
"... typically to check for unforeseen errors. For example, you could use adlib in a script which causes an error window to pop up unpredictably."
Each 100 ms (may be adjusted) the function is called to check the appearing of your error dialog:
Global $sErrorWindow = 'ErrorDialogName'
Global $iDelayHowOftenDoTheFunctionCall = 100
AdlibRegister('_isErrorWindowDisplayed', $iDelayHowOftenDoTheFunctionCall)
Func _isErrorWindowDisplayed()
If WinActive($sErrorWindow) <> 0 Then
WinActivate($sErrorWindow) ; just to be sure that the ENTER command is on the correct window/dialog
; either do
Send('{ENTER}')
; or
ControlClick('title', 'text', 'controlID')
EndIf
EndFunc
; do your software installation processing here
; ...
; ...
; don't forget to unregister the function at the end
AdlibUnRegister('_isErrorWindowDisplayed')
The following must work in qtp so i can not use WScript.Echo. The following code have to ask for an integer between 1 to 10 inclusive using an inputbox. If nothing entered the it has to give a message "Aborted".
If anything else entered then it has to say what is the problem and ask again for the number until I abort by cancel or by entering nothing. I have the following code but it looks like it is skipping the first condition and goes to the first else in the loop:
Option Explicit
Dim vNum, sNum, nNum
Do
vNum = InputBox("Please enter an integer between 1 and 10 inclusive")
If IsEmpty(vNum) Then
msgbox("Aborted")
Exit Do
Else
sNum = Trim(vNum)
If "" = sNum Then
vNum=Inputbox("Empty string")
Else
If IsNumeric(sNum) Then
nNum = CDbl(sNum)
If nNum <> Fix(nNum) Then
vNum=inputbox("Not an Integer")
Else
If nNum < 1 Or nNum > 10 Then
vNum=inputbox ("Not in range")
Else
msgbox nNum,("number ok")
Exit Do
End If
End If
Else
vNum= inputbox ("Not a number")
End If
End If
End If
Loop
msgbox ("Done")
You could loop and change the instruction message each time:
Dim vNum, instruction
instruction = "Please enter an integer between 1 and 10 inclusive"
Do
vNum = InputBox(instruction)
If vNum = False Then
MsgBox "Aborted"
Exit Do
ElseIf CStr(Trim(vNum)) = "" Then
instruction = "Empty string"
ElseIf Not IsNumeric(vNum) Then
instruction = "Not an integer"
ElseIf IsNumeric(vNum) And vNum < 1 Or vNum > 10 Then
instruction = "Not in range"
ElseIf IsNumeric(vNum) And vNum > 0 And vNum < 11 Then
MsgBox "Number OK"
Exit Do
Else
instruction = "Invalid Entry"
End If
Loop
This is what help says.
If the user clicks OK or presses ENTER, the InputBox function returns whatever is in the text box. If the user clicks Cancel, the function returns a zero-length string ("").
So you aren't testing for a empty, or zero length, string. It is a valid string, just empty.
Also from Help the meaning of Empty in VBS, which has nothing to do with what's in a string.
Empty
The Empty keyword is used to indicate an uninitialized variable value. This is not the same thing as Null.
Update
HELP IS NOT WRONG. InputBox returns a zero length string just like the docs say.
A uninitialized variable HAS A VALUE (for numbers, dates, and strings)
0 for numbers
1899 sometime for dates
and a zero length string for strings (and a string of spaces for fixed length strings).
HELP IS NOT a TECHNICAL REFERENCE
Help is a CONTRACTUAL document describing behaviour not implementation. As in the COM philosophy.
This is known as LET COERCION. And why x=65:Msgbox x works. There are two variables there.
From VBA Implementers Guidelines
The semantics of Empty Let-coercion depend on the destination’s declared type: Source
Any numeric type - The result is 0.
Boolean - The result is False.
Date - The result is 12/30/1899 00:00:00.
String - The result is a 0-length string.
String * length - The result is a string containing length spaces.
Any class or Object - Runtime error 424 (Object required) is raised. -
Any other type except Variant - Runtime error 13 (Type mismatch) is raised.
I would like to get a working code to simply remove from a text line a specific part that always begins with "(" and finish with ")".
Sample text : Hello, how are you (it is a question)
I want to remove this part: "(it is a question)" to only keep this message "Hello, how are you"
Lost...
Thanks
One way using Regular Expressions;
input = "Hello, how are you (it is a question)"
dim re: set re = new regexp
with re
.pattern = "\(.*\)\s?" '//anything between () and if present 1 following whitespace
.global = true
input = re.Replace(input, "")
end with
msgbox input
If the part to be removed is always at the end of the string, string operations would work as well:
msg = "Hello, how are you (it is a question)"
pos = InStr(msg, "(")
If pos > 0 Then WScript.Echo Trim(Left(msg, pos-1))
If the sentence always ends with the ( ) section, use the split function:
line = "Hello, how are you (it is a question)"
splitter = split(line,"(") 'splitting the line into 2 sections, using ( as the divider
endStr = splitter(0) 'first section is index 0
MsgBox endStr 'Hello, how are you
If it is in the middle of the sentence, use the split function twice:
line = "Hello, how are you (it is a question) and further on"
splitter = split(line,"(")
strFirst = splitter(0) 'Hello, how are you
splitter1 = split(line,")")
strSecond = splitter1(UBound(Splitter1)) 'and further on
MsgBox strFirst & strSecond 'Hello, how are you and further on
If there is only one instance of "( )" then you could use a '1' in place of the UBound.
Multiple instances I would split the sentence and then break down each section containing the "( )" and concatenate the final sentence.