|
Visual Basic 2010
Bahamut.Jetackuu
Server: Bahamut
Game: FFXI
Posts: 9001
By Bahamut.Jetackuu 2010-09-13 16:49:17
I'm trying to write an Ohm's Law Calculator for class, So far I only have one of my buttons working (the clear button) and aside from that I'm at a loss, the book isn't of much help and the only thing close that I'm finding online is for vb6 and the display commands aren't the same or I'm not looking hard enough, here's the source, help would be welcome.
Public Class OhmCalcfrm
Dim V As Double
Dim I As Double
Dim R As Double
Public Sub OhmCalc()
V = txtVolt.Text
I = txtCurr.Text
R = txtResi.Text
'(V=Voltage, R=Resistance, and I=Current)
End Sub
Private Sub VltBtn_Click()
V = (I * R)
' Solve ForVoltage
txtVolt.Text = V
End Sub
Private Sub ResiBtn_Click()
R = V / I ' Solve For Ressistance
txtCurr.Text = R
End Sub
Private Sub CurrBtn_Click()
I = V / R ' Solve For Current
(txtResi.Text) = I
End Sub
Private Sub ClrBtn_Click() Handles Clrbtn.MouseClick
txtVolt.Text = ""
txtResi.Text = ""
txtCurr.Text = ""
End Sub
End Class
I have 3 text boxes, and 4 buttons (one is for clear and it's working) but I can't get the others to calculate the formula.
Bahamut.Jetackuu
Server: Bahamut
Game: FFXI
Posts: 9001
By Bahamut.Jetackuu 2010-09-13 17:28:17
I've reread it again and I just don't see why it isn't doing it, should I have them set as Double? or as Integer (noob to programming)
Server: Siren
Game: FFXI
Posts: 10387
By Siren.Enternius 2010-09-13 17:30:30
Bahamut.Jetackuu said: Public Class OhmCalcfrm
Dim V As Double
Dim I As Double
Dim R As Double
Public Sub OhmCalc()
V = txtVolt.Text
I = txtCurr.Text
R = txtResi.Text
'(V=Voltage, R=Resistance, and I=Current)
End Sub
Private Sub VltBtn_Click()
V = (I * R)
' Solve ForVoltage
txtVolt.Text = V
End Sub
Private Sub ResiBtn_Click()
R = V / I ' Solve For Ressistance
txtCurr.Text = R
End Sub
Private Sub CurrBtn_Click()
I = V / R ' Solve For Current
(txtResi.Text) = I
End Sub
Private Sub ClrBtn_Click() Handles Clrbtn.MouseClick
txtVolt.Text = ""
txtResi.Text = ""
txtCurr.Text = ""
End Sub
End Class That's what she said.
Server: Phoenix
Game: FFXI
Posts: 738
By Phoenix.Smileybone 2010-09-13 17:32:33
I only took programming one but I think I might see your problem. You have V I and R defined twice as two different things.
Bahamut.Jetackuu
Server: Bahamut
Game: FFXI
Posts: 9001
By Bahamut.Jetackuu 2010-09-13 17:32:48
>.> how'd you know?
Bahamut.Jetackuu
Server: Bahamut
Game: FFXI
Posts: 9001
By Bahamut.Jetackuu 2010-09-13 17:36:04
I need it to feed the answer back into the box, but I also need it to know which numbers to put in the equations
Server: Phoenix
Game: FFXI
Posts: 738
By Phoenix.Smileybone 2010-09-13 17:40:50
Bahamut.Jetackuu said: I'm trying to write an Ohm's Law Calculator for class, So far I only have one of my buttons working (the clear button) and aside from that I'm at a loss, the book isn't of much help and the only thing close that I'm finding online is for vb6 and the display commands aren't the same or I'm not looking hard enough, here's the source, help would be welcome.
Public Class OhmCalcfrm
Dim V As Double
Dim I As Double
Dim R As Double
Public Sub OhmCalc()
Try deleting this:
|----------------|
| V = txtVolt.Text|
| I = txtCurr.Text|
| R = txtResi.Text|
|----------------|
'(V=Voltage, R=Resistance, and I=Current)
End Sub
Private Sub VltBtn_Click()
V = (I * R)
' Solve ForVoltage
txtVolt.Text = V
End Sub
Private Sub ResiBtn_Click()
R = V / I ' Solve For Ressistance
txtCurr.Text = R
End Sub
Private Sub CurrBtn_Click()
I = V / R ' Solve For Current
(txtResi.Text) = I
End Sub
Private Sub ClrBtn_Click() Handles Clrbtn.MouseClick
txtVolt.Text = ""
txtResi.Text = ""
txtCurr.Text = ""
End Sub
End Class
I have 3 text boxes, and 4 buttons (one is for clear and it's working) but I can't get the others to calculate the formula.
Not positive but may as well try it?
Bahamut.Jetackuu
Server: Bahamut
Game: FFXI
Posts: 9001
By Bahamut.Jetackuu 2010-09-13 17:43:35
Tried it, no go
Server: Phoenix
Game: FFXI
Posts: 738
By Phoenix.Smileybone 2010-09-13 17:44:00
oh wait I think what you need to do is have your outputs in a label box not a text box.
Server: Phoenix
Game: FFXI
Posts: 738
By Phoenix.Smileybone 2010-09-13 17:45:51
ignore that previous post
try this: Bahamut.Jetackuu said: I'm trying to write an Ohm's Law Calculator for class, So far I only have one of my buttons working (the clear button) and aside from that I'm at a loss, the book isn't of much help and the only thing close that I'm finding online is for vb6 and the display commands aren't the same or I'm not looking hard enough, here's the source, help would be welcome.
Public Class OhmCalcfrm
Dim V As Double
Dim I As Double
Dim R As Double
Public Sub OhmCalc()
V = txtVolt.Text
I = txtCurr.Text
R = txtResi.Text
'(V=Voltage, R=Resistance, and I=Current)
End Sub
Private Sub VltBtn_Click()
V = (I * R)
' Solve ForVoltage
lblVolt.Text = V
End Sub
Private Sub ResiBtn_Click()
R = V / I ' Solve For Ressistance
lblCurr.Text = R
End Sub
Private Sub CurrBtn_Click()
I = V / R ' Solve For Current
lblResi.Text = I
End Sub
Private Sub ClrBtn_Click() Handles Clrbtn.MouseClick
txtVolt.Text = ""
txtResi.Text = ""
txtCurr.Text = ""
End Sub
End Class
I have 3 text boxes, and 4 buttons (one is for clear and it's working) but I can't get the others to calculate the formula.
I think what you need is are label boxes for your outputs. Again not sure and I may have wrote it wrong (class was like a year and a half ago) but may as well try it.
Bahamut.Jetackuu
Server: Bahamut
Game: FFXI
Posts: 9001
By Bahamut.Jetackuu 2010-09-13 17:47:12
You can have an input box double as an output box, just dunno how
Bahamut.Jetackuu
Server: Bahamut
Game: FFXI
Posts: 9001
By Bahamut.Jetackuu 2010-09-13 17:47:35
there also should be a way to auto solve it without needing the buttons, but again dunno how
Quetzalcoatl.Serbzook
Server: Quetzalcoatl
Game: FFXI
Posts: 103
By Quetzalcoatl.Serbzook 2010-09-13 17:53:20
Every time someone teaches kids VB at school jesus comes down from heaven and starts murdering little babies. I dont know crap about VB but fyi i find some things suspicious as you say that only the clear button works:
Private Sub ClrBtn_Click() Handles Clrbtn.MouseClick
obviously this function handles the clrbtn mouseclick event
as for the other functions:
Private Sub ResiBtn_Click()
Private Sub CurrBtn_Click()
Private Sub VltBtn_Click()
I dont see em handling much, try to look at that for a starter,
Also your current function is feeding the resistance textbox and vice versa
Server: Asura
Game: FFXI
Posts: 367
By Asura.Theringer 2010-09-13 17:56:45
It's been like 3 years since I touched VB so this could fail miserably...
Private Sub VltBtn_Click()
V = (txtCurr.Text * txtResi.Text)
Though looking at what you already did.. This isn't gonna work :/ lol
Server: Phoenix
Game: FFXI
Posts: 738
By Phoenix.Smileybone 2010-09-13 17:57:13
This is what I'd try if you didn't want buttons.
You're gonna need input boxes for w/e the random variables are and label boxes for your outputs. I really wouldn't use a text box for outputs and I'm really not even sure if you can.
Public Class OhmCalcfrm
Dim V As Double
Dim I As Double
Dim R As Double
Public Sub OhmCalc()
(inputs)
V = txtVolt.text
I = txtCurr.Text
R = txtResi.Text
V = (I*R)
R = V/I
I = V/R
'(V=Voltage, R=Resistance, and I=Current)
(outputs)
lblVoltage.text=V
lblResistance.text=R
lblCurrent.text=I (or w/e the ending is I kinda forget)
End Sub
Private Sub ClrBtn_Click() Handles Clrbtn.MouseClick
txtVolt.Text = ""
txtResi.Text = ""
txtCurr.Text = ""
End Sub
End Class
With this you should get auto calculations and the only button you should need is the clear button. You'll have to check my grammar so to speak, not sure I wrote all this correctly but I think you might get the idea. I wish I had VB on my computer so I could mess around w/ it and try and help more :/
Bahamut.Jetackuu
Server: Bahamut
Game: FFXI
Posts: 9001
By Bahamut.Jetackuu 2010-09-13 17:58:41
Considering everyone in the class are adults and there quite likely isn't a heaven or a jesus fellow (although according to the bible he did like to murder babies, saying he existed and all)
I looked up a calculator clear button and used it's example to make mine, different names but I got it, the others I made myself in a rush, I had wanted it to solve from just the values of 2 of the fields being entered to solve for the other, but I'm at an entire loss, however thank you for stating the obvious, as it is typically the obvious that is *** up, just takes another set of eyes to see it, hence why I posted it.
Bahamut.Jetackuu
Server: Bahamut
Game: FFXI
Posts: 9001
By Bahamut.Jetackuu 2010-09-13 18:00:43
you can download the express version for free, and get a registration code for free apparently off the microsoft site.
Edit:
And I'll try that other code in a moment.
Server: Asura
Game: FFXI
Posts: 367
By Asura.Theringer 2010-09-13 18:00:50
I feel your pain tho. Horrible when you get to this point.. When things SHOULD work.. but dont. I once spent a good 20hours infront of the PC tryin to get something to work on fackin VB, only for me to notice missing a (....
Quetzalcoatl.Serbzook
Server: Quetzalcoatl
Game: FFXI
Posts: 103
By Quetzalcoatl.Serbzook 2010-09-13 18:05:21
if you keep up and continue in a career as a programmer, you gonna notice that 99% of the biggest errors made are the "obvious" ones, theres no shame in that. theringer also pointed out another obvious thing but i have no idea if VB lets ya multiply the text value which is most likely a string in that case youll have to convert it to a double before multiplication. Also most languages wont let you set the text value with a double variable, which again you might need to convert to a string. but then again idk crap about vb, but still interesting things for you to look up.
Bahamut.Jetackuu
Server: Bahamut
Game: FFXI
Posts: 9001
By Bahamut.Jetackuu 2010-09-13 18:16:29
/confused
Server: Asura
Game: FFXI
Posts: 21
By Asura.Schatten 2010-09-13 18:21:22
I think Smileybone has it right, I haven't touched VB6 in ages, but it might just interpret the V I R as strings, which are not numbers, there-for it may not allow you to multiply them.
You could also try and convert them to double
so it'll look something like this
V = CStr((CDbl(I)* CDbl(R)))
R = CStr(CDbl(V)/CDbl(I))
I = CStr(CDbl(V)/CDbl(R))
CDbl === a function that turns the input value onto a double object.
CStr === a function that turns the input value onto a string
object.
Let us know if any of these suggestions work.
Bahamut.Jetackuu
Server: Bahamut
Game: FFXI
Posts: 9001
By Bahamut.Jetackuu 2010-09-13 18:25:09
Ok I have it working to the point to where it can solve for V, but when I try to solve for the other two it says
"Conversion from string "" to type 'Double' is not valid."
here's the code
Public Class OhmCalcfrm
Dim V As Double
Dim I As Double
Dim R As Double
Public Sub OhmCalc()
'(V=Voltage, R=Resistance, and I=Current)
End Sub
Private Sub VltBtn_Click() Handles VltBtn.MouseClick
I = txtCurr.Text
R = txtResi.Text
V = (I * R)
' Solve ForVoltage
txtVolt.Text = V
End Sub
Private Sub ResiBtn_Click() Handles CurrBtn.MouseClick
V = txtVolt.Text
I = txtCurr.Text
R = (V / I) ' Solve For Ressistance
txtCurr.Text = R
End Sub
Private Sub CurrBtn_Click() Handles ResiBtn.MouseClick
V = txtVolt.Text
R = txtResi.Text
I = (V / R) ' Solve For Current
txtResi.Text = I
End Sub
Private Sub ClrBtn_Click() Handles Clrbtn.MouseClick
txtVolt.Text = ""
txtResi.Text = ""
txtCurr.Text = ""
End Sub
End Class
Bahamut.Jetackuu
Server: Bahamut
Game: FFXI
Posts: 9001
By Bahamut.Jetackuu 2010-09-13 18:25:50
It can use the text box as an output, and 2010 doesn't have a thing known as a "Label Box" or lblbox etc
Bahamut.Jetackuu
Server: Bahamut
Game: FFXI
Posts: 9001
By Bahamut.Jetackuu 2010-09-13 18:27:13
It's not VB6, it's 2010, last I checked there were many differences.
Server: Lakshmi
Game: FFXI
Posts: 1685
By Lakshmi.Hypnotizd 2010-09-13 18:28:30
Your ClrBtn_Click() the handles part isn't cased properly as "Clrbtn"
Try this:
Quote: Private Sub OhmCalc()
V = Convert.ToDouble(txtVolt.Text)
I = Convert.ToDouble(txtCurr.Text)
R = Convert.ToDouble(txtResi.Text)
End Sub
Private Sub VltBtn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles VltBtn.Click
V = (I * R)
' Solve ForVoltage
txtVolt.Text = V.ToString()
End Sub
Private Sub ResiBtn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ResiBtn.Click
R = V / I ' Solve For Ressistance
txtCurr.Text = R.ToString()
End Sub
Private Sub ClrBtn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ClrBtn.Click
txtVolt.Text = ""
txtResi.Text = ""
txtCurr.Text = ""
End Sub
Private Sub CurrBtn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CurrBtn.Click
I = V / R ' Solve For Current
txtResi.Text = I.ToString()
End Sub
Bahamut.Jetackuu
Server: Bahamut
Game: FFXI
Posts: 9001
By Bahamut.Jetackuu 2010-09-13 19:42:12
figured it out, when I was doing the last two calculations I had a couple of things mixed up, probably due to the lack of sleep (who knows) it's all working now, anyone want to run it let me know.
I'm trying to write an Ohm's Law Calculator for class, So far I only have one of my buttons working (the clear button) and aside from that I'm at a loss, the book isn't of much help and the only thing close that I'm finding online is for vb6 and the display commands aren't the same or I'm not looking hard enough, here's the source, help would be welcome.
Public Class OhmCalcfrm
Dim V As Double
Dim I As Double
Dim R As Double
Public Sub OhmCalc()
V = txtVolt.Text
I = txtCurr.Text
R = txtResi.Text
'(V=Voltage, R=Resistance, and I=Current)
End Sub
Private Sub VltBtn_Click()
V = (I * R)
' Solve ForVoltage
txtVolt.Text = V
End Sub
Private Sub ResiBtn_Click()
R = V / I ' Solve For Ressistance
txtCurr.Text = R
End Sub
Private Sub CurrBtn_Click()
I = V / R ' Solve For Current
(txtResi.Text) = I
End Sub
Private Sub ClrBtn_Click() Handles Clrbtn.MouseClick
txtVolt.Text = ""
txtResi.Text = ""
txtCurr.Text = ""
End Sub
End Class
I have 3 text boxes, and 4 buttons (one is for clear and it's working) but I can't get the others to calculate the formula.
|
|