Store form Image elements in a array - arrays

I need some help with storing image form elements in a array.
I have tried to use As Object/Variant and I've run out of logical options to try
As you can see below, the names of the images are I_Monday, I_Tuesday etc.
Current code:
Dim I_Day(0 To 4) As Image
I_Day(0) = I_Monday
I_Day(1) = I_Tuesday
I_Day(2) = I_Wednesday
I_Day(3) = I_Thursday
I_Day(4) = I_Friday
The elements with be accessed in a for loop.
For i = 0 To 4
If sht.Cells(nameRow, weekNum + i).Value = "Pass" Then
I_Day(i).BackColor = RGB(0, 255, 0)
ElseIf sht.Cells(nameRow, weekNum + i).Value = "Fail" Then
I_Day(i).BackColor = RGB(255, 0, 0)
Else
I_Day(i).BackColor = RGB(0, 0, 255)
End If
Next i
Thanks for any help.
Edit: Should probably mention the error message:
Run time error 91:
Object variable or with block not set

Because they are objects, you need to use Set when assigning them:
Dim I_Day(0 To 4) As Image
Set I_Day(0) = I_Monday
Set I_Day(1) = I_Tuesday
Set I_Day(2) = I_Wednesday
Set I_Day(3) = I_Thursday
Set I_Day(4) = I_Friday

Related

Map Layer Issues in ggplot2

I'm having a few issues with finalizing my map for a report. I think I'm warm on the solutions, but haven't quite figured them out. I would really appreciate any help on solutions so that I can finally move on!
1) The scale bar will NOT populate in the MainMap code and the subsequent Figure1 plot. This is "remedied" in the MainMap code if I comment out the "BCWA_land" map layer. However, when I retain the "BCWA_land" map layer it will eliminate the scale bar and produces this error:
Warning message: Removed 3 rows containing missing values (geom_text).
And this is the code:
MainMap <- ggplot(QOI) +
geom_sf(aes(fill = quadID)) +
scale_fill_manual(values = c("#6b8c42",
"#70b2ae",
"#d65a31")) +
labs(fill = "Quadrants of Interest",
caption = "Figure 1: Map depicting the quadrants in the WSDOT project area as well as other quadrants of interest in the Puget Sound area.")+
ggtitle("WSDOT Project Area and Quadrants of Interest") +
scalebar(x.min = -123, x.max = -122.8, y.min = 47, y.max = 47.1, location = "bottomleft",
transform = TRUE, dist = 10, dist_unit = "km", st.size = 3, st.bottom = TRUE, st.dist = 0.1) +
north(data = QOI, location = "topleft", scale = 0.1, symbol = 12, x.min = -123, y.min = 48.3, x.max = -122.7, y.max = 48.4) +
theme_bw()+
theme(panel.grid= element_line(color = "gray50"),
panel.background = element_blank(),
panel.ontop = TRUE,
legend.text = element_text(size = 11, margin = margin(l = 3), hjust = 0),
legend.position = c(0.95, 0.1),
legend.justification = c(0.85, 0.1),
legend.background = element_rect(colour = "#3c4245", fill = "#f4f4f3"),
axis.title = element_blank(),
plot.title = element_text(face = "bold", colour = "#3c4245", hjust = 0.5, margin = margin(b=10, unit = "pt")),
plot.caption = element_text(face = "italic", colour = "#3c4245", margin = margin(t = 7), hjust = 0, vjust = 0.5)) +
geom_sf(data = BCWA_land) + #this is what I've tried to comment out to determine the scale bar problem
xlim (-123.1, -121.4) +
ylim (47.0, 48.45)
MainMap
InsetRect <- data.frame(xmin=-123.2, xmax=-122.1, ymin=47.02, ymax=48.45)
InsetMap <- ggplotGrob( ggplot( quads) +
geom_sf(aes(fill = "")) +
scale_fill_manual(values = c("#eefbfb"))+
geom_sf(data = BCWA_land) +
scale_x_continuous(expand = c(0,0), limits = c(-124.5, -122.0)) +
scale_y_continuous(expand = c(0,0), limits = c(47.0, 49.5)) +
geom_rect(data = InsetRect,aes(xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax),
color="#3c4245",
size=1.25,
fill=NA,
inherit.aes = FALSE) +
theme_bw()+
theme(legend.position = "none",
panel.grid = element_blank(),
axis.title = element_blank(),
axis.text = element_blank(),
axis.ticks = element_blank(),
plot.margin = margin(0,0,0,0)))
InsetMap
Figure1 <- MainMap +
annotation_custom(grob = InsetMap, xmin = -122.2, xmax = -121.3,
ymin = 47.75, ymax = 48.5)
Figure1
As you can see I'm not getting this issue or error for my north arrow so I'm not really sure what is happening with the scale bar!
This problem is probably a little too OCD, however I REALLY don't want the gridlines to show up on the InsetMap, and was hoping that the InsetMap would overlay on top of the MainMap, without gridlines as I had those parameters set to element_blank() in the InsetMap code.
Here is an image of my plot. If you would like the data for this, please let me know. Because these are shapefiles, the data is unwieldy and not super conducive to SO's character limit for a post...
If anyone has any insight into a solution(s) I would so so appreciate that!! Thanks for your time!
The issue was the
xlim (-123.1, -121.4) +
ylim (47.0, 48.45)
call that I made. Instead, I used coord_sf(xlim = c(min, max), ylim = c(min, max)). I thought that this would be helpful to someone who might be in my position later on!
Essentially the difference between setting the limits of to the graph using just the x/y lim calls is that that truncates the data that is available in your dataset, whereas the coord_sf call simply "focuses" your graph on that extent if you will without altering the data you have available in your dataset.

