I have a working Excel VBA macro called CreateGraph that generates an Excel chart from existing data. I want to modify CreateGraph such that after the chart is created it adds a button on the chart itself that in turn can be used to call CreateGraph again to make a new (updated) chart.
After much trial and error, google searches, and abundant use of the macro recorder I have cobbled together the following:
Sub AddButtonForNewChart()
Dim MyButton As Button
Set MyButton = ActiveChart.Buttons.Add(1002750, 138119.25, 589949.25, 238461.75)
With MyButton
.Visible = True
.OnAction = "MainRoutine"
.Select
With Selection
.Characters.Text = "Create New Chart"
.AutoScaleFont = False
With .Characters(Start:=1, Length:=9).Font
.Name = "Calibri"
.FontStyle = "Regular"
.Size = 11
.Strikethrough = False
.Superscript = False
.Subscript = False
.OutlineFont = False
.Shadow = False
.Underline = xlUnderlineStyleNone
.ColorIndex = 1
End With
End With
End With
End Sub
This macro runs just fine .... except nothing is produced. No button anywhere.
Anyone have any thoughts?
Eurika! SMACK (the sound of palm hitting forehead). It turns out this routine WAS working all along. The length & width parameters for the Buttons.Add line were the culprit. They were part of the macro recorder generated effort, but for some unknown reason did not translate well. When replaced with more reasonable numbers ... viola ... everything worked. My working script now reads:
Sub AddButtonForNewChart()
Dim MyButton As Button
Set MyButton = ActiveChart.Buttons.Add(10, 10, 100, 25)
With MyButton
.Characters.Text = "Create New Chart"
.AutoScaleFont = False
.Visible = True
.OnAction = "MainRoutine"
End With
End Sub
Related
I'm pretty new to Rails and trying some basic stuff like conditional classes.
On the 'show' view I have an element that changes styling depending on the stock availability, but also the text changes accordingly.
People keep saying the controller should be as small as possible, but placing this conditional in the view also feels dirty. Is this really the best way?
Current controller:
def show
#tyre = Tyres::Tyre.find_by_id(params[:id])
if #tyre.in_stock
#availability = I18n.t("products.filter.other.in_stock")
#availability_class = 'i-check-circle color--success'
else
#availability = I18n.t("products.filter.other.not_in_stock")
#availability_class = 'i-cross-circle color--important'
end
end
Edit:
Controller:
def show
#tyre = Tyres::Tyre.find_by_id(params[:id])
if #tyre.in_stock
#availability_append = ".in_stock"
else
#availability_append = ".not_in_stock"
end
#availability = I18n.t("products.filter.other#{#availability_append}")
end
View:
.xs-12.description__status
%i{class: (#tyre.in_stock? ? 'i-check-circle color--success' : 'i-cross-circle color--important')}
= #availability
You can clean your controller tyres_controller.rb (i suppose) method,
def show
#tyre = Tyre.find(params[:id]) # I believe you have a model named 'tyre'
end
Then, there will be a file named tyres_helper.rb in your myproject/app/helpers/. Put the following code there,
def tyre_availability(tyre) # it'll return an array with two values, first one is class name, second one is localized value
if tyre.in_stock
return 'i-check-circle color--success', I18n.t("products.filter.other.in_stock")
else
return 'i-cross-circle color--important', I18n.t("products.filter.other.not_in_stock")
end
end
and, in the view you can use,
.xs-12.description__status
%i{:class => tyre_availability(#tyre)[0]}
= tyre_availability(#tyre)[1]
I need to use this plugin to add watermarks to images using classic ASP. I had this work partially using this code:
dim o, b, wm, layer,textlayer
Set b = CreateObject("ImageResizer.Configuration.Config")
Set wm = CreateObject("ImageResizer.Plugins.Watermark.WatermarkPlugin")
Set textlayer = CreateObject("ImageResizer.Plugins.Watermark.TextLayer")
Set layer = CreateObject("ImageResizer.Plugins.Watermark.Layer")
textlayer.Text = "Yeees"
textlayer.fontSize = 50
layer.fill = True
set layer("dd") = textlayer 'THIS IS FAILING
wm.NamedWatermarks("sfdf") = layer("dd") 'THIS IS FAILING TOO
wm.Install(b)
b.BuildImage "C:\lg1_1361_44.jpg", "C:\lg1_1361_44_WATER.png", "watermark=tessst&format=png"
Why are you creating an instance of Layer? TextLayer and ImageLayer are the classes you want to work with
I would drop everything related to 'layer' and try this instead.
textLayer.fill = True
wm.NamedWatermarks("sfdf") = textLayer
You'll also need "watermark=sfdf" instead of "tessst"
I am trying to remove onEvent listener from button widget. I tried to assign nil to onEvent attribute but it didn't work and lastly I tried this:
buttonWidget : removeEventListener("touch", buttonWidget.onEvent)
I have several button like that and it just stopped all button's event listeners. What do you suggest? How can I remove the event listener for one button widget? Thanks.
Here is how I create my button widgets:
for i=0,2 do
for j=0,8 do
count=count+1
letterBtn[count] = widget.newButton{
id = alphabet[count],
left = 5+j*50,
top = H-160+i*50,
label = alphabet[count],
width = 45,
height = 45,
font = nil,
fontSize = 18,
labelColor = { default = {0,0,0}, over = {255,255,255}},
onEvent = btnOnEventHandler
};
end
end
Can you tell me how can I remove onEvent later?
Okey, I tried Button: setEnabled(false) but still it disables all buttons not just one. I already tried your second advice but it gives the same result. I am copying the rest of the code. Can you please look at it and tell me what I am missing?
local function checkLetter(e)
if(guessWord) then
for i=1, #guessWord do
local c = guessWord:sub(i,i)
if c==e.target.id then
letter[i].text = e.target.id
letterCount = letterCount +1
print("letterCount"..letterCount)
e.target:setEnabled(false)
end
end
if (letterCount == #guessWord and not hanged) then
timer.performWithDelay(500, function()
letterCount=0
rightWGuess = rightWGuess+1
for k,v in pairs(notGuessedWord) do
if v == guessWord then
notGuessedWord[k]=nil
end
end
enableButtons()
startGame() end ,1)
end
end
end
local function btnOnEventHandler(e)
if(e.phase == "began") then
checkLetter(e)
print(e.target.id)
end
return true
end
If you want to temporarily (or permanently) stop a button from responding to touch events, you can use Button:setEnabled(false).
The following worked for me for removing a listener from just 2 buttons. Button 1 and 3 stopped responding to events as expected while 2, 4, and 5 still did.
Update: To disable, you have to do it on the 'ended' phase or Corona gets confused.
widget = require 'widget'
local function btnOnEventHandler(event)
print('Event', event.target.id, event.phase)
if event.phase == 'ended' then
-- Disable the button so it can't be clicked again
-- Must disable in the end state or Corona gets
-- confused
event.target:setEnabled(false)
end
end
local buttons = {}
for i=1,5 do
buttons[i] = widget.newButton{
id = 'button' .. i,
left = display.contentCenterX - 50,
top = 60 * i,
label = 'Button ' .. i,
width = 100,
height = 50,
onEvent = btnOnEventHandler
}
end
buttons[1]:removeEventListener('touch', buttons[1].onEvent)
buttons[3]:removeEventListener('touch', buttons[3].onEvent)
I am using an ultragrid and inside i have values that i load into a datatable from a database. In my grid i group the rows into groups with OutlookGroupBy code. My rows in the grid are in two categories. The Priority 1 and 0. I want when the data are loaded the rows that are in priority 1 to get color red, and the others in priority 0 to be in normal color.
I use the ultragrid pro grammatically so i didnt use any of its features in the editor.
here is how i initialize my grid and how i load from database from another class:
Dim dt As DataTable = Nothing
Timer1.Enabled = True
UltraGrid1.DataSource = Nothing
Generic.openOrders(dt)
UltraGrid1.DataSource = dt
Dim band As Infragistics.Win.UltraWinGrid.UltraGridBand = UltraGrid1.DisplayLayout.Bands(0)
UltraGrid1.DisplayLayout.ViewStyleBand = Infragistics.Win.UltraWinGrid.ViewStyleBand.OutlookGroupBy
band.SortedColumns.Add(band.Columns("PRIORITY"), True, True)
band.SortedColumns.Add(band.Columns("ORDERID"), False, True)
band.SortedColumns.Add(band.Columns("ORDERTIME"), False, True)
anyone has any idea of how can i change the row color into the priority 1 subrows??
You can try with this approach:
First you need to subscribe the event InitializeRow, so add this by the designer or by code (eg. in Form_Load or before setting the DataSource of the grid)
grd.InitializeRow += new InitializeRowEventHandler(grd_InitializeRow);
then, in the event, write code like this
private void grd_InitializeRow(object sender, InitializeRowEventArgs e)
{
if(e.Row.Band.Index == 1)
{
if(Convert.ToInt32(e.Row.Cells["PRIORITY"].Value) == 1)
e.Row.Appearance.BackColor = Color.LightGreen;
}
}
Keep in mind that if you have set CellAppearance they will have precedence on RowAppearance and, if you have many rows it is better to initialize an Appearance object, store it in the grid.DisplayLayout.Appearances collection and reuse the same object for every row involved.
Moreover, always with the aim of improving the performance, to get the cell value it is better to use the GetCellValue method of the row. This will avoid the creation of the a full Cell object just to retrieve its value. Things are a bit more complicated because you need an UltraGridColumn and not just the name of the column, but in the InitializeRow event, fired for each row, this is little price to pay.
private void grd_InitializeRow(object sender, InitializeRowEventArgs e)
{
if(e.Row.Band.Index == 1)
{
UltraGridColumn priorityColumn = e.Row.Band.Columns["PRIORITY"];
if(Convert.ToInt32(e.Row.GetCellValue(priorityColumn)) == 1)
e.Row.Appearance.BackColor = Color.LightGreen;
}
}
EDIT: The same code in VB.NET
....
AddHandler grd.InitializeRow, AddressOf Me.grd_InitializeRow
....
Private Sub grd_InitializeRow(sender As System.Object, e As InitializeRowEventArgs)
If e.Row.Band.Index = 1 Then
Dim priorityCol As UltraGridColumn = e.Row.Band.Columns("PRIORITY")
If Convert.ToInt32(e.Row.GetCellValue(priorityCol)) = 1 Then
e.Row.Appearance.BackColor = Color.LightGreen
End If
End If
End Sub
Also, the use the UltraGridColumn class, you need to add at the start of file
Imports Infragistics.Win.UltraWinGrid
I have a loop that goes through data from a book and displays it. The book is not consistent in it's layout so I am trying to display it in two different ways. First way(works fine) is to load the text from that section in to a panel and display it. The second way is to create a new panel (panel creates fine) and then add collapsable panels(nested) to that panel. Here is the code from the else loop.
else if (newPanel == false){
// simpleData is just for the title bar of the new panel
// otherwise the panel has no content
var simpleData:Section = new Section;
simpleData.section_letter = item.section_letter;
simpleData.letter_title = item.letter_title;
simpleData.section_id = item.section_id;
simpleData.title = item.title;
simpleData.bookmark = item.bookmark;
simpleData.read_section = item.read_section;
var display2:readPanel02 = new readPanel02;
//item is all the data for the new text
display2.id = "panel"+item.section_id;
//trace(display2.name);//trace works fine
// set vars is how I pass in the data to the panel
display2.setVars(simpleData);
studyArea.addElement(display2); // displays fine
newPanel = true;
//this is where it fails
var ssPanel:subSectionPanel = new subSectionPanel;
//function to pass in the vars to the new panel
ssPanel.setSSVars(item);
//this.studyArea[newPanelName].addElement(ssPanel);
this["panel"+item.section_id].addElement(ssPanel);
The error I get is: ReferenceError: Error #1069: Property panel4.4 not found on components.readTest and there is no default value.
I have tried setting the "name" property instead of the "id" property. Any help would be greatly appreciated. I am stumped. Thanks.
So here is the solution I came up with. I made the new readPanel create the sub panels. I added the else statement to help it make more sense. The readPanel creates the first sub panel, and for every subsequent need of a sub panel it references the other panel by name and calls the public function in the panel that creates the new sub panel. Here's the code to create the main panel:
else if (newPanel == false){
var display2:readPanel02 = new readPanel02;
studyArea.addElement(display2);
display2.name = "panel"+item.section_id;
display2.setVars(item);
newPanel = true;
}
else{
var myPanel:readPanel02 = studyArea.getChildByName("panel"+item.section_id) as readPanel02;
myPanel.addSubSection(item);
}
And here is the functions in the panel:
public function setVars(data:Section):void
{
myS = data;
textLetter = myS.section_letter;
textLetterTitle = myS.letter_title;
textSection = myS.section_id;
textTitle = myS.title;
myS.bookmark == 0 ? bookmarked = false : bookmarked = true;
myS.read_section == 0 ? doneRead = false : doneRead = true;
showTagIcon();
showReadIcon();
addSubSection(myS);
}
public function addSubSection(data:Section):void{
var ssPanel:subSectionPanel = new subSectionPanel;
ssPanel.setSSVars(data);
myContentGroup.addElementAt(ssPanel, i);
i++;
}