-
November 22nd, 2008, 06:28 PM
#1
two item array
look at the attached pics first
Code:
Public Class Form1
Private Sub TextBox1_MouseHover(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.MouseHover
ToolTip1.SetToolTip(TextBox1, "Cash Flow")
End Sub
Private Sub TextBox2_MouseHover(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox2.MouseHover
ToolTip1.SetToolTip(TextBox2, "Account Balance")
End Sub
Private Sub TextBox1_MouseDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles TextBox1.MouseDown
TextBox1.Clear()
End Sub
Private Sub TextBox2_MouseDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles TextBox2.MouseDown
TextBox2.Clear()
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
'these variable need to plug into an equation
dim name as string
Dim current As Decimal
Dim toBuy As Integer
Dim startPrice As Decimal
Dim newPrice As Decimal
Dim totalNeed As Decimal
Dim quantity As Integer
Dim subNeed As Decimal
Dim account As Decimal
Dim flow As Decimal
Dim hours As Decimal
'this is the equation
newPrice = current + (toBuy) * (0.1 * startPrice)
totalNeed = newPrice * quantity
subNeed = totalNeed - account
hours = subNeed / flow
MsgBox("it will take you " & hours & " hours to save up for " & quantity & name & "'s. ")
End Sub
End ClassPublic Class Form1
Private Sub TextBox1_MouseHover(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.MouseHover
ToolTip1.SetToolTip(TextBox1, "Cash Flow")
End Sub
Private Sub TextBox2_MouseHover(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox2.MouseHover
ToolTip1.SetToolTip(TextBox2, "Account Balance")
End Sub
Private Sub TextBox1_MouseDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles TextBox1.MouseDown
TextBox1.Clear()
End Sub
Private Sub TextBox2_MouseDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles TextBox2.MouseDown
TextBox2.Clear()
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
'these variable need to plug into an equation
dim name as string
Dim current As Decimal
Dim toBuy As Integer
Dim startPrice As Decimal
Dim newPrice As Decimal
Dim totalNeed As Decimal
Dim quantity As Integer
Dim subNeed As Decimal
Dim account As Decimal
Dim flow As Decimal
Dim hours As Decimal
'this is the equation
newPrice = current + (toBuy) * (0.1 * startPrice)
totalNeed = newPrice * quantity
subNeed = totalNeed - account
hours = subNeed / flow
MsgBox("it will take you " & hours & " hours to save up for " & quantity & name & "'s. ")
End Sub
End Class
for example, the plaza that i was about to click on (in the pic)
it is in combobox1, it is plaza, and its starting price is 1000000 dollars.
it has a starting price, but depending on how many somebody already owns it has a current price. you can find out the current price by plugging what you know into the equation:
newPrice = (current) + (toBuy) * (0.1 * startPrice)
you then plug the rest of these into some more code(not shown yet) to get the hours to save up.
my question is, how do i make an array that has the name and starting price associated with the combobox1.
so when i click the plaza it plugs the startPrice into the equation and it plugs the name into the msgbox output string.
please help, ive been struggling with this for a couple weeks now.
best regards!!!
-
November 22nd, 2008, 08:03 PM
#2
Re: two item array
You can use a ListArray, and add items. Use two arrays, or else create a class and use a listarray with it. You can use a Dictionary, but only if no two keys have the same value
EDIT: Strings OK
Last edited by dglienna; November 23rd, 2008 at 11:50 AM.
-
November 23rd, 2008, 12:27 AM
#3
Re: two item array
ok i got it, heres my complete code.
but its being weird. when the msgbox pops up it gives the right values except for the new minimum value. any help with my equations, the order or something of the sort, it works on a calculator but not in my program.
Code:
Public Structure lotStyle
Dim name As String
Dim startPrice As Decimal
End Structure
Public Class Form1
Public LotStuff() As lotStyle
Public Sub SetValues_hardCoded()
ReDim LotStuff(0 To 13)
LotStuff(0).name = "vacant lot"
LotStuff(0).startPrice = 5000
LotStuff(1).name = "Empty Storefront"
LotStuff(1).startPrice = 50000
LotStuff(2).name = "Plaza"
LotStuff(2).startPrice = 1000000
LotStuff(3).name = "Seaside Lot"
LotStuff(3).startPrice = 4000000
LotStuff(4).name = "Townhome"
LotStuff(4).startPrice = 10000
LotStuff(5).name = "Restaurant"
LotStuff(5).startPrice = 30000
LotStuff(6).name = "Condo Complex"
LotStuff(6).startPrice = 200000
LotStuff(7).name = "Luxury Hotel"
LotStuff(7).startPrice = 400000
LotStuff(8).name = "Skyscraper"
LotStuff(8).startPrice = 15000000
LotStuff(9).name = "Casino"
LotStuff(9).startPrice = 40000000
LotStuff(10).name = "Shipyard"
LotStuff(10).startPrice = 6000000
LotStuff(11).name = "Yacht Harbor"
LotStuff(11).startPrice = 5000000
LotStuff(12).name = "Seaside Resort"
LotStuff(12).startPrice = 20000000
LotStuff(13).name = "Downtown Shopping Mall"
LotStuff(13).startPrice = 50000000
End Sub
Private Sub TextBox1_MouseHover(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.MouseHover
ToolTip1.SetToolTip(TextBox1, "Cash Flow")
End Sub
Private Sub TextBox2_MouseHover(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox2.MouseHover
ToolTip1.SetToolTip(TextBox2, "Account Balance")
End Sub
Private Sub TextBox1_MouseDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles TextBox1.MouseDown
TextBox1.Clear()
End Sub
Private Sub TextBox2_MouseDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles TextBox2.MouseDown
TextBox2.Clear()
End Sub
Private Sub TextBox3_MouseDown(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox3.MouseDown
TextBox3.Clear()
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
SetValues_hardCoded()
'these variable need to plug into an equation
Dim current As Long
Dim toBuy As Integer
Dim startPrice As Long
Dim newPrice As Long
Dim totalNeed As Long
Dim quantity As Long
Dim subNeed As Decimal
Dim account As Decimal
Dim flow As Decimal
Dim hours As Decimal
Dim owned As Decimal
Dim index As Integer
Dim days As Decimal
owned = Val(TextBox3.Text)
quantity = Val(ComboBox2.Text)
account = Val(TextBox2.Text)
flow = Val(TextBox1.Text)
name = ComboBox1.Text
If name = "Vacant Lot" Then index = 0
If name = "Empty Store Front" Then index = 1
If name = "Plaza" Then index = 2
If name = "Seaside Lot" Then index = 3
If name = "Townhome" Then index = 4
If name = "Restaurant" Then index = 5
If name = "Condo Complex" Then index = 6
If name = "Luxury Hotel" Then index = 7
If name = "Skyspcraper" Then index = 8
If name = "Casino" Then index = 9
If name = "Shipyard" Then index = 10
If name = "Yacht Harbor" Then index = 11
If name = "Seaside Resort" Then index = 12
If name = "Downtown Shopping Mall" Then index = 13
' Pick starting price from the array
startPrice = Val(LotStuff(index).startPrice)
'this is the equation
current = (startPrice) + (owned) * (0.1 * startPrice)
newPrice = (current) + (toBuy) * (0.1 * startPrice)
totalNeed = (newPrice) * (quantity)
subNeed = (totalNeed) - (account)
hours = Math.Ceiling((subNeed) / (flow))
days = Math.Round((hours) / (24), 2)
MsgBox("it will take you: " & ControlChars.NewLine & hours & " hours, or " & ControlChars.NewLine & days & " days to save up for " & quantity & " " & Name & "'s" & ControlChars.NewLine & "The new minimum price of the " & Name & " is " & newPrice)
End Sub
End Class
-
November 23rd, 2008, 04:34 AM
#4
Re: two item array
Here's roughly how I'd go about it:
NOTE: Nothing in this code has explicit scope. You should add Public/Private/Protected where appropriate.
Code:
Structure LotInfo
Public Name as String
Public StartPrice as Integer
End Structure
Dim Lots as New Dictionary(Of Integer, LotInfo) 'Integer is questionable, as you only have 14
You still have the problem of having the values hard coded. You could add them as settings; I often Read in a string from the settings, although putting it in a resource file is just a good a method...
Code:
'My.Settings.Lots Contains something like: "Vacant Lot|5000;Empty Storefront|50000" etc.
Dim Parts() as String = Split(My.Settings.Lots, ";")
For Each P in Parts
Lots.Add(Lots.Count, New LotInfo() With {.Name = Left(P, Instr(P, "|") - 1), .StartPrice = CInt(Mid(P, Instr(P, "|")))}
Next
Also, you can neaten up later code. Rather than testing the name of the ComboBox1, why not use the SelectedIndex property. This should also match exactly to the key in the dictionary, assuming the combobox is populated logically.
Also, some of the maths can be neaten...but I'll leave that for you!
Help from me is always guaranteed!*
VB.NET code is made up on the spot with VS2008 Professional with .NET 3.5. Everything else is just made up on the spot.
Please Remember to rate posts, use code tags, send me money and all the other things listed in the "Before you post" posts.
*Guarantee may not be honoured.
-
November 23rd, 2008, 11:57 AM
#5
Re: two item array
Should be easy to debug. Just press F9 to create a breakpoint on the first variable = val(xxx.text)
Then run the program, enter info, and it will stop at that line. Press F10 to run line by line, and hover the cursor over variables to see their values.
You can also use Debug.Print to see values, or calculate by hand in the immediate window.
I'd suspect your calculations. Hard code them and test it. The pc isn't the same as a calculator.
-
November 24th, 2008, 12:43 AM
#6
Re: two item array
thank you guys for your input, if you want to see the completed program go here:
http://slickfightgear.exhspace.com/
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|