Corona show text from database in newScrollView

Im trying to pull some data from SQLite database to the Corona newScollView.
I managed to get data from the database in a tableView, so I thought the code should almost be the same for the newScrollView.
It keeps saying the row is empty, but its not. Any help?
Here is the code:
function scene:create( event )
local sceneGroup = self.view
local function scrollListener( event )
-- Get reference to the row group
local row = event.row
local options_metni =
{
parent = row,
text = row.params.Metni,
x = 0,
y = 0,
font = native.systemFont,
fontSize = 16
}
local metniObject = display.newText(options_metni)
metniObject:setTextColor(0)
metniObject.x = display.contentCenterX
end
---------------------
-- CREATE SCROLLVIEW
---------------------
local scrollView = widget.newScrollView
{
left = 0,
top = 0,
width = display.contentWidth,
height = display.contentHeight / 2,
topPadding = 200,
bottomPadding = 50,
horiontalScrollDisabled = true,
verticalScrollDisable = false,
listener = scrollListener,
}
sceneGroup:insert(scrollView)
---------------------
-- GET DATA FROM DB
---------------------
for row in db:nrows("SELECT baslik FROM dua LIMIT 1") do
if row.data == nil then
print(" NO DATA FOUND ")
end
local rowParams =
{
duaID = row.dua_id,
Metni = row.baslik,
}
end
end
You need to insert an object into the scrollView, it doesn't work like the tableView. Try this where the display object is being created and the text is being set from row.baslik:
for row in db:nrows("SELECT baslik FROM dua LIMIT 1") do
local text = display.newText( tostring( row.baslik ), 0, 0, native.systemFont, 16 )
scrollView:insert( text )
end

How do I randomize an array in Visual Basic 2010?

I have any array of questions like this:
Dim Questions(25) As TheQuestions
Function loadQuestions()
Questions(0).Question = "Which of these words are an adjective?"
Questions(0).option1 = "Dog"
Questions(0).option2 = "Beautiful"
Questions(0).option3 = "Steven"
Questions(0).option4 = "Bird"
Questions(0).Answer = "B"
Questions(1).Question = "What's the adjective in this sentence:" & vbCrLf & "'Kelly handled the breakable glasses very carefully'"
Questions(1).option1 = "Kelly"
Questions(1).option2 = "Handled"
Questions(1).option3 = "Carefully"
Questions(1).option4 = "Breakable"
Questions(1).Answer = "D"
Questions(2).Question = "What's the adjective in this sentence: 'Karen is a graceful dancer'"
Questions(2).option1 = "Is"
Questions(2).option2 = "Graceful"
Questions(2).option3 = "Dancer"
Questions(2).option4 = "Tanya"
Questions(2).Answer = "B"
...
I have found a way of randomizing the question successfully, but could I make sure that the correct, four potential answers are displayed along with the question being displayed?
Below is the code for calling the Function which gets the question and then displays it in a label (lblQuestion) and where the code I am looking for needs to go, I am guessing:
Function GetQuestion(ByVal intQuestion As Integer)
tmrOne.Start()
If questionNumber < 25 Then
lblQuestionNumber.Text = "Question" & " " & questionNumber
lblQuestion.Text = Questions(intQuestion).Question
btnAnswerA.Text = Questions(intQuestion).option1
btnAnswerB.Text = Questions(intQuestion).option2
btnAnswerC.Text = Questions(intQuestion).option3
btnAnswerD.Text = Questions(intQuestion).option4
strAnswer = Questions(intQuestion).Answer
questionNumber = questionNumber + 1
btnAnswerA.BackColor = Color.White
btnAnswerB.BackColor = Color.White
btnAnswerC.BackColor = Color.White
btnAnswerD.BackColor = Color.White
btnAnswerA.Enabled = True
btnAnswerB.Enabled = True
btnAnswerC.Enabled = True
btnAnswerD.Enabled = True
Return intQuestion
Else
MsgBox("You have finished")
End
End If
End Function
I used this:
lblQuestion.Text = Questions(random.Next(25)).Question
It randomizes the question, but how do I get it so that the four possible answers are shown with the correct question, like in the array above where there are FOUR options.
Many thanks!
Instead of:
lblQuestion.Text = Questions(random.Next(25)).Question
I think you just need to save the random number and do it like this:
dim questionChosen as int
questionChosen = random.Next(25)
lblQuestion.Text = Questions(questionChosen).Question
Then you update the rest of the fields using Questions(questionChosen).WhateverYouNeed

