Error with VB programming assignment...

Discussion in 'OT Technology' started by deesee22, Feb 4, 2006.

  1. deesee22

    deesee22 Habs Crew OT Supporter

    Joined:
    Mar 23, 2004
    Messages:
    13,617
    Likes Received:
    11
    Location:
    Canada
    Im just learning VB, and for an assignment we had to create a program which converts miles to kilometers. Anyways, got the program working no problems. but if there is no number in the input miles textbox and tthe convert button is clicked I get a

    "An unhandled exception of type 'System.InvalidCastException' occurred in microsoft.visualbasic.dll"

    Is there anything I can put in so if the textbox is blank the value will always be assigned as 0?

    Thanks in advance to anyone who can help

    *Edit: I just read the sticky, and by no means am I trying to get someone to do my homework. The program is all coded and finished, I just need to fix this problem.
     
  2. Runescaper

    Runescaper Guest

    You could do something like this when the convert button is clicked:

    Code:
    if textbox.text.replace(" ","") = "" then
    
       value = 0
    
    else
    
       value = textbox.text
    
    end if
    
     
    Last edited by a moderator: Feb 4, 2006
  3. Frequency

    Frequency New Member

    Joined:
    Dec 30, 2004
    Messages:
    7,504
    Likes Received:
    0
    Location:
    PA
    I'm assuming this is VBdotNET
    so it would be something like this
    Code:
    If IsNumeric(txtmiles.text) Then
         miles = Val(trim(txtmiles.text))
    Else
         MessageBox.Show("Invalid miles input")
    End If
    
     
  4. deusexaethera

    deusexaethera OT Supporter

    Joined:
    Jan 27, 2005
    Messages:
    19,712
    Likes Received:
    0
    VB.NET can kiss my ass. VB6 til death do us part.
     
  5. Yep

    Yep Knick knack paddy whack, give the old dog a bone

    Joined:
    Jan 22, 2001
    Messages:
    4,603
    Likes Received:
    0
    Location:
    South Jersey
    Heh yeah, Dot net stuff takes forever to load up.
     
  6. deusexaethera

    deusexaethera OT Supporter

    Joined:
    Jan 27, 2005
    Messages:
    19,712
    Likes Received:
    0
    It has to invoke the .NET framework before it can run. That's the same reason why Java apps take a while to load. At least JRE is small and loads faster than .NET, though.
     

Share This Page