Access Violation in TeeChart - activex

Below code gives me access violation. Can anyone help me with this.
for(long i = nTools-1; i > 0 ; i--)
{
if(m_spGraph.GetTools().GetItems(i).GetToolType() == 25 && m_spGraph.GetTools().GetItems(i).GetAsRectangle().GetAllowDrag() == TRUE) // Rectangle tool
{
m_spGraph.GetTools().Delete(i);
}
}
Thanks
Akshay

In VB6, if I run this and then I open an Editor I see 5 Rectangle tools and 5 Annotation tools:
TChart1.AddSeries scBar
TChart1.Series(0).FillSampleValues 8
Dim i As Integer
For i = 0 To 9
If (i Mod 2 = 0) Then
TChart1.Tools.Add tcRectangle
Else
TChart1.Tools.Add tcAnnotate
End If
Next i
Then, If I run this and I open the editor again after it, I only see the 5 Annotation tools:
For i = TChart1.Tools.Count - 1 To 0 Step -1
If (TChart1.Tools.Items(i).ToolType = 25 And TChart1.Tools.Items(i).asRectangle.AllowDrag) Then
TChart1.Tools.Delete i
End If
Next i
So it seems to work fine for me here.
Have you tried it with different TeeChart ActiveX builds? Have you obtained different results with each them?
Please, edit your question adding an SSCCE so we can reproduce the problem here and try to figure if there's a problem in your code or in the component.

Related

Use ImageSearch to control the menus of Google Sheets

Did someone try to use ImageSearch to control the menus of google sheets? It's somehow failing me.
I simulated a right click on column A and then tried to find the option to change the size of the column with ImageSearch. I even put *n to 60 and that kind of worked but with the unpleasant side effect that it took at least 2 seconds for AutoHotkey to detect the image/word and then click on it. Does this work for your or do you have the same problem as me?
This is my ImageSearch function:
ImageSearchFunction(ImagePath){
start := A_TickCount
Loop {
ImageSearch, FoundX, FoundY, 0, 0, 1373, 775, *60 %ImagePath%
totalTime := stop - start
stop := A_TickCount
ClickX := FoundX + 15
ClickY := FoundY + 15
if ErrorLevel = 0
{
break
}
else if totalTime > 3000
{
MsgBox, Something went wrong!
exit
}
}
}
I solve it with a mousemove to the same place within the window every time and it works more consistently than image search did:
!e:: ; "Tools" is at x540 y245
{
CoordMode, Mouse, Relative
MouseMove, 540, 250,0
MouseGetPos, xpos, ypos
MouseClick
MouseMove, xpos, ypos+125,3
MouseClick
return
}
ImageSearch will work for a day or two and then just not work, no idea why. this one I have to adjust a lot less often.
edit. this script goes to "tools > script editor"

AC dimmer using micropython