find and replace symbol using vbs

I am working a 1XXX words documents, I want to use vbs to changing the status of checkbox faster but I can't found any work solution, after that, i wonder if find and replace can solve my issue, so i wrote some code for this
Const wdReplaceAll = 2
Set objWord = CreateObject("Word.Application")
objWord.Visible = True
Set objDoc = objWord.Documents.Open("C:\checkbox.doc")
Set objDoc = objWord.Documents.Add()
Set objSelection = objWord.Selection
objSelection.Find.Text = "#1"
objSelection.Find.Forward = TRUE
objSelection.Find.MatchWholeWord = TRUE
objSelection.Find.Replacement.Text = objSelection.InsertSymbol 253, "Wingdings"
objSelection.Find.Execute ,,,,,,,,,,wdReplaceAll
But, it can't work, and always show the error on the objSelection.InsertSymbol 253...
You can't use InsertSymbol in an assignment like that. Either replace the search text with an appropriate character formatted as "Wingdings":
With objSelection.Find
.Text = "#1"
.Replacement.Text = ChrW(61693)
.Replacement.Font.Name = "Wingdings"
...
End With
objSelection.Find.Execute ,,,,,,,,,,wdReplaceAll
or just Find the search text and then use InsertSymbol on the selection:
objSelection.Find.Text = "#1"
objSelection.Find.Execute
objSelection.InsertSymbol 253, "Wingdings"

Creating buttons through iteration?

I've been using the Corona engine and I'm trying to create multiple buttons through a loop rather than explicitly creating each individual button. Problem is the loop only seems to be generating one button which suggests it's only iterating once.
Below is what I've got so far...
UPDATED
--> Create Level Selection:
local levelSelectionGroup = display.newGroup( );
--> Level Selected:
local function levelSelected()
print(id);
end
--> Button Creation:
local function createLevelSelection()
local levelsToBeMade = 30; -- Ignore these random numbers for now.
local positionX = 1; -- Ignore again.
local positionY = 1; -- Ignore again.
for buttonNumber=1, levelsToBeMade do
print(buttonNumber);
positionX = (positionX + 10); -- Ignore again.
positionY = (positionY + 10); -- Ignore again.
levelButton[buttonNumber] = widget.newButton{
id = buttonNumber,
label = buttonNumber,
default = "images/levelButton.png",
over = "images/levelButtonPressed.png",
width = 50,
height = 50,
onRelease = levelSelected
}
levelButton[buttonNumber].x = positionX;
levelButton[buttonNumber].y = positionY;
levelSelectionGroup:insert(levelButton[buttonNumber]);
end
end
The console states...
attempt to index global 'levelButton' (a nil value)
I guess you might have a problem with your variables or your scopes. So make sure that levelsToBeMade variable and positionX and positionY variables are correct. If you are absolutely sure, this should work: ( I don't see anything wrong in your code but, for loops are more trustable I guess. )
for i=1, levelsToBeMade do
print( "levelButton+1).." will be created." )
positionX = positionX + 10; -- Ignore numbers.
positionY = postionY + 10; -- Ignore numbers.
levelButton[#levelButton+1] = widget.newButton{
id = #levelButton,
label = #levelButton,
default = "images/levelButton.png",
over = "images/levelButtonPressed.png",
width = 50,
height = 50,
onRelease = levelSelected
}
levelButton[#levelButton].x = positionX;
levelButton[#levelButton].y = positionY;
end
If it doesn't work, just check console and see if the loop is executed desired times.
Last edit:
Oh, didn't notice that. You never created levelButton table before! Before starting to create level buttons you should create that like this: local levelButton = {}, at outside of for loop
You might want to reconsider your algorithm and change this while loop.
If the number of levels to be generated is going to stay constant you might want to do a for loop until the 31 st loop is reached.
for i=1,levelstToBeMade do
levelstToBeMade = (levelsToBeMade - 1); -- Ignore numbers.
positionX = positionX + 10; -- Ignore numbers.
positionY = postionY + 10; -- Ignore numbers.
levelButton[levelsToBeMade] = widget.newButton{
id = levelsToBeMade,
label = levelsToBeMade,
default = "images/levelButton.png",
over = "images/levelButtonPressed.png",
width = 50,
height = 50,
onRelease = levelSelected
}
levelButton[levelsToBeMade].x = positionX;
levelButton[levelsToBeMade].y = positionY;
end
Hope this helps.
Cheers
(Sorry, I don't know Corona so this might not apply.)
What is levelButton, and are you sure it exists? Maybe it should be levelButtons?
If that's fine as it is, then check to make sure newButton() actually returns a table as expected: print(levelButton[buttonNumber])

Resources