Page 1 of 2 12 LastLast
Results 1 to 10 of 11

Thread: Someone with some VB knowledge, please help meh!

  1. #1

    Default Someone with some VB knowledge, please help meh!

    I am new to programming/scripting. I am working on an assignment for class, but am having a problem with a piece of code for one of my exercises. The error I am getting is line 6 character 29. I do not see a problem with this particular character, but then again I'm new to VB. Below is the code, and any help is very appreciated!

    __________________

    Option explicit
    dim userNumber
    userNumber = inputbox("enter a number under 100:")
    if userNumber > 100 then
    wscript.echo "you entered " & userNumber _
    & " which is " & userNumber 100 & " above the allowed value."
    end if
    __________________

  2. #2

    Default

    I havent seen vb code in a while...ummm my only guess is all the &'s...

  3. #3
    R134A

    Default

    I believe it's the &'s too. I've never seen the &'s in any code before. Although I could be wrong.

  4. #4

    Default



    Quote Originally Posted by Powderhair View Post
    I am new to programming/scripting. I am working on an assignment for class, but am having a problem with a piece of code for one of my exercises. The error I am getting is line 6 character 29. I do not see a problem with this particular character, but then again I'm new to VB. Below is the code, and any help is very appreciated!

    __________________

    Option explicit
    dim userNumber
    userNumber = inputbox("enter a number under 100:")
    if userNumber > 100 then
    wscript.echo "you entered " & userNumber _
    & " which is " & userNumber – 100 & " above the allowed value."
    end if
    __________________
    I haven't used Visual Basic much, but I noticed that the 29th character in the line is the minus sign. My best guess is that you need parenthesis around the math operation like this: (userNumber - 100).

    The & shouldn't be a problem, at least according to this site: http://msdn.microsoft.com/en-us/libr...xw(VS.80).aspx

    Hope this helps...good luck on your assignment!

  5. #5

    Default

    I've never used Visual Basic before, but just looking at what you're trying to do here I'm like 80% sure it's a type correctness problem. Looking up the function definition for inputbox reveals that input box will return a string(I think that's what "as String" means :P), which makes sense as that's the format of the raw data the user is passing back to the program. InputBox Function (Visual Basic)

    This means that since you never declared the type of userNumber before that, userNumber's type is implicity of type string, and it's okay that userNumber is a string until you try to subtract the integer value 100 from the string userNumber.

    If I entered "300", you're essentially doing the operation (string)"300" - (integer)100, not (integer)300 - (integer)100, and doing the first one is not allowed.

    You probably need a function to convert ascii to an actual integer value. Something like C's atoi(), but for VB.

    EDIT: apparently the val() function provides similar functionality, try wrapping your inputbox call with val() like this

    userNumber = val(inputbox("enter a number under 100"))

    http://msdn.microsoft.com/en-us/libr...8VS.71%29.aspx

    EDIT 2: I dunno how VB works, but you also might get some ambiguity as to which overloaded function the compiler uses, as val() is overloaded to return a Double or an Integer, and as of yet everything is typeless (stupid dynamic typing). See what happens, but if your program spits out a decimal place, like "you entered 300.00, which is 200.00 above the allowed value, just throw an "as Integer into the line above, or where you declare userNumber and it ought to clear things up.

    Hope this helped

  6. #6

    Default



    Quote Originally Posted by Powderhair View Post
    I am new to programming/scripting. I am working on an assignment for class, but am having a problem with a piece of code for one of my exercises. The error I am getting is line 6 character 29. I do not see a problem with this particular character, but then again I'm new to VB. Below is the code, and any help is very appreciated!

    __________________

    Option explicit
    dim userNumber
    userNumber = inputbox("enter a number under 100:")
    if userNumber > 100 then
    wscript.echo "you entered " & userNumber _
    & " which is " & userNumber – 100 & " above the allowed value."
    end if
    __________________
    OH I REMEMBER NOW!.... You have to tell VB what data type is is. So Use dim userNumber as Single or whatever you want it to be. That should fix it.... right now the compilers is going like... What is it?

  7. #7

    Default



    Quote Originally Posted by dragsnick View Post
    OH I REMEMBER NOW!.... You have to tell VB what data type is is. So Use dim userNumber as Single or whatever you want it to be. That should fix it.... right now the compilers is going like... What is it?
    You mean like what I just said in the post above you? :P

  8. #8

    Default

    There was something wrong with your - sign, I replaced it with the normal one, and it worked like a charm, also I declared your userNumber as an integer.

    I tried this and found it working:

    Code:
    Dim userNumber As Integer
    userNumber = InputBox("enter a number under 100:")
    If userNumber > 100 Then
    wscript.echo = "you entered " & userNumber & " which is " & userNumber - 100 & " above the allowed value."
    End If
    if it's not working now, try to replace the - sign yourself again.



    Quote Originally Posted by dragsnick View Post
    OH I REMEMBER NOW!.... You have to tell VB what data type is is. So Use dim userNumber as Single or whatever you want it to be. That should fix it.... right now the compilers is going like... What is it?
    the beauty of VB is, that if you don't declare something, you can do math with them: for example:

    Code:
    a = 0
    b = 1
    MsgBox (a + b)
    will have as result 1

    but:

    Code:
    Dim a As String
    Dim b As String
    a = 0
    b = 1
    MsgBox (a + b)
    will result in 01

    oh, I don't know if this counts for vb.net, since it's different and more strict, but I tried those in vb6, and it worked perfectly.
    also: by using the 'option explicit', I think you HAVE to declare variables.

  9. #9

    Default

    If your doing a lot of coding for your class, and they're not too worried about tge variant of VB you use, you might want to try Visual Studio Express for VB.Net from Microsoft. It's free and the debugging tools can really help in situations like this.

    Hope this helps!

  10. #10

    Default



    Quote Originally Posted by kevintje View Post
    the beauty of VB is, that if you don't declare something, you can do math with them: for example:
    But you are technically declaring their type, in the first one it's just implicit because the variable took the type of what it was passed in, in that case an integer. I'd assume the second case only would work for primitives/classes which have the + operator defined. Strings take + as concatenation, but if you made up your own class and declared a and b as that class, if you don't create some sort of definition for what the + operator does I doubt it would work, and if it did it nearly certainly wouldn't do what you wanted it to do.

    Also agreed with above, Visual Studio is by far the best IDE I've come across for any language VS supports, like C++, C# or VB.

Similar Threads

  1. EDM Music: Hardcore Knowledge
    By kite in forum Off-topic
    Replies: 26
    Last Post: 08-Mar-2008, 10:08

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
ADISC.org - the Adult Baby / Diaper Lover / Incontinence Support Community.
ADISC.org is designed to be viewed in Firefox, with a resolution of at least 1280 x 1024.