Visual Basic 2010

Language: JP EN DE FR
users online
Forum » Everything Else » Chatterbox » Visual Basic 2010
Visual Basic 2010
 Bahamut.Jetackuu
Offline
Server: Bahamut
Game: FFXI
user: Jetackuu
Posts: 9001
By Bahamut.Jetackuu 2010-09-13 16:49:17
Link | Quote | Reply
 
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
Offline
Server: Bahamut
Game: FFXI
user: Jetackuu
Posts: 9001
By Bahamut.Jetackuu 2010-09-13 17:28:17
Link | Quote | Reply
 
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)
 Siren.Enternius
Offline
Server: Siren
Game: FFXI
user: Enternius
Posts: 10387
By Siren.Enternius 2010-09-13 17:30:30
Link | Quote | Reply
 
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.
 Phoenix.Smileybone
Offline
Server: Phoenix
Game: FFXI
Posts: 738
By Phoenix.Smileybone 2010-09-13 17:32:33
Link | Quote | Reply
 
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
Offline
Server: Bahamut
Game: FFXI
user: Jetackuu
Posts: 9001
By Bahamut.Jetackuu 2010-09-13 17:32:48
Link | Quote | Reply
 
>.> how'd you know?
 Bahamut.Jetackuu
Offline
Server: Bahamut
Game: FFXI
user: Jetackuu
Posts: 9001
By Bahamut.Jetackuu 2010-09-13 17:36:04
Link | Quote | Reply
 
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
 Phoenix.Smileybone
Offline
Server: Phoenix
Game: FFXI
Posts: 738
By Phoenix.Smileybone 2010-09-13 17:40:50
Link | Quote | Reply
 
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
Offline
Server: Bahamut
Game: FFXI
user: Jetackuu
Posts: 9001
By Bahamut.Jetackuu 2010-09-13 17:43:35
Link | Quote | Reply
 
Tried it, no go
 Phoenix.Smileybone
Offline
Server: Phoenix
Game: FFXI
Posts: 738
By Phoenix.Smileybone 2010-09-13 17:44:00
Link | Quote | Reply
 
oh wait I think what you need to do is have your outputs in a label box not a text box.
 Phoenix.Smileybone
Offline
Server: Phoenix
Game: FFXI
Posts: 738
By Phoenix.Smileybone 2010-09-13 17:45:51
Link | Quote | Reply
 
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
Offline
Server: Bahamut
Game: FFXI
user: Jetackuu
Posts: 9001
By Bahamut.Jetackuu 2010-09-13 17:47:12
Link | Quote | Reply
 
You can have an input box double as an output box, just dunno how
 Bahamut.Jetackuu
Offline
Server: Bahamut
Game: FFXI
user: Jetackuu
Posts: 9001
By Bahamut.Jetackuu 2010-09-13 17:47:35
Link | Quote | Reply
 
there also should be a way to auto solve it without needing the buttons, but again dunno how
 Quetzalcoatl.Serbzook
Offline
Server: Quetzalcoatl
Game: FFXI
user: niktod
Posts: 103
By Quetzalcoatl.Serbzook 2010-09-13 17:53:20
Link | Quote | Reply
 
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
 Asura.Theringer
Offline
Server: Asura
Game: FFXI
user: Theringer
Posts: 367
By Asura.Theringer 2010-09-13 17:56:45
Link | Quote | Reply
 
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
 Phoenix.Smileybone
Offline
Server: Phoenix
Game: FFXI
Posts: 738
By Phoenix.Smileybone 2010-09-13 17:57:13
Link | Quote | Reply
 
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
Offline
Server: Bahamut
Game: FFXI
user: Jetackuu
Posts: 9001
By Bahamut.Jetackuu 2010-09-13 17:58:41
Link | Quote | Reply
 
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
Offline
Server: Bahamut
Game: FFXI
user: Jetackuu
Posts: 9001
By Bahamut.Jetackuu 2010-09-13 18:00:43
Link | Quote | Reply
 
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.
 Asura.Theringer
Offline
Server: Asura
Game: FFXI
user: Theringer
Posts: 367
By Asura.Theringer 2010-09-13 18:00:50
Link | Quote | Reply
 
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
Offline
Server: Quetzalcoatl
Game: FFXI
user: niktod
Posts: 103
By Quetzalcoatl.Serbzook 2010-09-13 18:05:21
Link | Quote | Reply
 
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
Offline
Server: Bahamut
Game: FFXI
user: Jetackuu
Posts: 9001
By Bahamut.Jetackuu 2010-09-13 18:16:29
Link | Quote | Reply
 
/confused
 Asura.Schatten
Offline
Server: Asura
Game: FFXI
user: Yesman13
Posts: 21
By Asura.Schatten 2010-09-13 18:21:22
Link | Quote | Reply
 
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
Offline
Server: Bahamut
Game: FFXI
user: Jetackuu
Posts: 9001
By Bahamut.Jetackuu 2010-09-13 18:25:09
Link | Quote | Reply
 
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
Offline
Server: Bahamut
Game: FFXI
user: Jetackuu
Posts: 9001
By Bahamut.Jetackuu 2010-09-13 18:25:50
Link | Quote | Reply
 
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
Offline
Server: Bahamut
Game: FFXI
user: Jetackuu
Posts: 9001
By Bahamut.Jetackuu 2010-09-13 18:27:13
Link | Quote | Reply
 
It's not VB6, it's 2010, last I checked there were many differences.
 Lakshmi.Hypnotizd
Offline
Server: Lakshmi
Game: FFXI
user: hypnotizd
Posts: 1685
By Lakshmi.Hypnotizd 2010-09-13 18:28:30
Link | Quote | Reply
 
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
Offline
Server: Bahamut
Game: FFXI
user: Jetackuu
Posts: 9001
By Bahamut.Jetackuu 2010-09-13 19:42:12
Link | Quote | Reply
 
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.
Log in to post.