I want to control AC Light Dimmer using Micro Python with ESP8266. I am not getting any libraries or examples related to this.Could anyone please help me with this
Thanks in advance!
Actually, it depends on which type of AC dimmer you have. I would expect something like RobotDyn AC dimmer:
Robodyn AC dimmer
In this case the regulation is not so easy like in the case of standard DC PWM (please don't let youself being confused by PWM pin, it is not real PWM). This module is standard triac dimmer which needs controlled dimming process (see this schematics).
The way how regulation works is based on the fact that you know when AC sine goes through zero (twice per period). Therefore there is Z-C input pin. When voltage goes through zero, you open triac for a while and cut off part of sine. Thats about regulation.
Wave regulation image
And this is what your dimmer driver shall do. This is not easy task in micropython as it requires to involve interrupts. You can see following code which I tried on HW and which was "working":
from machine import Timer, Pin
from micropython import alloc_emergency_exception_buf
from math import acos, pi
class Dimmer:
def __init__(self, pwm_pin, zc_pin, fpulse = 4000):
alloc_emergency_exception_buf(100)
self._cnt = 0
self._freq = 0
self._timer = Timer(2)
self._mode = Timer.ONE_SHOT
self._pwm = Pin(pwm_pin, Pin.OUT)
self._fpulse = fpulse
self._ppulse = 100.0 / fpulse + 0.11
self._zc = Pin(zc_pin, Pin.IN)
self._val = 1
self._zc.irq(trigger = Pin.IRQ_RISING | Pin.IRQ_FALLING, handler = self._zeroDetectIsr)
def _zeroDetectIsr(self, pin):
if 0 == self._freq:
self._pwm.on()
return
if 0 > self._freq:
self._pwm.off()
return
self._cnt += 1
if 1 == self._cnt:
self._timer.init(freq = self._freq, mode = self._mode, callback = self._dimmDelayIsr)
def _dimmDelayIsr(self, _timer):
if 1 == self._cnt:
self._pwm.on()
self._timer.init(freq = self._fpulse, mode = self._mode, callback = self._dimmDelayIsr)
else:
self._pwm.off()
self._cnt = 0
#property
def value(self):
return self._val
#value.setter
def value(self, p):
p = min(1, max(0, p))
if not self._val == p:
self._val = p
p = acos(1 - p * 2) / pi
if p < self._ppulse:
f = -1
elif p > 0.99:
f = 0
else:
f = 100 / (1 - p)
self._freq = int(f)
return self._val
Just note that unlike transistor, triac holds opened state till voltage on it drops to 0, so you can even use just short pulse to open it.
Use of driver is then simple:
from dimmer import Dimmer
dimmer = Dimmer(4, 2)
dimmer.value = 0.3
Unfortunately, micropython on ESP32 is locking interrupts quite often, so whole stuff works only when nothing is happening around. Most visible problems was around print function which was sometimes able to block for several AC sine periods, what caused visible bulb blinking. Unfortunately I would expect something similar in the case of WiFi communication.
The conclusion here is that the best solution is to use some cheep AVR based board and write code in C++ which will just care about dimming and nothing else. Such board can be connected to ESP board over I2C bus and ESP only sends command to set dimmer value.

Checking if a number fits between two numbers in objective c? [duplicate]

This question already has answers here:
How to test to see if number is in range using Objective-C?
(6 answers)
Closed 7 years ago.
I was wondering if it's possible to check if a number fits between two numbers in Objective C. For example:
if (variable == 1-100) {
//Do Something
}
I don't mean if the variable is equal to 1 minus 100. I want to know if the variable fits between 1 and 100. I understand this may not be possible but I'm interested to know so if it is possible.
Try below code..
if(variable >= MINVALUE && variable <= MAXVALUE){
** Do your stuff here**
}
In Objective-C you can use this simple check:
if (variable >=1 && variable <= 100)
In Swift it's even easier:
if 1 ... 100 ~= variable
If, by "the variable fits between 1 and 100" you mean "variable should be between 1 and 100, including 1 and 100" then it is pretty trivial:
if (variable >= 1 && variable <= 100) {
//Do Someting
}
NB: The "&&" is the logical test operator AND commonly used in C, C++, Objective-C, Java...
You can do this:
if ( var >= 1 && var <= 100 ){ ... }

Decide different outcomes of team position by score

I don't know if this is the right place to ask such a question but I hope so! I'm developing a game for fun where you have different teams who get points for each kick they can do in volley with a football. When the game is over I'm counting the score of each team and sort them by the best score.
So say:
team 1 = 9 points
team 2 = 7 points
team 3 = 20 points
Then I've sorted it by the best one, so the positions are:
team 3 = 20 points
team 1 = 9 points
team 2 = 7 points
Then I print it on the screen and say like "Team 3 comes on first place with 20 points". "Team 1...second", "team 2 .....third".
The problem is when some of the teams get the same score. So say it ends up like this:
team 1 = 9 points
team 2 = 9 points
team 3 = 20 points
In such case I want it to print like: "Team 3 comes on first place with 20 points", "Team 1 and Team 2 comes on second place with 9 points each".
Here is the problem, I've been thinking and thinking but I can't come up with a smart solution of how to make the code consider a shared first/second/third place.
Here is my current code that doesn't take account of that:
for var i = 0; i < teamScoreArray.count; ++i { //sorted array by best score first
var tmpTeam:Team = teamScoreArray[i]
if i == 0{
firstPlacelbl.text = "On first place comes \(tmpTeam.teamName) with \(tmpTeam.teamScore) points"
}
if i == 1{
secondPlacelbl.text = "On second place comes \(tmpTeam.teamName) with \(tmpTeam.teamScore) points"
}
if i == 2{
thirdPlacelbl.text = "On third place comes \(tmpTeam.teamName) with \(tmpTeam.teamScore) points"
}
if i == 3{
fourthPlacelbl.text = "On fourth place comes \(tmpTeam.teamName) with \(tmpTeam.teamScore) points"
}
prevScore = tmpTeam.teamScore
}
Does anyone have any idea of how to make this?
Thank you in advance!
Increase the rank only when the score in the current iteration differs from the previous one:
var rank = 0
var previousScore = 0
for team in teamScoreArray {
if team.teamScore != previousScore {
rank += 1
}
println("Rank \(rank): \(team.teamName)")
previousScore = team.teamScore
}

Write QR-Code failed

I have a project using Xamarin with MvvmCross. In this project i want to create a QR-Code in a MvvmCross Plugin. I have it working in the Android plugint. However, the iOS plugin creates an corrupted image, which I cannot open after creation.
I use ZXing.Net PCL (Version: 0.14.0.1)
My code:
public byte[] GenerateQrImage(string content, int width, int height)
{
if (string.IsNullOrEmpty(content) || width <= 0 || height <= 0) return null;
var options = new QrCodeEncodingOptions
{
Height = height,
Width = width,
Margin = 0,
PureBarcode = true
};
var writer = new BarcodeWriter
{
Format = BarcodeFormat.QR_CODE,
Options = options
};
// Get bytes
return writer.Write(content);
}
The above code returns a byte array which I can save. When I open the application folder on my Mac, I cant open the image (I think its corrupt).
Can anyone tell me, how i can solve this problem? Thanks
After many tests (and also many fails) i found the solution. I took the wrong nuget-package. Just reference to Zxing.Net.Mobile and the qr-image generation works.
At the end it's the same problem described here.

Resources