Visual Basics

Anything else. Post a funny site or tell us about yourself. Discuss current events or whatever else you want. Post off topic threads here.
Post Reply
User avatar
[SD]Master_Wong
Forum God
Posts: 9509
Joined: Wed Jan 04, 2006 8:02 pm
Quick Reply: Yes
Location: Plymouth, University

Visual Basics

Post 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.
MaStEr
Image
credits zelzin ^^

User avatar
EvGa
Addicted Member
Posts: 2612
Joined: Wed Apr 23, 2008 4:33 am
Quick Reply: Yes
Location: Texas

Re: Visual Basics

Post 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.
Image

User avatar
[SD]Master_Wong
Forum God
Posts: 9509
Joined: Wed Jan 04, 2006 8:02 pm
Quick Reply: Yes
Location: Plymouth, University

Re: Visual Basics

Post by [SD]Master_Wong »

im new to coding whats that mean?
MaStEr
Image
credits zelzin ^^

User avatar
ShiningBow
Active Member
Posts: 895
Joined: Sat Sep 15, 2007 9:27 pm
Quick Reply: Yes
Location: Oasis

Re: Visual Basics

Post 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 :D
Silkroad Online.
Server:Venus
IGN:KrazyStrong
Level:78
Build:Warrior
Guild:SuddenDeath

Image

User avatar
[SD]Master_Wong
Forum God
Posts: 9509
Joined: Wed Jan 04, 2006 8:02 pm
Quick Reply: Yes
Location: Plymouth, University

Re: Visual Basics

Post 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 :D


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
MaStEr
Image
credits zelzin ^^

User avatar
Azilius
Senior Member
Posts: 4236
Joined: Tue Oct 31, 2006 9:39 pm
Location: CS:GO

Re: Visual Basics

Post by Azilius »

Does the code compile? Does it give you an error message? If it does compile, what is the problem with it?
ImageCrumpets for PresImage

User avatar
[SD]Master_Wong
Forum God
Posts: 9509
Joined: Wed Jan 04, 2006 8:02 pm
Quick Reply: Yes
Location: Plymouth, University

Re: Visual Basics

Post 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
MaStEr
Image
credits zelzin ^^

User avatar
[SD]Master_Wong
Forum God
Posts: 9509
Joined: Wed Jan 04, 2006 8:02 pm
Quick Reply: Yes
Location: Plymouth, University

Re: Visual Basics

Post by [SD]Master_Wong »

Urgent I am getting fustrated so please help

i 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>
MaStEr
Image
credits zelzin ^^

User avatar
[SD]Master_Wong
Forum God
Posts: 9509
Joined: Wed Jan 04, 2006 8:02 pm
Quick Reply: Yes
Location: Plymouth, University

Re: Visual Basics

Post 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
MaStEr
Image
credits zelzin ^^

Post Reply

Return to “Off Topic Lounge”