Page 1 of 1
Visual Basics
Posted: Tue Oct 16, 2012 8:13 am
by [SD]Master_Wong
Iv just started learning vb in uni its not important i get this done now i can wait til next weeks lecture but i wanna mess around with some other stuff and its confusing me why this code isnt working.
this code works fine
Code: Select all
sub btnkelv_onclick()
If txtkelv.value < 0 Then
fah.innertext = "Invalid"
cels.innertext = "Invalid"
Kelv.innertext = "Invalid"
Else
fah.innertext=txtkelv.value-273.15
cels.innertext=(((txtkelv.value-273.15)*9)/5)+32
kelv.innertext=txtkelv.value
end if
end sub
which basically is a calcualtor converting each temperature into different values but like i said this works perfect while this which is nearly identical code does not
sub btncels_onclick()
If txtcels.value < -273.15 Then
fah.innertext = "Invalid"
cels.innertext = "Invalid"
Kelv.innertext = "Invalid"
Else
cels.innertext=((txtcels.value*9)/5)+32
kelv.innertext=txtcels.value+273.15
fah.innertext=txtcels.value
end if
end sub
iv bolded the part that does not seem to work. i am simply trying to set a flaw value which it cannot go below as it does not exist.
Re: Visual Basics
Posted: Thu Oct 18, 2012 12:52 am
by EvGa
Can't remember the last time I wrote code in VB, but perhaps define your flaw value as a constant instead of defining it directly in the condition and see what happens.
Re: Visual Basics
Posted: Thu Oct 18, 2012 11:16 am
by [SD]Master_Wong
im new to coding whats that mean?
Re: Visual Basics
Posted: Thu Oct 18, 2012 8:03 pm
by ShiningBow
I don't know which version of visual basic you have (I've only used VB6

) nor am I great at programming...
So in VB6 there is no such thing as a .value property for textboxes but maybe your problem is that, that property doesn't support decimals?
Sorry can't help much but I know someone will be able to help

Re: Visual Basics
Posted: Thu Oct 18, 2012 11:48 pm
by [SD]Master_Wong
ShiningBow wrote:I don't know which version of visual basic you have (I've only used VB6

) nor am I great at programming...
So in VB6 there is no such thing as a .value property for textboxes but maybe your problem is that, that property doesn't support decimals?
Sorry can't help much but I know someone will be able to help

the box its refering to is
html
<input id="txtcels" type="text" />
but if it dont support decimals how can i work around that the decimal isnt all that important -275 will do but that dont work either.
atm i dont know where iv put my usb stick with this on, iv not been backing up as its not actual important work...wish i had now
Re: Visual Basics
Posted: Fri Oct 19, 2012 4:21 am
by Azilius
Does the code compile? Does it give you an error message? If it does compile, what is the problem with it?
Re: Visual Basics
Posted: Fri Oct 19, 2012 9:42 am
by [SD]Master_Wong
there are no error messages with it as i said when i use 0 the code works i dont know it might work with positive numbers
Re: Visual Basics
Posted: Thu Oct 25, 2012 10:45 pm
by [SD]Master_Wong
Urgent I am getting fustrated so please helpi must be terrible at coding this fraction calculator wont work at all and i dont know why
Code: Select all
<html>
<head>
<title></title>
</head>
<body>
<center>
<p>Fraction A...............................Fraction B................................Answer</p>
<input id="txtnum1" type="text" />+<input id="txtnum2" type="text" />=<input id="txtnum3" type="text" /></br>
<input id="txtden1" type="text" />+<input id="txtden2" type="text" />=<input id="txtden3" type="text" /></br>
<input id="btncalc" type="button" value="Calculate" /><input id="btnsimp" type="button" value="simplify" />
</center>
</body>
</html>
<script language="vbscript">
sub btncalc_onclick()
txtnum3.value = cint(txtnum1.value * txtden2.value) + cint(txtnum2.value * txtden1.value)
txtden3.value = txtden1.value * txtden2.value
end sub
sub btnsimp_onclick()
Dim GCD As Integer = GCF(txtnum3.value, txtden3.value)
txtnum3.value = txtnum3.value / GCD
txtden3.value = txtden3.value / GCD
end sub
Function GCF(ByVal x As Integer, ByVal y As Integer) As Integer
x = Math.Abs(x)
y = Math.Abs(y)
Dim z As Integer
Do
z = x Mod y
If z = 0 Then Return y
x = y
y = z
Loop
End Function
</script>
Re: Visual Basics
Posted: Thu Oct 25, 2012 11:13 pm
by [SD]Master_Wong
triple post the problematic code is
Code: Select all
sub btnsimp_onclick()
Dim GCD As Integer = GCF(txtnum3.value, txtden3.value)
txtnum3.value = txtnum3.value / GCD
txtden3.value = txtden3.value / GCD
end sub
Function GCF(ByVal x As Integer, ByVal y As Integer) As Integer
x = Math.Abs(x)
y = Math.Abs(y)
Dim z As Integer
Do
z = x Mod y
If z = 0 Then Return y
x = y
y = z
Loop
End Function
but i dont know why yet, il update this post in the future of my updates