-
Re: Power sign (^) and 'continue' in loops
Ivana Kolin Nov 25, 2015 6:51 PM (in response to Peter Brinkhuis)continue is .NET syntax.
can you try this?
debug.print 2^2
-
Re: Power sign (^) and 'continue' in loops
Peter Brinkhuis Nov 26, 2015 3:42 AM (in response to Ivana Kolin)When I type
Debug.Print 2^2
it automatically replaces it with
Debug.Print 2^; 2
The output to the immediate window is
2 2
But when I type:
Debug.Print 2 ^ 2
Debug.Print i ^ 2
Debug.Print 2 ^ i
It works Seems that the extra space is required. And when you read the MSDN link from Roland (which I already went through yesterday) very literally, you might notice the extra space.
And regarding the do while/ continue do topic, I've read the links below. I would like to go to the next iteration of the loop immediately.
https://msdn.microsoft.com/en-us/library/eked04a7.aspx
https://msdn.microsoft.com/en-us/library/801hyx6f.aspx
After writing the line "continue do" I get the message "Compile error: expected: expression".
-
Re: Power sign (^) and 'continue' in loops
Ivana Kolin Nov 26, 2015 4:37 AM (in response to Peter Brinkhuis)Sub main() Dim swApp As Object Set swApp = Application.SldWorks Dim i As Integer i = 0 Do While i < 10 MsgBox (i) If i = 5 Then i = 9 GoTo continue End If i = i + 1 continue: Loop End Sub
-
Re: Power sign (^) and 'continue' in loops
Peter Brinkhuis Nov 26, 2015 4:01 PM (in response to Ivana Kolin)This works, so thanks But is it according to the MSDN documentation? I'm trying to figure out how to follow those instructions, get my code running and find out if it is just another quirk of Solidworks or not. If I follow Microsoft's documentation, the line "Dim i As Integer = 6" would also work, which it doesn't.
-
Re: Power sign (^) and 'continue' in loops
Ivana Kolin Nov 26, 2015 4:41 PM (in response to Peter Brinkhuis)dim i as integer = 6
loop and continue is VB.NET and not vba.
VBA - macro is more like VB6
-
Re: Power sign (^) and 'continue' in loops
Peter Brinkhuis Nov 27, 2015 5:32 AM (in response to Ivana Kolin)Thanks, I'm sure that's the case. Too bad I couldn't find that out from the Microsoft documentation.
-
-
-
-
Re: Power sign (^) and 'continue' in loops
Roland Schwarz Nov 27, 2015 2:05 PM (in response to Peter Brinkhuis)Ordinarily I would give someone grief for marking their own answer correct. In this case, it seems you did indeed solve your own problem (at least in the final steps).
-
Re: Power sign (^) and 'continue' in loops
Peter Brinkhuis Nov 28, 2015 4:27 AM (in response to Roland Schwarz)Haha yeah I know, I thought about that before choosing the answer. Hope my findings help other people as well.
-
-
-
-
Re: Power sign (^) and 'continue' in loops
Roland Schwarz Nov 25, 2015 7:52 PM (in response to Peter Brinkhuis)In the first program, i is never assigned a value (default i=0?)
-
Re: Power sign (^) and 'continue' in loops
Subhra Maiti Nov 26, 2015 6:27 AM (in response to Peter Brinkhuis)It seems interesting i^2 doesn't work and I don't know why?
But there is a solution, if you have excel installed. Then you bypass the problem by using WorksheetFunction.power(x, y)
Here is the code for you.
Option Explicit
Dim xlApp As Object
Dim swApp As Object
Sub main()
Set swApp = Application.SldWorks
Set xlApp = CreateObject("Excel.Application")
Dim a As Double
a = xlApp.WorksheetFunction.power(2, 3)
MsgBox (a)
End Sub
-
Re: Power sign (^) and 'continue' in loops
Ian Worrall Nov 26, 2015 6:53 AM (in response to Subhra Maiti)I wonder if instead of i^2, you could use i*i (as that's all squaring something is)?
-
Re: Power sign (^) and 'continue' in loops
Peter Brinkhuis Nov 26, 2015 7:20 AM (in response to Ian Worrall)I'm sure multiplying multiple times would work. In my case it was a little harder to do because I wanted to do 10^i.
Subhra, thanks for you workaround. But as said in my previous post, it works in Solidworks when you add spaces between the symbols, so "i ^ 2" will work.
-
Re: Power sign (^) and 'continue' in loops
Subhra Maiti Nov 26, 2015 11:05 AM (in response to Peter Brinkhuis)Peter Brinkhuis Please marked it as resolved.
-
-
-