Help My Balloon finding macro is not working with input box, it works only when i manually add the balloon number.. please tell me what i m missing ...Ferdo m expecting you
Language="VBSCRIPT"
Sub CATMain()
Set drawingDocument1 = CATIA.ActiveDocument
Set selection1 = drawingDocument1.Selection
result = InputBox("Ballon Number ?", "Title") 'The variable is assigned the value entered in the InputBox
selection1.Search "CATDrwSearch.DrwBalloon.BalloonPartName_CAP= result ,all"
End Sub
I don't know what you are doing but the last line looks wrong. I don't know what the docs are for your function but you are passing the string result rather than the value of the variable result because it is in quotes. Assuming your line is otherwise right ...
selection1.Search "CATDrwSearch.DrwBalloon.BalloonPartName_CAP= " & result & ",all"
Related
I'm using AutoHotkey for this as the code is the most understandable to me. So I have a document with numbers and text, for example like this
120344 text text text
234000 text text
and the desired output is
12:03:44 text text text
23:40:00 text text
I'm sure StrReplace can be used to insert the colons in, but I'm not sure how to specify the position of the colons or ask AHK to 'find' specific strings of 6 digit numbers. Before, I would have highlighted the text I want to apply StrReplace to and then press a hotkey, but I was wondering if there is a more efficient way to do this that doesn't need my interaction. Even just pointing to the relevant functions I would need to look into to do this would be helpful! Thanks so much, I'm still very new to programming.
hfontanez's answer was very helpful in figuring out that for this problem, I had to use a loop and substring function. I'm sure there are much less messy ways to write this code, but this is the final version of what worked for my purposes:
Loop, read, C:\[location of input file]
{
{ If A_LoopReadLine = ;
Continue ; this part is to ignore the blank lines in the file
}
{
one := A_LoopReadLine
x := SubStr(one, 1, 2)
y := SubStr(one, 3, 2)
z := SubStr(one, 5)
two := x . ":" . y . ":" . z
FileAppend, %two%`r`n, C:\[location of output file]
}
}
return
Assuming that the "timestamp" component is always 6 characters long and always at the beginning of the string, this solution should work just fine.
String test = "012345 test test test";
test = test.substring(0, 2) + ":" + test.substring(2, 4) + ":" + test.substring(4, test.length());
This outputs 01:23:45 test test test
Why? Because you are temporarily creating a String object that it's two characters long and then you insert the colon before taking the next pair. Lastly, you append the rest of the String and assign it to whichever String variable you want. Remember, the substring method doesn't modify the String object you are calling the method on. This method returns a "new" String object. Therefore, the variable test is unmodified until the assignment operation kicks in at the end.
Alternatively, you can use a StringBuilder and append each component like this:
StringBuilder sbuff = new StringBuilder();
sbuff.append(test.substring(0,2));
sbuff.append(":");
sbuff.append(test.substring(2,4));
sbuff.append(":");
sbuff.append(test.substring(4,test.length()));
test = sbuff.toString();
You could also use a "fancy" loop to do this, but I think for something this simple, looping is just overkill. Oh, I almost forgot, this should work with both of your test strings because after the last colon insert, the code takes the substring from index position 4 all the way to the end of the string indiscriminately.
What is the output of an InputBox command that is left empty
Is there a good way to check if the feild was left empty
like if OutputVar = "" { goto, restart }
i've tried the solution above and it didn't work for me any help is appreciated
This is what I use:
InputBox, text, Enter Text
if(text)
MsgBox Something was inputed
else{
MsgBox Nothing was inputed
goto restart
}
The output of an empty InputBox is not a value, so you can just check whether or not the variable you store the output as has a value or not through an if(variable) statement.
Edit responding to comment:
AHK is special in that you do not need a boolean value (i.e. True or False) within an if statement in order for it to work (in contrast to traditional programming languages). In ahk, if the value inside the parenthesis of an if statement is a non-boolean data type (i.e. a number), the program will treat it as true if the value is non-zero. This can be seen with the following code:
text:=0 ; Alternatively: text:=""
if(text)
MsgBox True was triggered!
else
MsgBox False was triggered!
Another Edit after I noticed something:
The idea behind the code you had above also works, provided that you move the curly braces/ content to the next line.
So either
if (text = "")
{
MsgBox hello
}
or
if (text = "")
MsgBox hello
is also fine.
my #para_text = $mech->xpath('/html/body/form/table/tbody/tr[2]/td[3]/table/tbody/tr[2]/td/table/tbody/tr[3]/td/div/div/div', type => $mech->xpathResult('STRING_TYPE'));
#BELOW IS JUST TO MAKE SURE THE ABOVE CAPTURED THE CORRECT TEXT
print "Look here: #para_text";
$mech->click_button( id => "lnkHdrreplyall");
$mech->eval_in_page('document.getElementsByName("txtbdy")[0].value = "#para_text"');
In the last line of my code I need to put the contents of the #para_text array as the text to output into a text box on a website however from the "document" till the end of the line it needs to be surrounded by ' ' to work. Obviously this doesnt allow interpolation as that would require " " Any ideas on what to do?
To define a string that itself contains double quotes as well as interpolating variable values, you may use the alternative form of the double quote qq/ ... /, where you can choose the delimiter yourself and prevent the double quote " from being special
So you can write
$mech->eval_in_page(qq/document.getElementsByName("txtbdy")[0].value = "#para_text"/)
I found a similar question that asks how to get a value of a WebElement and put it in an excel file and then e-mail the excel file, but how do I put that value of a WEbElement in the body of an e-mail in the middle of a sentence and NOT in an excel file?
For example, I want to capture a WebElement that tells me how many coke points I have and then I want to e-mail myself that value. Something like: "You have 500 Coke Points now".
This is what I have, but i'm getting a syntax error:
Dim ResultsFile
Set objOutlook=CreateObject("Outlook.Application")
Set objOutlookMsg=objOutlook.CreateItem(olMailItem)
objOutlookMsg.To="email#email.com"
ResultsFile="C:\Documents and Settings\Administrator\My Documents\CkeZeroPoints.xlsx"
objOutlookMsg.Subject="Coke Zero points"
objOutlookMsg.Body="You now have" &Browser("Sweepstakes.*").Page("Sweepstakes.*").WebElement("htmlID:=glPointsText").GetRoProperty("innertext") "Coke Zero points."
objOutlookMsg.Attachments.Add(ResultsFile)
objOutlookMsg.Display
objOutlookMsg.Send
Set objOutlookMsg=Nothing
Set objOutlook=Nothing
The syntax error starts on line 7.
Thank you in advance.
You forgot an ampersand (&):
Dim ResultsFile, innerText
Set objOutlook=CreateObject("Outlook.Application")
Set objOutlookMsg=objOutlook.CreateItem(olMailItem)
' Better to separate tasks so you can trap errors earlier
innerText = Browser("Sweepstakes.*").Page("Sweepstakes.*").WebElement("htmlID:=glPointsText").GetRoProperty("innertext")
ResultsFile = "C:\Documents and Settings\Administrator\My Documents\CkeZeroPoints.xlsx"
' email handling here, you can refactor this in a separate method
objOutlookMsg.To ="email#email.com"
objOutlookMsg.Subject = "Coke Zero points"
objOutlookMsg.Body = "You now have " & innerText & " Coke Zero points." ' <-- ampersand added on this line.
objOutlookMsg.Attachments.Add ResultsFile ' <-- parenthesis removed, only us parenthesis if
' you are calling a (returning) function
objOutlookMsg.Display
objOutlookMsg.Send
Set objOutlookMsg = Nothing
Set objOutlook = Nothing
Hi I'm trying to write some VBA so that it checks whether one of my text boxes contains a number. The text box is called: CustomerName. Here's the code I am currently using:
Function HasNumber(strData As String) As Boolean
Dim iCnt As Integer
For iCnt = 1 To Len(strData)
If IsNumeric(Mid(strData, iCnt, 1)) Then
HasNumber = True
Exit Function
End If
Next iCnt
End Function
Private Sub CustomerName_AfterUpdate()
If HasNumber(CustomerName) Then
MsgBox "Only letters are allowed for this field."
Exit Sub
End If
End Sub
For some reason when I enter numbers into this field and then click out of it (i.e. update it) it doesn't come up with a msgbox or anything. What can I do to fix this?
Instead of using some custom code, I would use this validation rule on the CustomerName column of your table, or on the validation rule of your text box:
Not Like "*[0-9]*"
See here for a reference of validation rules.
Try it like this:
If HasNumber(CustomerName.Text) Then