Count Animation for number [closed] - winforms

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
I want to create a countup/count down animation like Countup.js. Is this possible with label? Any pointers would be greatly appreciated.

Here's a very simple example of that concept using a form with two textboxes (start and end) a display label. As it gets closer to the end target, the ease gets higher and the process slows down.
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
Dim cntr As Integer = CInt(Me.txtStart.Text)
Dim ease As Integer = 0
Do While cntr < Me.txtEnd.Text
cntr += 1
Me.lblCount.Text = cntr
Me.lblCount.Refresh()
Select Case Me.txtEnd.Text - cntr
Case Is < 5
ease = 100
Case Is < 10
ease = 40
Case Is < 100
ease = 10
Case Is < 200
ease = 1
End Select
If ease > 0 Then
System.Threading.Thread.Sleep(ease)
End If
Loop
End Sub

Related

Printing 1D Array onto Column [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 2 years ago.
Improve this question
I am looking across numerous columns and rows and inputting cell values of interest into a 1D array. I would just like to print this array of length 2020 into a single row on another worksheet. I am not sure why my program is not working, but I appreciate any help
Sub Math()
Dim FW_List() as Variant
x = 0
For i = 3 to 10
For j = 17 to 282
If Left(ws.Cells(j, i).Value, 3) = "0.7" And ws.Cells(j, i).Interior.Color <> 8696025 Then
ReDim Preserve FW_List(x)
FW_List(x) = ws.Cells(j, i).Value
x = x + 1
Next j
Next i
num = UBound(FW_List) - LBound(FW_List) + 1
Debug.Print num
wb.Sheets("JMP").Range("A1:A2020").Value = Application.WorksheetFunction.Transpose(FW_List)
End Sub
Your code is quite good but it lacks precision. Some of the changes I made are cosmetic, like the use of a With statement to shorten the code and thereby make it easier to read. But the nonchalance with which you approached variable naming probably caused your failure. Observe that I retained both structure and logic of your original code.
Sub Math()
Dim FW_List As Variant
Dim Ws As Worksheet
Dim C As Long ' loop counter: column
Dim R As Long ' loop counter: Row
Dim i As Long ' index of FW_List
Set Ws = ActiveSheet
ReDim FW_List(1 To 3000) ' any number larger than what you expect
For C = 3 To 10
For R = 17 To 282
With Ws.Cells(R, C)
If Left(.Value, 3) = "0.7" And .Interior.Color <> 8696025 Then
i = i + 1
FW_List(i) = .Value
End If
End With
Next R
Next C
If i Then
ReDim Preserve FW_List(i)
Worksheets("JMP").Cells(1, 1).Resize(1, i).Value = Application.Transpose(FW_List)
End If
End Sub
But here are two things you probably couldn't have known.
Dim FW_List As Variant creates a variant which, as you know, can be anything including an array. Therefore Dim FW_List() As Variant creates an array of such variants. Since any of its components can do what the whole structure does the idea isn't useful and therefore any difference it can make not beneficial.
When you Redim Preserve an array the entire array is re-written to a new one, element by element. As the size of your array grows to 2020 elements that process eats time if repeated 2000 times. Therefore my code creates an array intentionally larger than what is needed and then truncates unused elements - a process I believe is done without re-writing the array at all.

I need an array which vaires from different sizes of n and it needs to correspond to a given list [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
this is what I've got so far but I don't know what to do
` Sub SetUpList()
Dim UnsortedList(1 To 100000, 1 To 1) As Double
Dim i As Long
For i = 1 To 100000
UnsortedList(i, 1) = Rnd(-i)
Next i
Range("A1:A100000").value = UnsortedList
End Sub
Sub InitializeA()
Dim i As Long
n = Cells(2, 2).value
ReDim A(1 To n)
For i = 1 To n
A(i) = Cells(i, 1).value
Next i
End Sub
Here is a method to print a section of your list onto your spreadsheet.
Option Explicit
'this generates the list and I need to create an array from this list for different sizes of n
Sub SetUpList()
Dim UnsortedList(1 To 100000, 1 To 1) As Double
Dim i As Long, N As Long
Dim A As Variant, R As Range
For i = 1 To 100000
UnsortedList(i, 1) = Rnd(-i)
Next i
Range("A1:A100000").Value = UnsortedList
N = Cells(2, 2).Value
'this allows us to determine the size of the array which will vary because there can be different sizes of n
Initialize
End Sub
Sub Initialize()
Dim rDest As Range
Dim i As Long, N As Long
Dim A As Variant
Dim UnsortedList As Variant
UnsortedList = Range("A1", Cells(Rows.Count, "A").End(xlUp))
N = Cells(2, 2)
Set rDest = Range("C1")
ReDim A(1 To N, 1 To 1)
For i = 1 To N
A(i, 1) = UnsortedList(i, 1)
Next i
Set rDest = rDest.Resize(rowsize:=N)
rDest.EntireColumn.Clear
rDest = A
End Sub

Error While Editing Arrays [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 8 years ago.
Improve this question
I'm working with Arrays and trying to change the text value of an array to numerical for an easier evaluation as the code progress. I seem to be having issues with Arrays, but I'm not sure why. Can you take a look at my code and offer feedback?
Dim MonthlyValuesUnclean() As Range
Dim CodeCountOne As Long
Range("A1").Select
CodeCountOne = Application.CountA(Range("A:A")) 'Counts Total Number of Codes Before Clean
ReDim MonthlyValuesUnclean(CodeCountOne, 1 To 3)
For columnNumber = 1 To 3
ReDim MonthlyValuesUnclean(CodeCountOne, columnNumber)
For counter = 1 To CodeCountOne
If MonthlyValuesUnclean(counter, columnNumber).Text = "R" Then
MonthlyValuesUnclean(counter, columnNumber).Value = 5
ElseIf MonthlyValuesUnclean(counter, columnNumber).Text = "Y" Then
MonthlyValuesUnclean(counter, columnNumber).Value = 4
ElseIf MonthlyValuesUnclean(counter, columnNumber).Text = "G" Then
MonthlyValuesUnclean(counter, columnNumber).Value = 3
ElseIf MonthlyValuesUnclean(counter, columnNumber).Text = "?" Then
MonthlyValuesUnclean(counter, columnNumber).Value = 2
Else
MonthlyValuesUnclean(counter, columnNumber).Value = 1
End If
Next counter
Next columnNumber
What I am trying to do is take a range of cells and put them into the array.
OK, that's what I thought, but you haven't actually done that. You've defined an array of range objects (not what you want) and you have dimensioned that array probably correctly (but unnecessarily).
In this, we will first define and assign a range variable (monthlyValuesRange). Then, we will assign the range's .Value array to an array variable (MonthlyValuesUnclean). Then, we can process that array, and finally put those values back in to the worksheet.
Sub Test()
Dim MonthlyValuesUnclean As Variant
Dim CodeCountOne As Long
Dim monthlyValuesRange As Range
CodeCountOne = Application.CountA(Range("A:A")) 'Counts Total Number of Codes Before Clean
'Define your range variable
Set monthlyValuesRange = Range("A1:C" & CodeCountOne)
'Assigns the range's value array to the MonthlyValuesUnclean array variable:
MonthlyValuesUnclean = monthlyValuesRange.Value
For columnNumber = 1 To 3
For counter = 1 To CodeCountOne
'## I find Select statement easier to work with:
Select Case UCase(MonthlyValuesUnclean(counter, columnNumber))
Case "R"
MonthlyValuesUnclean(counter, columnNumber) = 5
Case "Y"
MonthlyValuesUnclean(counter, columnNumber) = 4
Case "G"
MonthlyValuesUnclean(counter, columnNumber) = 3
Case "?"
MonthlyValuesUnclean(counter, columnNumber) = 2
Case Else
MonthlyValuesUnclean(counter, columnNumber) = 1
End Select
Next counter
Next columnNumber
'Now put the updated values in the worksheet
monthlyValuesRange.Value = MonthlyValuesUnclean
End Sub
Tested & confirmed this is working as expected. Before:
After:
And an example of examining the MonthlyValuesUnclean in the VBE's locals window:

Array of Rectangles [duplicate]

This question already has answers here:
VS2010 does not show unhandled exception message in a WinForms Application on a 64-bit version of Windows
(5 answers)
Closed 8 years ago.
I'm having a hard time displaying rectangles from an array.
Here's the code:
Dim recs(9) As PowerPacks.RectangleShape
Dim canvas As New Microsoft.VisualBasic.PowerPacks.ShapeContainer
Private Sub Spi_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Dim sz As Integer = 350
canvas.Parent = Me
recs(0).Height = sz
recs(0).Width = sz
recs(0).Left = 20
recs(0).Top = 20
recs(0).Parent = canvas
recs(0).FillColor = Color.Green
recs(0).FillStyle = PowerPacks.FillStyle.Solid
End Sub
There are no syntax or runtime errors. I can't figure out what is going on.
If I try to make a rectangle alone it will show it but when I'm making an array of them, it shows nothing. If I debug it, when the next statement to be executed is any line of code that uses the array, it justs ignores it and moves on, meaning that it will ignore all my commands that use the "recs(0)". Why???
Any help is appreciated. Thanks.
EDIT: Ok guys. Thanks for your help.
As has been mentioned, your problem is, the array isn't initialized, and since you can't initialize an array with New you'll either have to initialize each element or switch to a different collection, like List:
Dim recs(9) As PowerPacks.RectangleShape
Dim canvas As New Microsoft.VisualBasic.PowerPacks.ShapeContainer
Private Sub Spi_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Dim sz As Integer = 350
canvas.Parent = Me
recs(0) = New PowerPacks.RectangleShape(20, 20, sz, sz)
recs(0).Parent = canvas
recs(0).FillColor = Color.Green
recs(0).FillStyle = PowerPacks.FillStyle.Solid
End Sub
Dim recs As New List(Of PowerPacks.RectangleShape)

Making every variable in this code Dynamic Visual Basic 2010

Sorry for the long piece of code. In a game I'm designing, I have this code starting at the checkbox.checked if statement currently repeated 5 times for each checkbox clicked--each checkbox is equal to a card within the players hand in the game.
What I'd like to know is what can I do to make it mostly dynamic. Namely the CardCheckBox1.Checked Object/Method. As stated above the code is repeated 5 times, as I have 5 existing checkboxes. Is there a way to place the checkboxes into an array or collection so when I click a check box and hit the play button it will be the equivalent of hitting CardCheckBox2.checked = true, CardCheckBox2.checked = true, etc. Once I figure how to make that part dynamic I can finally start making the rest of the code dynamic, because I assume procedure for making a dynamic label code would be very similar to the checkboxes, etc.
I've had
Dim CardCheckBoxArray() As CheckBox = {CardCheckBox1, CardCheckBox2, CardCheckBox3, CardCheckBox4, CardCheckBox5}
posted at the Modular Level, in the Form_Load Procedure, and even the Play_Button Procedure, but I always end up with a nullreference exception on the CardCheckBox(n).Checked Portion of the code when I do
If CardCheckBoxArray(0).Checked = True And Player1HandGroup(Number1).QuantityInteger > 0 Then
So I don't know where to go with it. The long piece of code is my entire PlayButton_Click procedure, except for the other CardCheckBox if statements.
Private Sub PlayButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PlayButton.Click
Dim n As Integer
Dim WeaponDiscardInteger As Integer = 1
AtkPlayerDialog.ShowDialog()
'Code for choosing which player to attack
If AtkPlayerDialog.DialogResult = Windows.Forms.DialogResult.Cancel Then
n = 2
ElseIf AtkPlayerDialog.DialogResult = Windows.Forms.DialogResult.OK Then
n = 1
ElseIf AtkPlayerDialog.DialogResult = Windows.Forms.DialogResult.Abort Then
n = 3
ElseIf AtkPlayerDialog.DialogResult = Windows.Forms.DialogResult.Retry Then
n = 4
ElseIf AtkPlayerDialog.DialogResult = Windows.Forms.DialogResult.Ignore Then
n = 5
End If
'playing card 1
If CardCheckBox1.Checked = True And Player1HandGroup(Number1).QuantityInteger > 0 Then
'Subtract Hitpoints when damage is delt
Player1HandGroup(n).HitPoints -= Player1HandGroup(Number1).DamageInteger
HitPoints1.Text = Player1HandGroup(1).HitPoints.ToString
HitPoints2.Text = Player1HandGroup(2).HitPoints.ToString
HitPoints3.Text = Player1HandGroup(3).HitPoints.ToString
HitPoints4.Text = Player1HandGroup(4).HitPoints.ToString
HitPoints5.Text = Player1HandGroup(5).HitPoints.ToString
'When player plays hand, card quantity is removed from hand to discard pile.
Player1HandGroup(Number1).QuantityInteger -= 1
DiscardGroup(Number1).QuantityInteger += 1
'Shuffle Deck from Discard Pile if Deck is out of cards
Call DiscardPile()
'Reset Number Generator, unless weapon isn't discard
Number = (DeckGroup(Rnd.Next(0, DeckGroup.Count)).ID)
If DeckGroup(Number).QuantityInteger > 0 Then
'Grab New Card From Deck
DeckGroup(Number).QuantityInteger -= 1
Player1HandGroup(Number).QuantityInteger += 1
Card1Type = Player1HandGroup(Number).CardType
CardCheckBox1.Text = Player1HandGroup(Number).CardNameString
Number1 = Number
Else
Call PlayElse()
End If
I f you use the checkbox array inside/through most your form code then move it out o the form load event right the way up to the form level scope. when it is inside the forn_load event subroutine, that is not the same as module level scope.
so you would have......
Dim CardCheckBoxArray() As CheckBox = {CardCheckBox1, CardCheckBox2, CardCheckBox3, CardCheckBox4, CardCheckBox5}
Sub Form_Load(blah blah blah)
...
End Sub
Sub Play_Button(blah blah blah)
...
End Sub
etc etc

Resources