I'm using QTP 11.0 which uses VBScript for it's "language".
I have the following four lines of code:
For x = 1 to 8
msgbox(x)
update1 = SwfWindow("NextGen File Maintenance").SwfWindow("SIM Library Configuration").SwfObject("spreadCtl").Object.ActiveSheet.GetValue(x,2)
Next
The return values are:
1
3
3
3
3
3
... forever
I can not seem to use the counter variable in a vbscript for loop without it somehow becoming corrupted - no matter what the name of the variable. I have even tried assigning X to another variable and using that in my GetValue statement with no success.
Am I missing something really simple here? No documentation on Google for a vbscript For loop implies any different usage. I found nothing in reference to QTP either.
Thanks,
Jason
This is very strange, I assume that if you remove the second line in the loop and just leave the MsgBox then x is incremented correctly.
Perhaps ActiveSheet.GetValue takes the first parameter by reference and modifies it. You say that you tried using a temporary variable and it didn't work, have you tried something like this?
For x = 1 to 8
tmp = x
update1 = SwfWindow("NextGen File Maintenance").SwfWindow("SIM Library Configuration").SwfObject("spreadCtl").Object.ActiveSheet.GetValue(tmp, 2)
MsgBox("x=" & x & " tmp=" & tmp)
Next
If the problem is that GetValue indeed changes the index you can try using a function that takes the index by value and then use that in the loop.
Public Function GetVal(ByVal index)
GetVal = SwfWindow("NextGen File Maintenance").SwfWindow("SIM Library Configuration").SwfObject("spreadCtl").Object.ActiveSheet.GetValue(index, 2)
End Function
Related
So I want to have different Variables with the same name, except for the numbers at the end. The number increases over time, since it's in a repeat loop.
set i to 0
repeat 6 times
set i to i + 1
set SampleVar & i to i + 10
end repeat
end run
This Syntax is probably completely wrong but, I hope you understand, what I want to achieve.
As already mentioned in the comments by red_menace:
You cannot dynamically create variables like that, they need to be declared at compile time. The normal way to use collections would be to use a list or record.
This is your script rewritten to use lists:
set SampleList to {}
set i to 0
repeat 6 times
set i to i + 1
set the end of SampleList to i
end repeat
I don't know what the advantages of writing it as a record are but it usually takes longer and I'm not quite as familiar with them as I am with lists.
While reproducing an example from IBM documentation: https://www.ibm.com/support/knowledgecenter/SSMKHH_9.0.0/com.ibm.etools.mft.doc/ak04864_.htm
with the following example message:
https://www.ibm.com/support/knowledgecenter/SSMKHH_9.0.0/com.ibm.etools.mft.doc/ak05911_.htm
without application of the message model,
on:
IBM Integration Toolkit Version: 10.0.0.16
with the following code fragment:
CALL CopyEntireMessage();
-- Declare the dynamic reference
DECLARE myref REFERENCE TO OutputRoot.XMLNSC.Invoice.Purchases.Item[1];
-- Continue processing for each item in the array
WHILE LASTMOVE(myref)=TRUE
DO
-- Add 1 to each item in the array
SET myref = CAST(myref AS INTEGER) + 1;
-- Move the dynamic reference to the next item in the array
MOVE myref NEXTSIBLING;
END WHILE;
I suddenly found out that the following line of code:
SET myref = myref + 1;
or alternatively:
SET myref = CAST(myref AS INTEGER) + 1;
did not have any effect on the value in the first item, and, even more, it was preventing expected work of:
MOVE myref NEXTSIBLING;
so that the myref pointer did not move to the next sibling (did not move from the item[1] to the item[2]) and myref was just disappearing from the list of variables in my debug view.
My question:
Any idea why SET myref = myref + 1; or SET myref = CAST(myref AS INTEGER) + 1; do not work? According to the document, the latter should work without the message model.
I cannot explain the symptoms, but I can make a couple of helpful suggestions:
Don't use counted loops in ESQL. It is almost always better to use a FOR loop to iterate over an array.
CALL CopyEntireMessage();
-- For each item in the array...
FOR refItem AS OutputRoot.XMLNSC.Invoice.Purchases.Item[] DO
SET refItem = CAST(refItem AS INTEGER) + 1;
END FOR;
No need to declare the reference variable (but you can if you want to, to stop the ESQL editor from complaining about the 'undeclared' reference variable).
No need to move the reference variable yourself - the FOR loop does it for you.
If you really want to know why your WHILE loop is not working...
You will find that the debugger only tells you what is happening. But (as you are finding out) it cannot tell you why it is happening. For that, you need a user trace. Not a Trace node, a user trace. You have to open the IIB console and use the mqsichangetrace, mqsireadlog, mqsiformatlog commands (in that order) to start user trace, read it and format it as text. It's a bit of hassle the first couple of times, but it will almost certainly show you why your code is not working.
When I run my code one error occurs with my code setindex! not defined for WeakRefStrings.StringArray{String,1}
CSV File here.
using CSV
EVDdata =CSV.read(raw"wikipediaEVDdatesconverted.csv")
EVDdata[end-9:end,:]
And the Error Code is here
rows, cols = size(EVDdata)
for j =1:cols
for i = 1:rows
if !isdigit(string(EVDdata[i, j])[1])
EVDdata[i,j] = 0
end
end
end
I am working with Julia 1.4.1 on Jupter Notebook
setindex!(collection, item, inds...) is the function that colection[inds...] = item gets lowered to. The error comes from the fact that CSV.read makes an immutable collection.
As Oscar says in his answer, setindex! tries to mutate its arguments, i.e. change the contents of your column in place. When you do CSV.read(), by default immutable columns of type CSV.Column are returned. This is done for performance reason, as it means columns don't have to be copied after parsing.
To get around this, you can do two things:
Pass the keyword argument CSV.read(raw"wikipediaEVDdatesconverted.csv", copycols = true) - this will copy the columns and therefore make them mutable; or
Achieve the same by using DataFrame((raw"wikipediaEVDdatesconverted.csv"))
The second way is the preferred way as CSV.read will be deprecated in the CSV.jl package.
You can see that it's current implementation is basically doing the same thing I listed in (2) above in the source here. Removing this method will allow CSV.jl not to depend on DataFrames.jl anymore.
It could also be done this way
col1dt = Vector{Dates.DateTime}(undef, length(col1))
for v = 1:length(col1)
col1dt[v] = Dates.DateTime(col1[v], "d-u-y")
end
I want to show "c:\project\ndev" by message box but the result print "\n" as a new line, hence the actual result is "c:\project" + new line + "dev"
Anyone know how to treat this case? I've spent so much time for that but still have no solution.
I have tried two variations on calling the msgbox function on a Windows 8 box.
Option 1 - Using sub procedure
x=msgbox("c:\project\ndev",0,"Your drive letter information")
Result
Option 2 - Use plain msgbox call.
msgbox("c:\project\ndev")
Result:
I am currently trying you learn VB6 and came across this issue.
I wanted to loop through a for loop and adding a number to a control name.
Dim I As Integer
For I = 1 To 5
S = CStr(I)
If TextS.Text = "" Then
LabelS.ForeColor = &HFF&
Else
LabelS.ForeColor = &H80000012
End If
Next I
This S needs to be added to Text and Label so the colour will be changed without needing to use 5 If Else statements
I hope you can help me with this.
From your comment below:
What i mean is this: If Text1.text = "" Then I need this 1 to be replaced with the variable I, so the for loop can loop through my 5 textboxes and the same for my Labels.
You can't do that (look up a variable using an expression to create its name) in VB6. (Edit: While that statement is true, it's not true that you can't look up form controls using a name from an expression. See "alternative" below.)
What you can do is make an array of your textboxes, and then index into that array. The dev env even helps you do that: Open your form in the dev env and click the first textbox. Change its name to the name you want the array to have (perhaps TextBoxes). Then click the next textbox and change its name to the same thing (TextBoxes). The dev env will ask you:
(Don't ask me why I have a VM lying around with VB6 on it...)
Click Yes, and then you can rename your other textboxes TextBoxes to add them to the array. Then do the same for your labels.
Then your code should look like this:
For I = TextBoxes.LBound To TextBoxes.UBound
If TextBoxes(I).Text = "" Then
Labels(I).ForeColor = &HFF&
Else
Labels(I).ForeColor = &H80000012
End If
Next
LBound is the lowest index of the control array, UBound is the highest. (You can't use the standard LBound and Ubound that take the array as an argument, because control arrays aren't quite normal arrays.) Note also that there's no need to put I on the Next line, that hasn't been required since VB4 or VB5. You can, though, if you like being explicit.
Just make sure that you have exactly the same number of TextBoxes as Labels. Alternately, you could create a user control that consisted of a label and a textbox, and then have a control array of your user control.
Alternative: : You can use the Controls array to look up a control using a name resulting from an expression, like this:
For I = 1 To 5
If Me.Controls("Text" & I).Text = "" Then
Me.Controls("Label" & I).ForeColor = &HFF&
Else
Me.Controls("Label" & I).ForeColor = &H80000012
End If
Next
This has the advantage of mapping over to a very similar construct in VB.Net, should you migrate at some point.
Side note:
I am currently trying you learn VB6...
(tl;dr - I'd recommend learning something else instead, VB6 is outdated and the dev env hasn't been supported in years.)
VB6's development environment has been discontinued and unsupported for years (since 2008). The runtime is still (I believe) supported because of the sheer number of apps that use it, although the most recent patch seems to be from 2012. But FWIW, you'd get a better return on your study time learning VB.net or C#.Net (or any of several non-Microsoft languages), rather than VB6...