As the title suggest, I need help on changing the code on an old project I'm planning on revamping for an upcoming one. I need to change the Financial.DDB to Financial.SLN without an error occuring concerning there being too many arguments. Also I think the Main_Form_Load contents should be replaced with lstUsefulLife.Items.Add("2") to ("20"). Can anyone help? Here's the code.
Public Class Main_Form
Private Sub Main_Form_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim i As Integer
i = 3
Do
lstUsefulLife.Items.Add(i.ToString())
i = i + 1
Loop While i <= 20
End Sub
Private Sub btnSchedule_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSchedule.Click
Dim i As Integer
Dim amount As Double
txtSchedule.Text = ""
txtSchedule.Text = "Year" & vbTab & "Depreciation" & vbNewLine
Dim years As Integer
years = Convert.ToDouble(lstUsefulLife.SelectedItem)
i = 1
Do
amount = Financial.DDB(Convert.ToDouble(txtAsset.Text), Convert.ToDouble(txtSalvage.Text), years, i)
txtSchedule.Text = txtSchedule.Text & i & vbTab & amount.ToString("N2") & vbNewLine
i = i + 1
Loop While i <= years
End Sub
Private Sub btnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExit.Click
End
End Sub
End Class
Related
I am working on a calculator project, done with 2 operand but struggling to code and solve the 3 operand calc. The problem is when I do for example, 10+10= (answer 20) works fine but 10+10+10= (also answer 20). Seems it forget the 1st variable.
Below is my code on vb2010, please advise if I miss something. Thank you.
Dim first As Double
Dim second As Double
Dim third As Double
Dim answer As Double
Dim process As String
Private Sub Button15_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button15.Click
first = Val(TextBox1.Text)
TextBox1.Text = ""
formula.Text = first & "x"
process = "*"
End Sub
Private Sub Button14_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button14.Click
first = Val(TextBox1.Text)
TextBox1.Text = ""
formula.Text = first & "+"
process = "+"
End Sub
Private Sub Button12_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button12.Click
first = "0"
second = "0"
answer = "0"
formula.Text = ""
TextBox1.Text = ""
End Sub
Private Sub Button16_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button16.Click
If process = "+" Then
second = Val(TextBox1.Text)
formula.Text = first & "+" & second & "="
answer = first + second
TextBox1.Text = answer
End If
If process = "*" Then
second = Val(TextBox1.Text)
formula.Text = first & "x" & second & "="
answer = first * second
TextBox1.Text = answer
End If
If process = "/" Then
second = Val(TextBox1.Text)
formula.Text = first & "÷" & second & "="
answer = first / second
TextBox1.Text = answer
End If
If process = "-" Then
second = Val(TextBox1.Text)
formula.Text = first & "-" & second & "="
answer = first - second
TextBox1.Text = ""
End If
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
first = Val(TextBox1.Text)
TextBox1.Text = ""
formula.Text = first & "-"
process = "-"
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
first = Val(TextBox1.Text)
TextBox1.Text = ""
formula.Text = first & "÷"
process = "/"
End Sub
So, as the title says, I need to be able to sort an array of randomly generated numbers and also have the user choose the number they want to roll, say they want to roll a 4, they will input a 4 in a textbox and there will be a label somewhere on the form telling the user how many times that number showed up, I just can't seem to figure it out though, how to sort and how to get that probability, any help?
Here is my code so far:
Public Class Chcked
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
End Sub
Public Sub cmdGenerate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdGenerate.Click
' Initialize the random-number generator.
Dim strOutput As String
Dim intArray(Val(txtFirst.Text)) As Integer
Dim Counter As Integer
Dim Random As Integer
For Counter = 1 To Val(txtFirst.Text)
Randomize()
Random = Int(Rnd() * 6) + 1
intArray(txtFirst.Text) = Random
strOutput = intArray(txtFirst.Text)
txtSequence.Text = " " & strOutput & " " + txtSequence.Text & " "
Next Counter
End Sub
Private Sub Clear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Clear.Click
txtSequence.Text = " "
End Sub
Private Sub Sort_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Sort.Click
End Sub
End Class
I am trying to write a program that calculates the yearly depreciation cost with Financial.DDB function. I need to display the year and depreciation for that year in a listbox. Here is what I have so far:
Public Class Form1
Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
'Displays 1-20 in list box
For intUsefullife As Integer = 1 To 20
lstUsefullife.Items.Add(intUsefullife.ToString)
Next intUsefullife
End Sub
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
'set variables
Dim decAssetcost As Decimal
Dim intUsefullife As Integer
Dim decSalvage As Decimal
Dim decSchedule As Decimal
'parse text boxes
Integer.TryParse(lstUsefullife.SelectedItem.ToString, intUsefullife)
Decimal.TryParse(txtAssetcost.Text, decAssetcost)
Decimal.TryParse(txtSalvage.Text, decSalvage)
'converts decSchedule to strings
txtSchedule.Text = decSchedule.ToString
'Name Headers
txtSchedule.Text = "Year" & ControlChars.Tab & "Depreciation" & ControlChars.NewLine
'Calculates depreciation schedule
For intUsefullife = 1 To intUsefullife Step 1
txtSchedule.Text = txtSchedule.Text &
ControlChars.Tab & intUsefullife.ToString
For decSchedule = Financial.DDB(decAssetcost, decSalvage, intUsefullife, intUsefullife)
txtSchedule.Text = txtSchedule.Text &
ControlChars.NewLine
ControlChars.Tab & decSchedule.ToString("C2") & ControlChars.NewLine
Next decSchedule
Next intUsefullife
End Sub
Private Sub btnExit_Click(sender As System.Object, e As System.EventArgs) Handles btnExit.Click
Me.Close()
End Sub
End Class
I have no idea where to go from here. All that happens when I hit debug and then calculate is year 1 and $0.00 under the depreciation amount. (the year does not display where I want it to either).
Here is my code in vb.net for automatically changing image using timer but code doesn't work...
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
Me.BackgroundImage = Image.FromFile("C:\images\\" + Label1.Text + "1.jpg")
Dim i As Integer = Convert.ToInt32(Label1.Text)
i += 1
If (i > 4) Then
i = 1
End If
Label1.Text = i.ToString()
End Sub
Move the counter out to class level. Incorporating the comments from dbasnett as well. Also, shouldn't the label reflect the current image number? The way you have it the value in the Label is one "ahead" of the background image.
Try something more like:
Private i As Integer = 1
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
Dim FileName As String = "C:\images\" & i.ToString & ".jpg"
Try
Me.BackgroundImage = Image.FromFile(FileName)
Label1.Text = i.ToString()
i += 1
If (i > 4) Then
i = 1
End If
Catch ex As Exception
Debug.Print(FileName)
MessageBox.Show(FileName & vbCrLf & vbCrLf & ex.ToString, "Error Loading Image")
End Try
End Sub
Hi I am trying to make a program that has 6 checkboxes and when one is checked a label displays the actors take in average, but if more than one is checked the label will only show the highest average of the checked boxes.
Private Sub CheckBox1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox1.CheckedChanged
SC = ((Val(425488741) + Val(555909803) + Val(868659354) + Val(966435555) + Val(720388023) + Val(617520987)) / 6)
If CheckBox1.Checked = True Then
Label3.Text = "Sean Connery $" & SC
Exit Sub
End If
End Sub
Private Sub CheckBox2_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox2.CheckedChanged
GL = 513445231
If CheckBox2.Checked = True Then
Label3.Text = "George Lazenby $" & GL
Exit Sub
End If
End Sub
Private Sub CheckBox3_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox3.CheckedChanged
RM = ((Val(785677477) + (426826774) + (666367656) + (624527272) + (481005579) + (405873493) + (316186616)) / 7)
If CheckBox3.Checked = True Then
Label3.Text = "Roger Moore $" & RM
Exit Sub
End If
End Sub
Private Sub CheckBox4_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox4.CheckedChanged
TD = ((Val(362876056) + (271586451)) / 2)
If CheckBox4.Checked = True Then
Label3.Text = "Timothy Dalton $" & TD
Exit Sub
End If
End Sub
Private Sub CheckBox5_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox5.CheckedChanged
PB = ((Val(499954330) + (465588535) + (504705882) + (546490272)) / 4)
If CheckBox5.Checked = True Then
Label3.Text = "Pierce Brosnan $" & PB
Exit Sub
End If
End Sub
Private Sub CheckBox6_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox6.CheckedChanged
DC = ((Val(640803677) + (586090727)) / 2)
If CheckBox6.Checked = True Then
Label3.Text = "Daniel Craig $" & DC
Exit Sub
End If
End Sub
In the future, when asking a question, please do not include all the unnecessary details. If understand your problem correctly, this is one possible simple solution:
Dim incomes = New Integer() {100, 2000, 500}
Dim names = New String() {"John", "Tim", "Allan"}
Private Sub CheckedListBox1_SelectedIndexChanged(sender As System.Object, e As System.EventArgs) Handles CheckedListBox1.SelectedIndexChanged
Dim maxIncome As Integer = 0
Dim name As String = ""
For i = 0 To incomes.Length - 1
If CheckedListBox1.GetItemChecked(i) And incomes(i) > maxIncome Then
maxIncome = incomes(i)
name = names(i)
End If
Next
Label1.Text = name & " $" & maxIncome
End Sub
For this code to work you need to create a CheckedListBox with 3 items in it's collection. However, this approach might lead to a very bad code once there are many values. In that case you should use a database or at least a structure like:
Structure People
Dim name As String
Dim income As Integer
Dim checkBox As CheckBox
End Structure
Also the is no need to write Exit Sub anywhere in your code, it does nothing.
Details: Saulius is correct in that you should use a database and that you should use a checkedlistbox instead to make it much easier. However, I will just assume you want to use separate checkboxes for whatever reason.
Solution:
Create an Actor Class
Public Class Actor
Property Name As String
Property TotalValue As Double
End Class
In your main form
Public Sub DisplayHighestPaidActor(ByVal actorName As String, ByVal isChecked As Boolean)
If isChecked Then
'Add the Actor
selectedActors.Add((From actor In allActors
Where actor.Name = actorName).FirstOrDefault())
'Order the Actors
selectedActors = (From actor In selectedActors
Order By actor.TotalValue Descending).ToList()
Else
'Remove the Actor
selectedActors.Remove((From actor In allActors
Where actor.Name = actorName).FirstOrDefault())
'Order the Actors
selectedActors = (From actor In selectedActors
Order By actor.TotalValue Descending).ToList()
End If
If (selectedActors.Count > 0) Then
'Display the highest value
lblHighestPaidActor.Text = selectedActors.Item(0).Name.ToString() _
+ " $" + selectedActors.Item(0).TotalValue.ToString()
Else
lblHighestPaidActor.Text = ""
End If
End Sub
Private Sub CheckBox1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox1.CheckedChanged
DisplayHighestPaidActor("Sean Connery", CheckBox1.Checked)
End Sub
Private Sub CheckBox2_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox2.CheckedChanged
DisplayHighestPaidActor("George Lazenby", CheckBox2.Checked)
End Sub
Private Sub CheckBox3_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox3.CheckedChanged
DisplayHighestPaidActor("Roger Moore", CheckBox3.Checked)
End Sub